示例#1
0
        private bool Can(FileEntry fileEntry, Guid userId, SecurityAction action)
        {
            if (fileEntry == null || project == null)
            {
                return(false);
            }

            if (!ProjectSecurity.CanReadFiles(project, userId))
            {
                return(false);
            }

            if (project.Status == ProjectStatus.Closed &&
                action != SecurityAction.Read)
            {
                return(false);
            }

            if (ProjectSecurity.IsAdministrator(userId))
            {
                return(true);
            }

            using (var scope = DIHelper.Resolve())
            {
                var projectEngine = scope.Resolve <EngineFactory>().ProjectEngine;

                var folder = fileEntry as Folder;
                if (folder != null && folder.FolderType == FolderType.DEFAULT && folder.CreateBy == userId)
                {
                    return(true);
                }

                var file = fileEntry as File;
                if (file != null && file.CreateBy == userId)
                {
                    return(true);
                }

                switch (action)
                {
                case SecurityAction.Read:
                    return(!project.Private || projectEngine.IsInTeam(project.ID, userId));

                case SecurityAction.Create:
                case SecurityAction.Edit:
                    return(projectEngine.IsInTeam(project.ID, userId) &&
                           (!ProjectSecurity.IsVisitor(userId) ||
                            folder != null && folder.FolderType == FolderType.BUNCH));

                case SecurityAction.Delete:
                    return(!ProjectSecurity.IsVisitor(userId) && project.Responsible == userId);

                default:
                    return(false);
                }
            }
        }
        private bool Can(FileEntry fileEntry, Guid userId, SecurityAction action)
        {
            if (fileEntry == null || Project == null)
            {
                return(false);
            }

            if (!ProjectSecurity.CanReadFiles(Project, userId))
            {
                return(false);
            }

            if (Project.Status != ProjectStatus.Open &&
                action != SecurityAction.Read)
            {
                return(false);
            }

            if (ProjectSecurity.IsAdministrator(userId))
            {
                return(true);
            }

            var folder = fileEntry as Folder;

            if (folder != null && folder.FolderType == FolderType.DEFAULT && folder.CreateBy == userId)
            {
                return(true);
            }

            var file = fileEntry as File;

            if (file != null && file.CreateBy == userId)
            {
                return(true);
            }

            switch (action)
            {
            case SecurityAction.Read:
                return(!Project.Private || Global.EngineFactory.ProjectEngine.IsInTeam(Project.ID, userId));

            case SecurityAction.Create:
            case SecurityAction.Edit:
                return(Global.EngineFactory.ProjectEngine.IsInTeam(Project.ID, userId) &&
                       (!ProjectSecurity.IsVisitor(userId) || folder != null && folder.FolderType == FolderType.BUNCH));

            case SecurityAction.Delete:
                return(!ProjectSecurity.IsVisitor(userId) && Project.Responsible == userId);

            default:
                return(false);
            }
        }
        private bool Can(FileEntry fileEntry, Guid userId, SecurityAction action)
        {
            if (!ProjectSecurity.CanReadFiles(Project, userId))
            {
                return(false);
            }

            if (ProjectSecurity.IsAdministrator(userId))
            {
                return(true);
            }
            if (fileEntry == null || Project == null)
            {
                return(false);
            }
            if (fileEntry is Folder && ((Folder)fileEntry).FolderType == FolderType.DEFAULT && fileEntry.CreateBy == userId)
            {
                return(true);
            }
            if (fileEntry is File && fileEntry.CreateBy == userId)
            {
                return(true);
            }

            switch (action)
            {
            case SecurityAction.Read:
                return(!Project.Private || dao.IsInTeam(Project.ID, userId));

            case SecurityAction.Create:
            case SecurityAction.Edit:
                return(dao.IsInTeam(Project.ID, userId) &&
                       (!ProjectSecurity.IsVisitor(userId) || fileEntry is Folder && ((Folder)fileEntry).FolderType == FolderType.BUNCH));

            case SecurityAction.Delete:
                return(!ProjectSecurity.IsVisitor(userId) && Project.Responsible == userId);

            default:
                return(false);
            }
        }