public PermissionCheckResult HasPermission(FirmaSession firmaSession, Project contextModelObject)
        {
            var hasPermissionByPerson = HasPermissionByFirmaSession(firmaSession);

            if (!hasPermissionByPerson)
            {
                return(new PermissionCheckResult($"You don't have permission to Edit {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {contextModelObject.GetDisplayName()}"));
            }

            if (contextModelObject.IsProposal())
            {
                return(new PermissionCheckResult($"{FieldDefinitionEnum.Proposal.ToType().GetFieldDefinitionLabelPluralized()} cannot be updated through the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} Update process."));
            }

            if (!contextModelObject.IsUpdatableViaProjectUpdateProcess())
            {
                return(new PermissionCheckResult($"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {contextModelObject.GetDisplayName()} is not updateable via the {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} Update process"));
            }

            bool hasUpdateAdminPermission = new ProjectUpdateAdminFeatureWithProjectContext().HasPermission(firmaSession, contextModelObject).HasPermission;
            bool isUsersProject           = contextModelObject.IsMyProject(firmaSession);

            var projectIsEditableByUser = hasUpdateAdminPermission || isUsersProject;

            if (!projectIsEditableByUser)
            {
                return(new PermissionCheckResult($"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {contextModelObject.ProjectID} is not editable by you."));
            }

            return(new PermissionCheckResult());
        }
Ejemplo n.º 2
0
        public PermissionCheckResult HasPermission(FirmaSession firmaSession, Project contextModelObject)
        {
            if (contextModelObject.IsRejected() || contextModelObject.IsProposal() || contextModelObject.IsPendingProject())
            {
                return(new ProjectCreateFeature().HasPermission(firmaSession, contextModelObject));
            }
            else
            {
                var hasPermissionByPerson = HasPermissionByFirmaSession(firmaSession);
                if (!hasPermissionByPerson)
                {
                    return(new PermissionCheckResult("You do not have permission to access the Project History Timeline"));
                }

                bool isUsersProject = contextModelObject.IsMyProject(firmaSession);
                bool userHasUpdateAdminPermission = new ProjectUpdateAdminFeatureWithProjectContext().HasPermission(firmaSession, contextModelObject).HasPermission;
                var  projectIsEditableByUser      = userHasUpdateAdminPermission || isUsersProject;
                if (projectIsEditableByUser)
                {
                    return(new PermissionCheckResult());
                }

                return(new PermissionCheckResult("You do not have permission to access the Project History Timeline"));
            }
        }
        public PermissionCheckResult HasPermission(Person person, Project contextModelObject)
        {
            var hasPermissionByPerson = HasPermissionByPerson(person);

            if (!hasPermissionByPerson)
            {
                return(PermissionCheckResult.MakeFailurePermissionCheckResult($"You don't have permission to Edit {FieldDefinition.Project.GetFieldDefinitionLabel()} {contextModelObject.DisplayName}"));
            }

            if (contextModelObject.IsProposal())
            {
                return(PermissionCheckResult.MakeFailurePermissionCheckResult($"{FieldDefinition.Application.GetFieldDefinitionLabelPluralized()} cannot be updated through the {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update process."));
            }

            if (!contextModelObject.IsUpdatableViaProjectUpdateProcess)
            {
                return(PermissionCheckResult.MakeFailurePermissionCheckResult($"{FieldDefinition.Project.GetFieldDefinitionLabel()} {contextModelObject.DisplayName} is not updatable via the {FieldDefinition.Project.GetFieldDefinitionLabel()} Update process"));
            }

            var projectIsEditableByUser = new ProjectUpdateAdminFeatureWithProjectContext().HasPermission(person, contextModelObject).HasPermission || contextModelObject.IsMyProject(person);

            if (!projectIsEditableByUser)
            {
                return(PermissionCheckResult.MakeFailurePermissionCheckResult($"{FieldDefinition.Project.GetFieldDefinitionLabel()} {contextModelObject.ProjectID} is not editable by you."));
            }

            return(PermissionCheckResult.MakeSuccessPermissionCheckResult());
        }
Ejemplo n.º 4
0
        public PermissionCheckResult HasPermission(FirmaSession firmaSession, ActionItem contextModelObject)
        {
            var project = contextModelObject.Project;

            if (project.IsRejected() || project.IsProposal() || project.IsPendingProject())
            {
                return(new ProjectCreateFeature().HasPermission(firmaSession, project));
            }
            else
            {
                var hasPermissionByPerson = HasPermissionByFirmaSession(firmaSession);
                if (!hasPermissionByPerson)
                {
                    return(new PermissionCheckResult($"You do not have permission to manage {FieldDefinitionEnum.ActionItem.ToType().GetFieldDefinitionLabelPluralized()} for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}"));
                }

                var projectIsEditableByUser = new ProjectUpdateAdminFeatureWithProjectContext().HasPermission(firmaSession, project).HasPermission || project.IsMyProject(firmaSession);
                if (projectIsEditableByUser)
                {
                    return(new PermissionCheckResult());
                }

                return(new PermissionCheckResult($"You do not have permission to manage {FieldDefinitionEnum.ActionItem.ToType().GetFieldDefinitionLabelPluralized()} for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}"));
            }
        }