public void EnableTeamFeatures_ExceptionUpdate_ReturnsFalse() { // Arrange var countGetField = 0; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => { if (countGetField == 0) { countGetField++; return(null); } return(new ShimSPField() { Update = () => { throw new Exception(); } }); }, AddStringSPFieldTypeBoolean = (displayName, type, required) => string.Empty } }; // Act var actualResult = ListCommands.EnableTeamFeatures(list); // Assert actualResult.ShouldBeFalse(); }
public void SaveIconToReporting_Should_ExecuteQuery() { // Arrange var actualQueryExecute = string.Empty; IDictionary <string, object> actualParameters = new Dictionary <string, object>(); var list = new ShimSPList() { IDGet = () => DummyGuid, ParentWebGet = () => new ShimSPWeb() }; ShimGridGanttSettings.ConstructorSPList = (sender, listParam) => sender.ListIcon = DummyIcon; ShimQueryExecutor.ConstructorSPWeb = (sender, web) => new ShimQueryExecutor(); ShimQueryExecutor.AllInstances.ExecuteReportingDBNonQueryStringIDictionaryOfStringObject = (sender, query, parameters) => { actualQueryExecute = query; actualParameters = parameters; }; // Act ListCommands.SaveIconToReporting(list); // Assert this.ShouldSatisfyAllConditions( () => actualQueryExecute.ShouldBe(@"INSERT INTO ReportListIds (Id, ListIcon) VALUES (@Id, @Icon)"), () => actualParameters.Count.ShouldBe(2), () => actualParameters.ShouldContainKeyAndValue("@Id", DummyGuid), () => actualParameters.ShouldContainKeyAndValue("@Icon", DummyIcon)); }
public GlobalCommand(ListCommands input) : base() { switch (input) { case ListCommands.Clear: Command = new RelayCommand <IList>(i => i.Clear(), i => i is IList); break; case ListCommands.MoveDown: Command = new RelayCommand <object[]>(i => { if (i is object[] j) { if (j.Length == 2) { if (j[0] is IList k) { k.MoveDown(j[1], true); } } } }, i => i is object[] j && j.Length == 2 && j[0] is IList); break; case ListCommands.MoveUp: Command = new RelayCommand <object[]>(i => { if (i is object[] j) { if (j.Length == 2) { if (j[0] is IList k) { k.MoveUp(j[1], true); } } } }, i => i is object[] j && j.Length == 2 && j[0] is IList); break; case ListCommands.Remove: Command = new RelayCommand <object[]>(i => { if (i is object[] j) { if (j.Length == 2) { if (j[0] is IList k) { k.Remove(j[1]); } } } }, i => i is object[] j && j.Length == 2 && j[0] is IList); break; } }
public void DisableTimesheets_Should_RemoveStringFromList() { // Arrange var actualEpmLiveTsLists = string.Empty; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() }, TitleGet = () => DummyTitle }; var web = new ShimSPWeb() { SiteGet = () => new ShimSPSite() { RootWebGet = () => new ShimSPWeb() } }; ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink(); ShimCoreFunctions.getConfigSettingSPWebString = (rootWeb, setting) => $"{DummyTitle}\r\n{DummyInternalName}"; ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value; // Act ListCommands.DisableTimesheets(list, web); // Assert actualEpmLiveTsLists.ShouldBe(DummyInternalName); }
public void ChangeContent(int listStyle) { switch (listStyle) { case 1 when !(Content is ImagesAndText): // Значки и текст this.RaisePropertyChanged(nameof(ButtonWidth)); this.RaisePropertyChanged(nameof(FontMaxHeight)); Content = new ImagesAndText { DataContext = this }; return; case 2 when !(Content is ListCommands): // Список Content = new ListCommands { DataContext = this }; return; default: // Только значки if (!(Content is OnlyImages)) { Content = new OnlyImages { DataContext = this } } ; break; } } }
public static void Execute(Command cmd) { if (cmd.Condition) { if (cmd is CommandAsync) { var command = (cmd as CommandAsync); ListCommands.Add(command); command.OnFinished += (s, e) => ListCommands.Remove(cmd as CommandAsync); command.OnFinished += new EventHandler(OnFinished); command.OnCanceled += new EventHandler(OnCanceled); command.OnError += new EventHandler(OnError); command.Start(); } else if (cmd is Command) { cmd.Execute(); if (OnCommandFinished != null) { OnCommandFinished(null, EventArgs.Empty); } } } else { ViewMainForm.GetInstance.MessageShow(cmd.errorMessage, strings.Info, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void HandleChangeCommand(string partialCommandName) { if (string.IsNullOrEmpty(partialCommandName)) { AddData(CoordinatateParserNames.Stop); return; } var listCommands = GetCommandList(partialCommandName); if (listCommands.Count == 0) { return; } var commandName = listCommands[0]; var currentAction = ListCommands.GetAction(ListCommands.NameMapping[commandName]); if (currentAction != null) { ActionsGraph.SwitchAction(currentAction.Name); } else { AddData(CoordinatateParserNames.Stop); } }
public void EnableTeamFeatures_Updated_ReturnsTrue() { // Arrange var actualUpdatedField = false; var countGetField = 0; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => { if (countGetField == 0) { countGetField++; return(null); } return(new ShimSPField() { Update = () => actualUpdatedField = true }); }, AddStringSPFieldTypeBoolean = (displayName, type, required) => string.Empty } }; // Act var actualResult = ListCommands.EnableTeamFeatures(list); // Assert this.ShouldSatisfyAllConditions( () => actualResult.ShouldBeTrue(), () => actualUpdatedField.ShouldBeTrue()); }
public void SetUp() { _shimsContext = ShimsContext.Create(); _testEntity = new ListCommands(); _privateObject = new PrivateObject(_testEntity); _privateType = new PrivateType(typeof(ListCommands)); ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = codeToRun => { codeToRun(); }; _spSiteConstructor = new ShimSPSite(); ShimSPSite.ConstructorGuid = (sender, guid) => new ShimSPSite(); ShimSPSite.ConstructorString = (sender, guid) => new ShimSPSite(); ShimSPSite.AllInstances.OpenWebGuid = (sender, guid) => new ShimSPWeb(); ShimSPContext.CurrentGet = () => new ShimSPContext() { WebGet = () => new ShimSPWeb() { UrlGet = () => string.Empty } }; ShimCoreFunctions.getLockConfigSettingSPWebStringBoolean = (web, setting, isRelative) => setting; ShimCoreFunctions.getConfigSettingSPWebString = (web, setting) => { switch (setting) { case "EPMLiveDisablePublishing": case "EPMLiveDisablePlanners": return("true"); case "EPKLists": return(DummyTitle); case "EPKDummyTitle_nonactivexs": case "EPKDummyTitle_menus": return(string.Empty); case "EPKMenus": return("EPKMenus"); case "epknonactivexs": return("epknonactivexs"); default: break; } return(null); }; }
public void EnableTimesheets_Should_UpdateFields() { // Arrange var countUpdatedField = 0; var countUpdatedContentType = 0; var countUpdatedList = 0; var actualEpmLiveTsLists = string.Empty; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() { Update = () => countUpdatedField++ } }, ContentTypesGet = () => new ShimSPContentTypeCollection() { ItemGetString = itemName => new ShimSPContentType() { FieldLinksGet = () => new ShimSPFieldLinkCollection() { ItemGetGuid = guid => null }, Update = () => countUpdatedContentType++ } }, Update = () => countUpdatedList++, TitleGet = () => DummyTitle }; var web = new ShimSPWeb() { SiteGet = () => new ShimSPSite() { RootWebGet = () => new ShimSPWeb() } }; ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink(); ShimCoreFunctions.getConfigSettingSPWebString = (rootWeb, setting) => string.Empty; ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value; // Act ListCommands.EnableTimesheets(list, web); // Assert this.ShouldSatisfyAllConditions( () => countUpdatedField.ShouldBe(2), () => countUpdatedContentType.ShouldBe(2), () => countUpdatedList.ShouldBe(1), () => actualEpmLiveTsLists.ShouldBe($"\r\n{DummyTitle}")); }
public void EnableFancyForms_FancyFormNotFound_SaveChangesAndDispose() { // Arrange var actualCountSaveChanges = 0; var actualDisposeWeb = false; var list = new ShimSPList() { ParentWebGet = () => new ShimSPWeb() { ServerRelativeUrlGet = () => DummyUrl, GetFileString = strUrl => new ShimSPFile() { GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager() { WebPartsGet = () => new ShimSPLimitedWebPartCollection() { ItemGetInt32 = itemId => { if (itemId == 0) { return(new ShimWebPart(new ShimGridListView().Instance) { TitleGet = () => "Fancy Display Form" }); } return(new ShimWebPart(new ShimListFormWebPart().Instance)); } } .Bind( new WebPart[] { new ShimWebPart(new ShimGridListView().Instance), new ShimWebPart(new ShimListFormWebPart().Instance) }), SaveChangesWebPart = webPartChanged => actualCountSaveChanges++, WebGet = () => new ShimSPWeb() { Dispose = () => actualDisposeWeb = true } } } }, RootFolderGet = () => new ShimSPFolder() }; // Act ListCommands.EnableFancyForms(list); // Assert this.ShouldSatisfyAllConditions( () => actualCountSaveChanges.ShouldBe(2), () => actualDisposeWeb.ShouldBeTrue()); }
// Private Methods (4) private void GetAssociatedItems(List <NavLink> links) { Guid parentWebId = Guid.Empty; Guid parentListId = Guid.Empty; int parentItemId = 0; ParentWebListItemId(ref parentWebId, ref parentListId, ref parentItemId); if (parentWebId == Guid.Empty || parentListId == Guid.Empty || parentItemId <= 0) { return; } links.Add(new NavLink { Title = @"Associated Items<span id=""epm-nav-asoitems-info"" class=""icon-info-2"" style=""padding-left: 8px;"" title=""Since this Workspace was created from an Item in the parent site, you have access to these associated parent Lists and Libraries."" data-delay=""100"" data-placement=""right"" data-toggle=""tooltip""></span>", Url = "Header" }); using (var spSite = new SPSite(SiteId, GetUserToken())) { using (SPWeb spWeb = spSite.OpenWeb(parentWebId)) { SPList spList = null; try { spList = spWeb.Lists.GetList(parentListId, false); } catch { } if (spList == null) { return; } NavLink navLink = GetLink(spList, parentItemId); if (navLink != null) { links.Add(navLink); links.AddRange(from object associatedList in ListCommands.GetAssociatedLists(spList) where associatedList != null select(AssociatedListInfo) associatedList into listInfo select GetLink(listInfo, spList, navLink.Title) into link where link != null select link); } } } }
public IList <Command> GetAllCommands() { var commands = new List <Command>(); var testCommand = CommandStub.Make(); var listCommands = new ListCommands(new BotStub()); commands.Add(testCommand); commands.Add(listCommands); return(commands); }
public override void Execute(ITelegramBotClient client, Message message) { var commands = ListCommands.GetAllCommands(); StringBuilder sb = new StringBuilder(); sb.AppendLine("Я підтримую наступні команди:"); foreach (var command in commands.Skip(1)) { sb.AppendLine($"{command.TextCommand} {command.Des} \nПриклад: [{command.Example}]\n"); } client.SendTextMessageAsync(message.Chat, sb.ToString()); }
public void InstallListsViewsWebParts_FoundGridListView_AddGridView() { // Arrange var actualAddedGridView = false; var actualDisposeWeb = false; var spList = new ShimSPList() { BaseTemplateGet = () => SPListTemplateType.AccessApp, ParentWebGet = () => new ShimSPWeb() { GetFileString = strUrl => new ShimSPFile() { ExistsGet = () => true, GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager() { WebPartsGet = () => new ShimSPLimitedWebPartCollection().Bind( new WebPart[] { new ShimWebPart(new ShimGridListView().Instance) }), AddWebPartWebPartStringInt32 = (webPart, zoneId, zoneIndex) => { if (webPart.GetType() == typeof(GridListView)) { actualAddedGridView = true; } }, WebGet = () => new ShimSPWeb() { Dispose = () => actualDisposeWeb = true } } } }, ViewsGet = () => new ShimSPViewCollection().Bind( new SPView[] { new ShimSPView() { UrlGet = () => DummyUrl } }) }; // Act ListCommands.InstallListsViewsWebparts(spList); // Assert this.ShouldSatisfyAllConditions( () => actualAddedGridView.ShouldBeFalse(), () => actualDisposeWeb.ShouldBeTrue()); }
public void GetAssociatedLists_NotFound_ReturnsArrayList() { // Arrange var list = new ShimSPList() { IDGet = () => ListId, ParentWebGet = () => new ShimSPWeb() { ListsGet = () => new ShimSPListCollection().Bind( new SPList[] { new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection().Bind( new SPField[] { new ShimSPField( new ShimSPFieldLookup() { LookupListGet = () => $"{{{ListId}}}" }) { TypeGet = () => SPFieldType.Lookup, InternalNameGet = () => DummyInternalName } }), ImageUrlGet = () => DummyImageUrl, IDGet = () => DummyGuid, TitleGet = () => DummyTitle } }) } }; ShimGridGanttSettings.ConstructorSPList = (sender, listParam) => sender.AssociatedItems = true; // Act var actualResult = ListCommands.GetAssociatedLists(list); // Assert var associatedListInfo = (AssociatedListInfo)actualResult[0]; this.ShouldSatisfyAllConditions( () => actualResult.Count.ShouldBe(1), () => actualResult[0].ShouldBeOfType <AssociatedListInfo>(), () => associatedListInfo.Title.ShouldBe(DummyTitle), () => associatedListInfo.LinkedField.ShouldBe(DummyInternalName), () => associatedListInfo.ListId.ShouldBe(DummyGuid), () => associatedListInfo.icon.ShouldBe(DummyImageUrl)); }
public void EnableTeamFeatures_Found_ReturnsTrue() { // Arrange var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() } }; // Act var actualResult = ListCommands.EnableTeamFeatures(list); // Assert actualResult.ShouldBeTrue(); }
/// <summary> /// Processes all associated lists. /// </summary> /// <param name="elevatedWeb">The elevated web.</param> /// <param name="baseList">The base projects list.</param> /// <param name="level">The logging level.</param> private void ProcessAssociatedLists(SPWeb elevatedWeb, SPList baseList, int level) { var associated = ListCommands.GetAssociatedLists(baseList).Cast <AssociatedListInfo>().ToArray(); if (associated.Length > 0) { LogInfo($"Updating associated lists for {baseList.Title}.", level); foreach (var associatedListInfo in associated) { UpdateAssociatedList(elevatedWeb, associatedListInfo, level + 1); } } else { LogItemSkipped($"Associated lists are not configured for list {baseList.Title}.", level); } }
private void CommandsWindow_Loaded(object sender, RoutedEventArgs e) { string initialValue = null; if (Model.AddinConfiguration.Commands.Count > 0) { CommanderCommand selectedItem = null; if (!string.IsNullOrEmpty(CommanderAddinConfiguration.Current.LastCommand)) { selectedItem = Model.AddinConfiguration.Commands.FirstOrDefault( cmd => cmd.Name == Model.AddinConfiguration.LastCommand); } else { selectedItem = Model.AddinConfiguration.Commands[0]; } ListCommands.SelectedItem = selectedItem; if (selectedItem != null) { initialValue = selectedItem.CommandText; } } editor = new MarkdownEditorSimple(WebBrowserCommand, initialValue); editor.IsDirtyAction = () => { string val = editor.GetMarkdown(); if (val != null && Model.ActiveCommand != null) { Model.ActiveCommand.CommandText = val; } return(true); }; Dispatcher.InvokeAsync(() => { ListCommands.Focus(); editor.SetEditorSyntax("csharp"); }, System.Windows.Threading.DispatcherPriority.ApplicationIdle); pageLoaded = true; }
public void MapListToReporting_Should_CreateListBiz() { // Arrange var actualCreatedListBiz = false; var list = new ShimSPList() { IDGet = () => DummyGuid, ParentWebGet = () => new ShimSPWeb { IDGet = () => DummyGuid, SiteGet = () => new ShimSPSite() { IDGet = () => DummyGuid } } }; ShimSPContext.CurrentGet = () => new ShimSPContext() { SiteGet = () => new ShimSPSite() { RootWebGet = () => new ShimSPWeb() } }; ShimReportBiz.AllInstances.GetListBizGuid = (sender, guid) => new ShimListBiz() { ListNameGet = () => string.Empty }; ShimReportBiz.AllInstances.CreateListBizGuid = (sender, guid) => { actualCreatedListBiz = true; return(new ShimListBiz()); }; ShimReportBiz.ConstructorGuidGuidBoolean = (sender, siteId, webId, reporintv2) => new ShimReportBiz(); ShimCoreFunctions.getConfigSettingSPWebString = (web, setting) => "true"; // Act ListCommands.MapListToReporting(list); // Assert actualCreatedListBiz.ShouldBeTrue(); }
private static void Client_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { Console.OutputEncoding = Encoding.UTF8; Console.WriteLine($"Name: {e.Message.From.FirstName}, Id: {e.Message.From.Id} [{e.Message.Text}]"); if (e.Message.Type == MessageType.Text) { foreach (var item in ListCommands.GetAllCommands()) { if (item.TextCommand.CheckCommand(e.Message.Text)) { e.Message.Text = e.Message.Text.ToLower(); item.Execute(client, e.Message); return; } } } client.SendTextMessageAsync(e.Message.Chat, "Команда не вірна!"); }
private async void CommandsWindow_Loaded(object sender, RoutedEventArgs e) { await Task.Delay(1); string initialValue = null; if (Model.AddinConfiguration.Commands.Count > 0) { CommanderCommand selectedItem = null; if (!string.IsNullOrEmpty(CommanderAddinConfiguration.Current.LastCommand)) { selectedItem = Model.AddinConfiguration.Commands.FirstOrDefault( cmd => cmd.Name == Model.AddinConfiguration.LastCommand); } else { selectedItem = Model.AddinConfiguration.Commands[0]; } ListCommands.SelectedItem = selectedItem; if (selectedItem != null) { initialValue = selectedItem.CommandText; } } editor = new MarkdownEditorSimple(WebBrowserCommand, initialValue, "csharp"); editor.ShowLineNumbers = true; editor.IsDirtyAction = (isDirty, newText, oldText) => { if (newText != null && Model.ActiveCommand != null) { Model.ActiveCommand.CommandText = newText; } return(newText != oldText); }; Dispatcher.Invoke(() => ListCommands.Focus(), DispatcherPriority.ApplicationIdle); pageLoaded = true; }
public void EnableFancyForms_FancyFormNotFound_AddChangesAndDispose() { // Arrange var actualCountAddChanges = 0; var actualDisposeWeb = false; var list = new ShimSPList() { ParentWebGet = () => new ShimSPWeb() { ServerRelativeUrlGet = () => DummyUrl, GetFileString = strUrl => null }, RootFolderGet = () => new ShimSPFolder() { FilesGet = () => new ShimSPFileCollection() { AddStringSPTemplateFileType = (urlOfFile, templateFileType) => new ShimSPFile() { GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager() { AddWebPartWebPartStringInt32 = (webPart, zoneId, zoneIndex) => actualCountAddChanges++, WebGet = () => new ShimSPWeb() { Dispose = () => actualDisposeWeb = true } } } } } }; // Act ListCommands.EnableFancyForms(list); // Assert this.ShouldSatisfyAllConditions( () => actualCountAddChanges.ShouldBe(1), () => actualDisposeWeb.ShouldBeTrue()); }
public string RPopLPush(string source, string destination) => Multi(ListCommands.RPopLPush(source, destination));
public Task <string> RPopLPushAsync(string source, string destination) => MultiAsync(ListCommands.RPopLPush(source, destination));
public long RPushX(string key, params object[] values) => Multi(ListCommands.RPushX(key, values));
public Task <long> RPushXAsync(string key, params object[] values) => MultiAsync(ListCommands.RPushX(key, values));
/// <summary> /// Updates the project status. /// </summary> /// <param name="projectListItem">The project list item.</param> /// <param name="status">if set to <c>true</c> project will be archived, otherwise restored.</param> private void UpdateProjectStatus(SPListItem projectListItem, bool status) { if (projectListItem == null) { throw new ArgumentNullException(); } var web = projectListItem.Web; web.AllowUnsafeUpdates = true; try { var action = status ? ArchiveProjectAction : RestoreProjectAction; LogMessage(web, $"Updating project '{projectListItem.ID}' - Action: '{action}'", LogKind.Info); projectListItem[ArchivedColumn] = status; if (projectListItem.Fields.ContainsFieldWithInternalName(TimesheetColumn)) { projectListItem[TimesheetColumn] = !status; } projectListItem.Update(); // when associated lists configured - move to archive all of them SPSecurity.RunWithElevatedPrivileges( () => { using (var elevatedSite = new SPSite(web.Site.ID)) { using (var elevatedWeb = elevatedSite.OpenWeb(web.ID)) { elevatedWeb.AllowUnsafeUpdates = true; if (ConnectionProvider.AllowDatabaseConnections(elevatedWeb)) { var pfeProjectRepository = new ProjectRepository(); pfeProjectRepository.UpdateArchivedStatus(web, projectListItem.ParentList.ID, projectListItem.ID, status); } try { var elevatedProjectList = elevatedWeb.Lists.GetList( projectListItem.ParentList.ID, false); var settings = ListCommands.GetGridGanttSettings(elevatedProjectList); if (settings.AssociatedItems) { var associated = ListCommands.GetAssociatedLists(elevatedProjectList) .Cast <AssociatedListInfo>().ToArray(); UpdateAssociatedLists(elevatedWeb, projectListItem.ID, status, associated); } } finally { elevatedWeb.AllowUnsafeUpdates = false; } } } }); } catch (Exception ex) { LogError(web, ex); throw; } finally { web.AllowUnsafeUpdates = false; } }
protected void Page_Load(object sender, EventArgs e) { SPWeb web = SPContext.Current.Web; string resUrl = ""; web.Site.CatchAccessDeniedException = false; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb aweb = site.OpenWeb(web.ID)) { resUrl = CoreFunctions.getConfigSetting(aweb, "EPMLiveResourceURL", true, false); } } }); //bool canManageAGroup = false; SPListItem oLi = null; SPList oList = null; bool bUseTeam = false; Guid listid = Guid.Empty; int itemid = 0; try { listid = new Guid(Request["listid"]); itemid = int.Parse(Request["id"]); oList = web.Lists[listid]; oLi = oList.GetItemById(itemid); GridGanttSettings gSettings = new GridGanttSettings(oList); bUseTeam = gSettings.BuildTeam; } catch (Exception) { try { APITeam.VerifyProjectTeamWorkspace(web, out itemid, out listid); if (itemid > 0 && listid != Guid.Empty) { try { while (!web.IsRootWeb) //Inherit | Open { if (web.IsRootWeb) { break; } web = web.ParentWeb; } oList = web.Lists[listid]; GridGanttSettings gSettings = ListCommands.GetGridGanttSettings(oList); bUseTeam = gSettings.BuildTeam; oLi = oList.GetItemById(itemid); } catch { } } } catch { } } if (bUseTeam) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite tSite = new SPSite(web.Site.ID)) { using (SPWeb tWeb = tSite.OpenWeb(web.ID)) { SPListItem spListItem = null; SPList tList = tWeb.Lists[listid]; try { spListItem = tList.GetItemById(itemid); } catch (ArgumentException ex) { throw new SPException("The associated project does not exist or has been deleted.", ex); } web.Site.CatchAccessDeniedException = false; foreach (SPRoleAssignment assn in spListItem.RoleAssignments) { if (assn.Member.GetType() == typeof(Microsoft.SharePoint.SPGroup)) { try { SPGroup group = web.SiteGroups.GetByID(assn.Member.ID); if (group.CanCurrentUserEditMembership) { string[] sG = group.Name.Split(' '); if (sG[sG.Length - 1] == "Member") { sDefaultGroup = group.ID.ToString(); } bCanEditTeam = "true"; } } catch { } } } } } }); } else { foreach (SPGroup g in web.Groups) { string[] sG = g.Name.Split(' '); if (sG[sG.Length - 1] == "Member") { sDefaultGroup = g.ID.ToString(); } if (g.CanCurrentUserEditMembership) { bCanEditTeam = "true"; } } } if (itemid > 0 && listid != Guid.Empty && PfeData.ConnectionProvider.AllowDatabaseConnections(web)) { // collect pfe database project id for processing in UI part var repository = new PfeData.ProjectRepository(); projectIdInPfe = repository.FindProjectId(web, listid, itemid); } if (web.Features[new Guid("84520a2b-8e2b-4ada-8f48-60b138923d01")] == null && !bUseTeam) { sDisable = "_spBodyOnLoadFunctionNames.push(\"ShowDisable\");"; SPList teamlist = web.Lists["Team"]; //if(web.DoesUserHavePermissions(SPBasePermissions.ManagePermissions)) //{ // bCanEditTeam = "true"; //} } else { try { using (SPSite rsite = new SPSite(resUrl)) { using (SPWeb rweb = rsite.OpenWeb()) { SPList list = rweb.Lists["Resources"]; //DataTable dtTemp = list.Items.GetDataTable(); bCanAccessResourcePool = "true"; if (list.DoesUserHavePermissions(SPBasePermissions.AddListItems)) { bCanAddResource = "true"; sNewResUrl = list.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl; } } } } catch { } XmlDocument doc = new XmlDocument(); doc.LoadXml("<Grid/>"); if (bUseTeam) { try { if (oLi.DoesUserHavePermissions(SPBasePermissions.EditListItems)) { bCanEditTeam = "true"; } XmlAttribute attr = doc.CreateAttribute("WebId"); attr.Value = Convert.ToString(web.ID); doc.FirstChild.Attributes.Append(attr); attr = doc.CreateAttribute("ListId"); attr.Value = Convert.ToString(listid); doc.FirstChild.Attributes.Append(attr); attr = doc.CreateAttribute("ItemId"); attr.Value = Convert.ToString(itemid); doc.FirstChild.Attributes.Append(attr); } catch { } } else { SPList teamlist = web.Lists.TryGetList("Team"); if (teamlist == null) { web.AllowUnsafeUpdates = true; web.Lists.Add("Team", "Use this list to manage your project team", SPListTemplateType.GenericList); teamlist = web.Lists.TryGetList("Team"); try { teamlist.Fields.Add("ResID", SPFieldType.Number, false); teamlist.Update(); } catch { } } } sLayoutParam = HttpUtility.HtmlEncode(doc.OuterXml); if (bCanEditTeam == "true") { sResPool = Properties.Resources.txtBuildTeamResPool.Replace("#LayoutParam#", sLayoutParam).Replace("#DataParam#", sLayoutParam); sResGrid = @"TreeGrid( { Layout:{ Url:""../../_vti_bin/WorkEngine.asmx"",Timeout:0, Method:""Soap"",Function:""Execute"",Namespace:""workengine.com"",Param:{Function:""GetResourceGridLayout"",Dataxml:""" + sLayoutParam + @""" } } , Data:{ Url:""../../_vti_bin/WorkEngine.asmx"",Timeout:0, Method:""Soap"",Function:""Execute"",Namespace:""workengine.com"",Param:{Function:""GetResourceGridData"",Dataxml:""" + sLayoutParam + @""" } }, Debug:"""",SuppressMessage:""3"" }, ""divResPool"" );" ; } } sUserInfoList = web.SiteUserInfoList.ID.ToString().ToUpper(); if (Request["isDlg"] == "1") { sClose = "SP.SOD.execute('SP.UI.Dialog.js', 'SP.UI.ModalDialog.commonModalDialogClose', SP.UI.DialogResult.OK, '');"; } else { if (String.IsNullOrEmpty(Request["Source"])) { sClose = "location.href='" + ((web.ServerRelativeUrl == "/") ? "" : web.ServerRelativeUrl) + "'"; } else { sClose = "location.href='" + Request["Source"] + "'"; } } }
public void GetRibbonProps_ContentTypesEnabledTrue_ReturnsGridGanttSettings() { // Arrange ShimSPSecurableObject.AllInstances.DoesUserHavePermissionsSPBasePermissions = (sender, permission) => true; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => { if (internalName == "AssignedTo") { return(new ShimSPField()); } return(null); } }, TitleGet = () => DummyTitle }; ShimSPSite.AllInstances.OpenWeb = sender => new ShimSPWeb() { ListsGet = () => new ShimSPListCollection() { ItemGetString = name => new ShimSPList(new ShimSPDocumentLibrary()) { ContentTypesEnabledGet = () => false, ContentTypesGet = () => new ShimSPContentTypeCollection().Bind( new SPContentType[] { new ShimSPContentType() { DocumentTemplateUrlGet = () => "mpp" } }) } } }; ShimSPSite.AllInstances.FeaturesGet = sender => new ShimSPFeatureCollection() { ItemGetGuid = guid => new ShimSPFeature() }; ShimSPSite.AllInstances.RootWebGet = sender => new ShimSPWeb(); var gridGranttSettings = new ShimGridGanttSettings(); gridGranttSettings.Instance.BuildTeam = true; ShimListCommands.GetGridGanttSettingsSPList = listParam => gridGranttSettings; // Act var actualResult = ListCommands.GetRibbonProps(list); // Assert this.ShouldSatisfyAllConditions( () => actualResult.bBuildTeam.ShouldBeTrue(), () => actualResult.bDisableProject.ShouldBeTrue(), () => actualResult.bDisablePlan.ShouldBeTrue(), () => actualResult.aEPKButtons.Count.ShouldBe(1), () => actualResult.aEPKButtons[0].ShouldBe("EPKMenus"), () => actualResult.aEPKActivex.Count.ShouldBe(1), () => actualResult.aEPKActivex[0].ShouldBe("epknonactivexs")); }