protected override DriverResult Editor(AttachToMilestonePart part, IUpdateModel updater, dynamic shapeHelper) { if (!this.contentOwnershipService.IsCurrentUserOperator()) { return(null); } // Check whether the given contentItem is a Ticket int?milestoneOfParentId = this.GetMilestoneOfParentId(part); if (milestoneOfParentId == null) { EditAttachToViewModel model = new EditAttachToViewModel(); updater.TryUpdateModel(model, Prefix, null, null); part.Record.MilestoneId = model.SelectedId; part.Record.Size = model.Size; } else { part.Record.MilestoneId = milestoneOfParentId; } return(this.Editor(part, shapeHelper)); }
public ActionResult ProjectMilestones(int projectId) { // check user is operator if (!this.crmContentOwnershipService.IsCurrentUserOperator()) { return(HttpNotFound()); } var project = this.services.ContentManager.Get(projectId); if (!this.crmContentOwnershipService.CurrentUserCanViewContent(project)) { ModelState.AddModelError("ProjectId", new OrchardSecurityException(T("You are not authorized to view the item"))); return(this.CreateActionResultBasedOnAjaxRequest(null, null)); } var milestones = this.milestoneService.GetOpenMilestones(projectId); EditAttachToViewModel model = new EditAttachToViewModel(); Converter.Fill(model.Items, milestones); AjaxMessageViewModel returnValue = new AjaxMessageViewModel { IsDone = true, Data = model }; return(this.Json(returnValue, JsonRequestBehavior.AllowGet)); }
protected override DriverResult Editor(FolderPart part, IUpdateModel updater, dynamic shapeHelper) { if (!this.contentOwnershipService.CurrentUserCanEditContent(part.ContentItem)) { throw new Security.OrchardSecurityException(T("You don't have permission to create/edit the item")); } PostedEditFolderViewModel model = new PostedEditFolderViewModel(); updater.TryUpdateModel(model, Prefix, null, null); EditAttachToViewModel attachToProjectModel = new EditAttachToViewModel(); updater.TryUpdateModel(attachToProjectModel, "AttachToProjectPart", null, null); // not valid if (attachToProjectModel.SelectedId == null) { updater.AddModelError("AttachToProjectPart.ProjectId", T("No project is selected")); return(this.Editor(part, shapeHelper)); } var project = this.projectService.GetProject(attachToProjectModel.SelectedId.Value); if (project == null) { throw new OrchardCoreException(T("There is no project with the given Id")); } // check user has access to the project if (!this.contentOwnershipService.CurrentUserCanEditContent(project)) { throw new Security.OrchardSecurityException(T("You don't have permission to create/edit the item")); } // A folder can not be parent of himself or a sub-folder can not be parent of his parents if (model.ParentId != null) { var folders = this.folderService.GetFolders(attachToProjectModel.SelectedId.Value).Select(c => c.As <FolderPart>()); var ancestors = this.folderService.GetAncestors(folders, model.ParentId.Value).Select(c => c.Id).ToList(); ancestors.Add(part.Id); if (ancestors.Any(c => c == model.ParentId.Value)) { updater.AddModelError("FolderPart.ParentId", T("A Folder can not be parent of himself. Please select another folder.")); return(this.Editor(part, shapeHelper)); } } part.Record.Title = model.Title; part.Record.Parent_Id = model.ParentId; return(this.Editor(part, shapeHelper)); }
protected override DriverResult Editor(AttachToMilestonePart part, dynamic shapeHelper) { if (!this.contentOwnershipService.IsCurrentUserOperator()) { return(null); } int?projectId = this.GetProjectId(part); if (projectId == null) { return(null); } // Check whether the given contentItem is a Ticket int?milestoneOfParentId = this.GetMilestoneOfParentId(part); var milestones = this.milestoneService.GetOpenMilestones(projectId.Value); EditAttachToViewModel model = new EditAttachToViewModel(); model.Size = part.Record.Size; Converter.Fill(model.Items, milestones, false); if (milestoneOfParentId.HasValue) { model.ParentId = milestoneOfParentId; var milestoneOfParent = milestones.FirstOrDefault(c => c.Id == milestoneOfParentId.Value); if (milestoneOfParent != null) { model.ParentName = milestoneOfParent.As <TitlePart>().Title; } } if (part.Record.MilestoneId.HasValue) { var selectedItem = model.Items.FirstOrDefault(c => c.Value == part.Record.MilestoneId.Value.ToString(CultureInfo.InvariantCulture)); if (selectedItem != null) { selectedItem.Selected = true; } } return(ContentShape("Parts_AttachToMilestone_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/AttachToMilestone", Model: model, Prefix: Prefix))); }
protected override DriverResult Editor(AttachToProjectPart part, IUpdateModel updater, dynamic shapeHelper) { EditAttachToViewModel model = new EditAttachToViewModel(); updater.TryUpdateModel(model, Prefix, null, null); // check user has access to old project if (part.Record.Project != null) { var oldProject = this.projectService.GetProject(part.Record.Project.Id); if (oldProject == null) { return(null); } } if (model.SelectedId == null) { part.Record.Project = null; } else { // check user has access to new project var newProject = this.projectService.GetProject(model.SelectedId.Value); if (newProject == null) { return(null); } part.Record.Project = new ProjectPartRecord { Id = model.SelectedId.Value }; } return(this.Editor(part, shapeHelper)); }
protected override DriverResult Editor(AttachToProjectPart part, dynamic shapeHelper) { var settings = part.TypePartDefinition.Settings.GetModel <AttachToProjectPartSettings>(); int?projectId = null; int?parentProjectId = this.GetParentProjectId(part); // if it is Create Mode if (part.Record.Project == null) { projectId = this.projectService.GetProjectIdFromQueryString(); if (projectId != null) { var projectPart = this.projectService.GetProject(projectId.Value); if (projectPart != null) { part.Record.Project = projectPart.Record; } } } else { projectId = part.Record.Project != null ? (int?)part.Record.Project.Id : null; } // For some contents, we don't want to represent the project selection, if (!settings.HiddenInEditMode && parentProjectId == null) { var projects = this.projectService.GetProjects(null).Select(c => c.As <ProjectPart>()).ToList(); if (projects.Count == 0) { return(null); } // user doesn't have access to the project if (projectId.HasValue && !projects.Any(c => c.Id == projectId.Value)) { return(null); } EditAttachToViewModel model = new EditAttachToViewModel(); Converter.Fill(model.Items, projects); if (projectId.HasValue) { var selectedItem = model.Items.FirstOrDefault(c => c.Value == projectId.Value.ToString(CultureInfo.InvariantCulture)); if (selectedItem != null) { selectedItem.Selected = true; } } return(ContentShape("Parts_AttachToProject_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/AttachToProject", Model: model, Prefix: Prefix))); } else { return(ContentShape("Parts_AttachToProject_HiddenField_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/AttachToProject.HiddenField", Model: projectId, Prefix: Prefix))); } }