public PermissionActionResult(PermissionResult permission, HttpRequestMessage request) {
            if (permission == null)
                throw new ArgumentNullException("permission");

            if (request == null)
                throw new ArgumentNullException("request");

            Permission = permission;
            Request = request;
        }
Ejemplo n.º 2
0
        protected override async Task <PermissionResult> CanDeleteAsync(Organization value)
        {
            if (!String.IsNullOrEmpty(value.StripeCustomerId) && !User.IsInRole(AuthorizationRoles.GlobalAdmin))
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it has a subscription.", value.Id));
            }

            var projects = (await _projectRepository.GetByOrganizationIdAsync(value.Id)).Documents.ToList();

            if (!User.IsInRole(AuthorizationRoles.GlobalAdmin) && projects.Any())
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it contains any projects.", value.Id));
            }

            return(await base.CanDeleteAsync(value));
        }
Ejemplo n.º 3
0
        protected virtual async Task <PermissionResult> CanUpdateAsync(TModel original, Delta <TUpdateModel> changes)
        {
            var orgModel = original as IOwnedByOrganization;

            if (orgModel != null && !CanAccessOrganization(orgModel.OrganizationId))
            {
                return(PermissionResult.DenyWithMessage("Invalid organization id specified."));
            }

            if (changes.GetChangedPropertyNames().Contains("OrganizationId"))
            {
                return(PermissionResult.DenyWithMessage("OrganizationId cannot be modified."));
            }

            return(PermissionResult.Allow);
        }
Ejemplo n.º 4
0
        protected virtual async Task <PermissionResult> CanAddAsync(TModel value)
        {
            var orgModel = value as IOwnedByOrganization;

            if (_isOrganization || orgModel == null)
            {
                return(PermissionResult.Allow);
            }

            if (!CanAccessOrganization(orgModel.OrganizationId))
            {
                return(PermissionResult.DenyWithMessage("Invalid organization id specified."));
            }

            return(PermissionResult.Allow);
        }
        protected virtual PermissionResult CanAdd(TModel value)
        {
            var orgModel = value as IOwnedByOrganization;

            if (_isOrganization || orgModel == null)
            {
                return(PermissionResult.Allow);
            }

            if (!IsInOrganization(orgModel.OrganizationId))
            {
                return(PermissionResult.DenyWithResult(BadRequest("Invalid organization id specified.")));
            }

            return(PermissionResult.Allow);
        }
        protected override PermissionResult CanDelete(Organization value)
        {
            if (!String.IsNullOrEmpty(value.StripeCustomerId) && User.IsInRole(AuthorizationRoles.GlobalAdmin))
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it has a subscription.", value.Id));
            }

            List <Project> projects = _projectRepository.GetByOrganizationId(value.Id).ToList();

            if (!User.IsInRole(AuthorizationRoles.GlobalAdmin) && projects.Any())
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it contains any projects.", value.Id));
            }

            return(base.CanDelete(value));
        }
Ejemplo n.º 7
0
        protected override PermissionResult CanAdd(Project value)
        {
            if (String.IsNullOrEmpty(value.Name))
            {
                return(PermissionResult.DenyWithMessage("Project name is required."));
            }

            if (!IsProjectNameAvailableInternal(value.OrganizationId, value.Name))
            {
                return(PermissionResult.DenyWithMessage("A project with this name already exists."));
            }

            if (!_billingManager.CanAddProject(value))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add additional projects."));
            }

            return(base.CanAdd(value));
        }
Ejemplo n.º 8
0
        protected override async Task <PermissionResult> CanAddAsync(Organization value)
        {
            if (String.IsNullOrEmpty(value.Name))
            {
                return(PermissionResult.DenyWithMessage("Organization name is required."));
            }

            if (!await IsOrganizationNameAvailableInternalAsync(value.Name))
            {
                return(PermissionResult.DenyWithMessage("A organization with this name already exists."));
            }

            if (!await _billingManager.CanAddOrganizationAsync(CurrentUser))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add an additional organization."));
            }

            return(await base.CanAddAsync(value));
        }
        protected override PermissionResult CanAdd(Organization value)
        {
            if (String.IsNullOrEmpty(value.Name))
            {
                return(PermissionResult.DenyWithMessage("Organization name is required."));
            }

            if (!IsOrganizationNameAvailableInternal(value.Name))
            {
                return(PermissionResult.DenyWithMessage("A organization with this name already exists."));
            }

            if (!_billingManager.CanAddOrganization(ExceptionlessUser))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add an additional organization."));
            }

            return(base.CanAdd(value));
        }
 public PermissionActionResult Permission(PermissionResult permission)
 {
     return(new PermissionActionResult(permission, Request));
 }