protected void ValidateOrganizationHeader(int initialOrganizationId, string objectType) { if (OrganizationContext.SpecifiedOrganizationDoesNotExist) { var message = "The organization specified in the header does not exist"; AddError(message); } else { // Treating these errors as Not Found errors if (OrganizationContext.HasOrganization) { if (initialOrganizationId != OrganizationContext.OrganizationId) { var message = $"The current {objectType} doesn't belong to the organization specified in the header"; AddError(message, 404); } } if (!CurrentUserOrgIds.Contains(initialOrganizationId)) { var message = $"The current user is not a member of the {objectType} organization"; AddError(message, 404); } } }
protected void ValidateProject() { if ((Organization == null) || (Group == null) || (ProjectOwner == null)) { // Allowing it to return in these cases should cause the base to hit normal // foreign key failures return; } if (Organization != Group.Owner) { var message = "The group associated with this project is not owned by the project organization"; AddError(message); } if ((ProjectOwner.OrganizationIds == null) || (!ProjectOwner.OrganizationIds.Contains(Organization.Id))) { var message = "The project owner is not a member of the project organization"; AddError(message); } // The current user should be a member of the organization if ((!CurrentUserOrgIds.Contains(Organization.Id)) && (!IsCurrentUserSuperAdmin())) { var message = ("The current user is not a member of the project organization"); AddError(message); } if (ProjectOwner.PublishingKey == null) { var message = ("The project owner's publishing key is not set"); AddError(message); } else if (!ValidPublishingKey(ProjectOwner.PublishingKey)) { var message = ("The project owner's publishing key is not valid"); AddError(message); } }
protected void ValidateProduct(Project project, ProductDefinition productDefinition, Store store, int?storeLanguageId) { if ((project == null) || (productDefinition == null)) { // Allowing it to return in these cases should cause the base to hit normal // foreign key failures return; } if (store != null) { if (!(store.StoreTypeId == productDefinition.Workflow.StoreTypeId)) { var message = "The store type values do not match for this product"; AddError(message); } if (!project.Organization.StoreIds.Contains(store.Id)) { var message = "This store is not permitted for this product"; AddError(message); } if (!storeLanguageId.HasValue) { var message = "A Store is specified but there is no store language for this product"; AddError(message); } else if (!store.StoreType.LanguageIds.Contains(storeLanguageId.Value)) { var message = "Invalid store language for this product"; AddError(message); } } if (!project.Organization.ProductDefinitionIds.Contains(productDefinition.Id)) { var message = $"This product is not permitted for the organization"; AddError(message); } if (project.WorkflowProjectUrl == null) { var message = $"There is no workflow project url for this product"; AddError(message); } // The current user should be a member of the organization if ((!CurrentUserOrgIds.Contains(project.Organization.Id)) && (!IsCurrentUserSuperAdmin())) { var message = ("The current user is not a member of the organization"); AddError(message); } }
public bool IsValid(int id, Group group) { //If changing owner (which is an organization), validate the change CurrentUserOrgIds = CurrentUser.OrganizationIds.OrEmpty(); var original = GroupRepository.Get() .Where(g => g.Id == id) .Include(g => g.Owner) .FirstOrDefaultAsync().Result; ValidateOrganizationHeader(original.OwnerId, "group"); if (group.OwnerId != VALUE_NOT_SET) { if ((!CurrentUserOrgIds.Contains(group.OwnerId)) && (!IsCurrentUserSuperAdmin())) { var message = "You do not belong to an organization that the group is owned by and therefor cannot reassign ownership"; AddError(message); } } return(base.IsValid()); }