public bool AllowActionExecution(ModuleLink link, int idUser, int idCommunity, int idRole, Dictionary <string, long> moduleUserLong = null, Dictionary <string, string> moduleUserString = null) { litePerson person = Manager.Get <litePerson>(idUser); switch (link.SourceItem.ObjectTypeID) { case (Int32)ModuleProjectManagement.ObjectType.Project: case (Int32)ModuleProjectManagement.ObjectType.Task: switch (link.DestinationItem.ServiceCode) { case lm.Comol.Core.FileRepository.Domain.ModuleRepository.UniqueCode: ProjectAttachment attachment = AttachmentGet(link); if (attachment != null && attachment.Project != null && attachment.Link != null && link.DestinationItem.ObjectLongID == attachment.Item.Id && link.DestinationItem.FQN == attachment.Item.GetType().FullName) { dtoAttachmentPermission permissions = AttachmentGetPermissions(person, attachment, attachment.Project, attachment.Activity); return(permissions.Play || permissions.Download); } break; default: return(false); } break; default: return(false); } return(false); }
private dtoAttachmentPermission AttachmentGetPermissions(litePerson person, ProjectAttachment attachment, Project project, PmActivity activity) { dtoAttachmentPermission result = new dtoAttachmentPermission(); if (attachment != null && project != null) { lm.Comol.Core.FileRepository.Domain.ModuleRepository repositoryPermissions = GetRepositoryPermissions((project.isPortal) ? 0 : (project.Community == null) ? -1 : project.Community.Id, person.Id); ModuleProjectManagement mPermission = (project.isPortal) ? ModuleProjectManagement.CreatePortalmodule((person == null) ? (Int32)UserTypeStandard.Guest : person.TypeID) : new ModuleProjectManagement(Manager.GetModulePermission(person.Id, (!project.isPortal && project.Community != null) ? project.Community.Id : 0, GetIdModule())); ProjectResource resource = project.Resources.Where(r => r.Deleted == BaseStatusDeleted.None && r.Type == ResourceType.Internal && r.Person == person).FirstOrDefault(); PmActivityPermission rolePermissions = GetRolePermissions(AttachmentGetContainerRole(project, activity, resource, mPermission)); switch (attachment.Type) { case AttachmentType.file: result.Download = (attachment.Item != null && attachment.Item.IsDownloadable || attachment.Item.Type == ItemType.Link) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments)); result.Play = (attachment.Item != null && (attachment.Item.Type == ItemType.Multimedia || attachment.Item.Type == ItemType.ScormPackage || attachment.Item.Type == ItemType.VideoStreaming)) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments)); switch (attachment.Item.Type) { case ItemType.ScormPackage: case ItemType.Multimedia: result.ViewMyStatistics = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments); if (attachment.Item.IsInternal || (repositoryPermissions.Administration || (repositoryPermissions.EditOthersFiles || (repositoryPermissions.EditMyFiles && attachment.Item.IdOwner == person.Id)))) { result.ViewOtherStatistics = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id); result.SetMetadata = result.ViewOtherStatistics; } break; case ItemType.Link: result.Play = result.Download; break; } result.Edit = false; break; case AttachmentType.url: result.Download = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments); result.Play = result.Download; result.Edit = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id); break; } result.Delete = false; result.UnDelete = (attachment.Deleted != BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualUnDeleteAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id)); result.Unlink = (attachment.SharedItems.Any() && activity != null && attachment.SharedItems.Where(s => s.Deleted == BaseStatusDeleted.None && s.Activity != null && s.Activity.Id == activity.Id && s.Type == AttachmentLinkType.Shared).Any() && attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id)); result.VirtualDelete = (attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id)); } return(result); }
private dtoAttachmentPermission AttachmentGetPermissions(litePerson person, dtoAttachment attachment, PmActivity activity, PmActivityPermission rolePermissions, ModuleProjectManagement mPermission, ModuleRepository repositoryPermissions) { dtoAttachmentPermission result = new dtoAttachmentPermission(); switch (attachment.Type) { case AttachmentType.file: result.Download = (attachment.File != null && (attachment.File.IsDownloadable || attachment.File.Type == ItemType.Link)) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments)); result.Play = (attachment.File != null && (attachment.File.Type == ItemType.Multimedia || attachment.File.Type == ItemType.ScormPackage || attachment.File.Type == ItemType.VideoStreaming)) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments)); switch (attachment.File.Type) { case ItemType.ScormPackage: case ItemType.Multimedia: result.ViewMyStatistics = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments); if (attachment.File.IsInternal || (repositoryPermissions.Administration || (repositoryPermissions.EditOthersFiles || (repositoryPermissions.EditMyFiles && attachment.File.IdOwner == person.Id)))) { result.ViewOtherStatistics = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id); result.SetMetadata = result.ViewOtherStatistics; } break; case ItemType.Link: result.Play = result.Download; break; } result.Edit = false; break; case AttachmentType.url: result.Download = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments); result.Play = result.Download; result.Edit = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id); break; } result.Delete = false; result.UnDelete = (attachment.Deleted != BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualUnDeleteAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id)); result.Unlink = (attachment.InSharing && attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.CreatedBy != null && attachment.IdCreatedBy == person.Id)); result.VirtualDelete = (attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id)); return(result); }
private List <StandardActionType> GetAllowedStandardActionForFile(int idUser, ModuleObject source, ModuleObject destination) { List <StandardActionType> actions = new List <StandardActionType>(); litePerson person = Manager.Get <litePerson>(idUser); Project project = ((Int32)ModuleProjectManagement.ObjectType.Project == source.ObjectTypeID) ? Manager.Get <Project>(source.ObjectLongID) : null; PmActivity activity = ((Int32)ModuleProjectManagement.ObjectType.Task == source.ObjectTypeID) ? Manager.Get <PmActivity>(source.ObjectLongID) : null; if (project == null && activity != null) { project = activity.Project; } if (project != null) { ProjectAttachment attachment = AttachmentGet(project, activity, destination.ObjectLongID); if (attachment != null && attachment.Link != null && destination.ObjectLongID == attachment.Item.Id && destination.FQN == attachment.Item.GetType().FullName) { dtoAttachmentPermission permissions = AttachmentGetPermissions(person, attachment, project, activity); if (permissions.SetMetadata) { actions.Add(StandardActionType.EditMetadata); } if (permissions.Play) { actions.Add(StandardActionType.Play); } if (permissions.ViewMyStatistics) { actions.Add(StandardActionType.ViewPersonalStatistics); } if (permissions.ViewOtherStatistics) { actions.Add(StandardActionType.ViewAdvancedStatistics); } } } return(actions); }
private dtoAttachmentPermission AttachmentGetPermissions(litePerson person, dtoAttachment attachment, CoreItemPermission permissions, lm.Comol.Core.FileRepository.Domain.ModuleRepository moduleRepository) { dtoAttachmentPermission result = new dtoAttachmentPermission(); if (attachment.File != null) { Boolean fileRepositoryOwner = (moduleRepository.Administration || (moduleRepository.EditOthersFiles || (moduleRepository.EditMyFiles && attachment.File.IdOwner == person.Id))); result.Download = (attachment.File != null && (attachment.File.IsDownloadable || attachment.File.Type == FileRepository.Domain.ItemType.Link)) && permissions.AllowViewFiles; result.Play = (attachment.File != null && (attachment.File.Type == FileRepository.Domain.ItemType.Multimedia || attachment.File.Type == FileRepository.Domain.ItemType.ScormPackage || attachment.File.Type == FileRepository.Domain.ItemType.VideoStreaming)) && permissions.AllowViewFiles; result.EditVisibility = permissions.AllowEdit; switch (attachment.File.Type) { case FileRepository.Domain.ItemType.Multimedia: case FileRepository.Domain.ItemType.ScormPackage: result.ViewMyStatistics = permissions.AllowViewStatistics; result.SetMetadata = permissions.AllowEdit && (attachment.File.IsInternal || fileRepositoryOwner); result.ViewOtherStatistics = permissions.AllowEdit && (attachment.File.IsInternal || fileRepositoryOwner); break; case FileRepository.Domain.ItemType.Link: result.Play = result.Download; break; } result.Edit = false; result.EditRepositoryVisibility = permissions.AllowEdit && fileRepositoryOwner && !attachment.File.IsInternal; result.EditRepositoryPermission = permissions.AllowEdit && fileRepositoryOwner && !attachment.File.IsInternal; result.Delete = attachment.File.IsInternal && permissions.AllowDelete && (attachment.Deleted != BaseStatusDeleted.None);; result.UnDelete = attachment.File.IsInternal && (attachment.Deleted != BaseStatusDeleted.None) && (permissions.AllowUnDelete); result.VirtualDelete = attachment.File.IsInternal && (attachment.Deleted == BaseStatusDeleted.None) && permissions.AllowUnDelete; result.Unlink = (!attachment.File.IsInternal && permissions.AllowAddFiles); result.Publish = permissions.AllowFilePublish && attachment.File.IsInternal && attachment.Deleted == BaseStatusDeleted.None; } return(result); }