diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetFolderController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetFolderController.java index 36002fc76..778398782 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetFolderController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/AssetFolderController.java @@ -7,7 +7,6 @@ package org.librecms.ui.contentsections; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.AuthorizationRequired; -import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionManager; import org.libreccm.security.Role; import org.libreccm.security.RoleRepository; @@ -256,9 +255,7 @@ public class AssetFolderController { if (parentFolderResult.isPresent()) { parentFolder = parentFolderResult.get(); } else { - models.put("contentSection", section.getLabel()); - models.put("folderPath", parentFolderPath); - return "org/librecms/ui/contentsection/assetfolder/assetfolder-not-found.xhtml"; + return showAssetFolderNotFound(section, folderName); } } @@ -312,8 +309,9 @@ public class AssetFolderController { return sectionsUi.showContentSectionNotFound(sectionIdentifier); } if (!assetPermissionsChecker.canEditAssets(section)) { - models.put("sectionidentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier + ); } final Folder folder; @@ -332,16 +330,15 @@ public class AssetFolderController { assetFolderModel.setBreadcrumbs(buildBreadcrumbs(folderPath)); } else { - models.put("contentSection", section.getLabel()); - models.put("folderPath", folderPath); - return "org/librecms/ui/contentsection/assestfolder/assetfolder-not-found.xhtml"; + return showAssetFolderNotFound(section, folderPath); } } if (!assetPermissionsChecker.canEditAssets(folder)) { - models.put("sectionidentifier", sectionIdentifier); - models.put("folderPath", folderPath); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier, + "folderPath", folderPath + ); } final Optional roleResult = roleRepo.findByName(roleParam); @@ -395,8 +392,9 @@ public class AssetFolderController { return sectionsUi.showContentSectionNotFound(sectionIdentifier); } if (!assetPermissionsChecker.canEditAssets(section)) { - models.put("sectionidentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier + ); } final Folder folder; @@ -411,15 +409,14 @@ public class AssetFolderController { assetFolderModel.setBreadcrumbs(buildBreadcrumbs(folderPath)); } else { - models.put("contentSection", section.getLabel()); - models.put("folderPath", folderPath); - return "org/librecms/ui/contentsection/assetfolder/assetfolder-not-found.xhtml"; + return showAssetFolderNotFound(section, folderPath); } if (!assetPermissionsChecker.canEditAssets(folder)) { - models.put("sectionidentifier", sectionIdentifier); - models.put("folderPath", folderPath); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier, + "folderPath", folderPath + ); } folder.setName(folderName); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationController.java index 3f104fe4f..388e8b60c 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationController.java @@ -39,6 +39,9 @@ public class ConfigurationController { @Inject private ContentSectionRepository sectionRepo; + @Inject + private ContentSectionsUi sectionsUi; + @Inject private IdentifierParser identifierParser; @@ -55,43 +58,19 @@ public class ConfigurationController { public String showConfigurationIndexPage( @PathParam("sectionIdentifier") final String sectionIdentifierParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); if (!hasRequiredPermission(section)) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } - return "org/librecms/ui/contentsection/configuration/index.xhtml"; } @@ -105,7 +84,8 @@ public class ConfigurationController { || permissionChecker.isPermitted( AdminPrivileges.ADMINISTER_ROLES, section ) - || permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS, section + || permissionChecker.isPermitted( + AdminPrivileges.ADMINISTER_WORKFLOWS, section ); } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationDocumentTypesController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationDocumentTypesController.java index 871ece71a..5051cc37e 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationDocumentTypesController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationDocumentTypesController.java @@ -53,6 +53,9 @@ import javax.ws.rs.PathParam; @Path("/{sectionIdentifier}/configuration/documenttypes") public class ConfigurationDocumentTypesController { + @Inject + private AdminPermissionsChecker adminPermissionsChecker; + @Inject private CmsAdminMessages cmsAdminMessages; @@ -63,7 +66,7 @@ public class ConfigurationDocumentTypesController { private ContentSectionManager sectionManager; @Inject - private ContentSectionRepository sectionRepo; + private ContentSectionsUi sectionsUi; @Inject private ContentTypeManager typeManager; @@ -99,43 +102,17 @@ public class ConfigurationDocumentTypesController { public String listDocumentTypes( @PathParam("sectionIdentifier") final String sectionIdentifierParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerContentTypes(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } documentTypesModel.setAssignedTypes( @@ -201,43 +178,17 @@ public class ConfigurationDocumentTypesController { @FormParam("defaultLifecycleUuid") final String defaultLifecycleUuid, @FormParam("defaultWorkflowUuid") final String defaultWorkflowUuid ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerContentTypes(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional typeInfo = typesManager @@ -309,113 +260,6 @@ public class ConfigurationDocumentTypesController { ); } -// @GET -// @Path("/{documentType}") -// public String showDocumentType( -// @PathParam("sectionIdentifier") final String sectionIdentifierParam, -// @PathParam("documentType") final String documentTypeParam -// ) { -// final Identifier sectionIdentifier = identifierParser.parseIdentifier( -// sectionIdentifierParam -// ); -// -// final Optional sectionResult; -// switch (sectionIdentifier.getType()) { -// case ID: -// sectionResult = sectionRepo.findById( -// Long.parseLong( -// sectionIdentifier.getIdentifier() -// ) -// ); -// break; -// case UUID: -// sectionResult = sectionRepo.findByUuid( -// sectionIdentifier.getIdentifier() -// ); -// break; -// default: -// sectionResult = sectionRepo.findByLabel( -// sectionIdentifier.getIdentifier() -// ); -// break; -// } -// -// if (!sectionResult.isPresent()) { -// models.put("sectionIdentifier", sectionIdentifier); -// return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; -// } -// final ContentSection section = sectionResult.get(); -// sectionModel.setSection(section); -// -// if (!permissionChecker.isPermitted( -// AdminPrivileges.ADMINISTER_CONTENT_TYPES, section -// )) { -// models.put("sectionIdentifier", sectionIdentifier); -// return "org/librecms/ui/contentsection/access-denied.xhtml"; -// } -// -// final Optional typeResult = section -// .getContentTypes() -// .stream() -// .filter(type -> type.getContentItemClass().equals(documentTypeParam)) -// .findAny(); -// -// if (!typeResult.isPresent()) { -// return "org/librecms/ui/contentsection/configuration/documenttype-not-found.xhtml"; -// } -// -// final ContentType type = typeResult.get(); -// -// documentTypeModel.setContentItemClass(sectionIdentifierParam); -// documentTypeModel.setDescriptions( -// type -// .getDescription() -// .getValues() -// .entrySet() -// .stream() -// .collect(Collectors.toMap( -// entry -> entry.getKey().toString(), -// entry -> entry.getValue() -// )) -// ); -// documentTypeModel.setLabels( -// type -// .getLabel() -// .getValues() -// .entrySet() -// .stream() -// .collect(Collectors.toMap( -// entry -> entry.getKey().toString(), -// entry -> entry.getValue() -// )) -// ); -// -// final LifecycleDefinition defaultLifecycle = type.getDefaultLifecycle(); -// documentTypeModel.setLifecycles( -// section -// .getLifecycleDefinitions() -// .stream() -// .map( -// def -> buildLifecycleModel( -// def, def.equals(defaultLifecycle) -// ) -// ).collect(Collectors.toList()) -// ); -// -// final Workflow defaultWorkflow = type.getDefaultWorkflow(); -// documentTypeModel.setWorkflows( -// section -// .getWorkflowTemplates() -// .stream() -// .map( -// template -> buildWorkflowModel( -// template, template.equals(defaultWorkflow) -// ) -// ).collect(Collectors.toList()) -// ); -// -// return "org/librecms/ui/contentsection/configuration/documenttype.xhtml"; -// } @POST @Path("/{documentType}") @AuthorizationRequired @@ -427,43 +271,17 @@ public class ConfigurationDocumentTypesController { @FormParam("defaultWorkflowUuid") final String defaultWorkflowUuid, @FormParam("roleUuids") final Set roleUuids ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerContentTypes(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional typeResult = section @@ -625,43 +443,17 @@ public class ConfigurationDocumentTypesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("documentType") final String documentTypeParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerContentTypes(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional typeResult = section @@ -743,9 +535,9 @@ public class ConfigurationDocumentTypesController { model.setDescription(descUtil.getText(typeInfo.getDescriptionKey())); model.setMode( Optional - .ofNullable(type.getMode()) - .map(ContentTypeMode::toString) - .orElse("") + .ofNullable(type.getMode()) + .map(ContentTypeMode::toString) + .orElse("") ); model.setPermissions( diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationRolesController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationRolesController.java index 28506673f..dc66f4043 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationRolesController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ConfigurationRolesController.java @@ -7,12 +7,10 @@ package org.librecms.ui.contentsections; import org.libreccm.api.Identifier; import org.libreccm.api.IdentifierParser; -import org.libreccm.core.CcmObject; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.Party; import org.libreccm.security.PartyRepository; -import org.libreccm.security.Permission; import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionManager; import org.libreccm.security.Role; @@ -33,7 +31,6 @@ import javax.ws.rs.PathParam; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.Folder; import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AssetPrivileges; @@ -58,6 +55,9 @@ import javax.ws.rs.POST; @Path("/{sectionIdentifier}/configuration/roles") public class ConfigurationRolesController { + @Inject + private AdminPermissionsChecker adminPermissionsChecker; + @Inject private CmsAdminMessages messages; @@ -67,8 +67,10 @@ public class ConfigurationRolesController { @Inject private ContentSectionModel sectionModel; +// @Inject +// private ContentSectionRepository sectionRepo; @Inject - private ContentSectionRepository sectionRepo; + private ContentSectionsUi sectionsUi; @Inject private GlobalizationHelper globalizationHelper; @@ -104,43 +106,19 @@ public class ConfigurationRolesController { public String listRoles( @PathParam("sectionIdentifier") final String sectionIdentifierParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final List sectionRoles = section.getRoles(); @@ -179,43 +157,18 @@ public class ConfigurationRolesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("roleName") final String roleName ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -225,9 +178,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -278,43 +229,18 @@ public class ConfigurationRolesController { @PathParam("roleName") final String roleName, @FormParam("roleName") final String newRoleName ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -324,9 +250,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -349,43 +273,18 @@ public class ConfigurationRolesController { @PathParam("roleName") final String roleName, @FormParam("grantedPermissions") final List grantedPermissions ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -395,9 +294,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -458,43 +355,18 @@ public class ConfigurationRolesController { @PathParam("roleName") final String roleName, @FormParam("roleMembers") final List roleMembersParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -504,9 +376,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -550,43 +420,18 @@ public class ConfigurationRolesController { @FormParam("locale") final String localeParam, @FormParam("value") final String value ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -596,9 +441,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -623,43 +466,18 @@ public class ConfigurationRolesController { @PathParam("locale") final String localeParam, @FormParam("value") final String value ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -669,9 +487,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -696,43 +512,18 @@ public class ConfigurationRolesController { @PathParam("locale") final String localeParam, @FormParam("value") final String value ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final Optional result = section @@ -742,9 +533,7 @@ public class ConfigurationRolesController { .findAny(); if (!result.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - models.put("roleName", roleName); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleName); } final Role role = result.get(); @@ -766,43 +555,18 @@ public class ConfigurationRolesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @FormParam("roleName") final String roleName ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } final List errors = new ArrayList<>(); @@ -841,43 +605,18 @@ public class ConfigurationRolesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @FormParam("rolesToAdd") final List rolesToAdd ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } for (final String roleUuid : rolesToAdd) { @@ -903,71 +642,24 @@ public class ConfigurationRolesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("roleIdentifier") final String roleIdentifierParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } - - final Identifier roleIdentifier = identifierParser.parseIdentifier( - roleIdentifierParam - ); - - final Optional roleResult; - switch (roleIdentifier.getType()) { - case ID: - roleResult = roleRepo.findById( - Long.parseLong(roleIdentifier.getIdentifier()) - ); - break; - case UUID: - roleResult = roleRepo.findByUuid( - roleIdentifier.getIdentifier() - ); - break; - default: - roleResult = roleRepo.findByName( - roleIdentifier.getIdentifier() - ); - break; - } - + + final Optional roleResult = findRole(roleIdentifierParam); if (!roleResult.isPresent()) { - models.put("roleIdentifier", roleIdentifierParam); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleIdentifierParam); } final Role role = roleResult.get(); sectionManager.removeRoleFromContentSection(section, role); @@ -985,71 +677,23 @@ public class ConfigurationRolesController { @PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("roleIdentifier") final String roleIdentifierParam ) { - final Identifier sectionIdentifier = identifierParser.parseIdentifier( - sectionIdentifierParam - ); - - final Optional sectionResult; - switch (sectionIdentifier.getType()) { - case ID: - sectionResult = sectionRepo.findById( - Long.parseLong( - sectionIdentifier.getIdentifier() - ) - ); - break; - case UUID: - sectionResult = sectionRepo.findByUuid( - sectionIdentifier.getIdentifier() - ); - break; - default: - sectionResult = sectionRepo.findByLabel( - sectionIdentifier.getIdentifier() - ); - break; - } - + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifierParam); if (!sectionResult.isPresent()) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + return sectionsUi.showContentSectionNotFound(sectionIdentifierParam); } final ContentSection section = sectionResult.get(); sectionModel.setSection(section); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES, section - )) { - models.put("sectionIdentifier", sectionIdentifier); - return "org/librecms/ui/contentsection/access-denied.xhtml"; - } - - final Identifier roleIdentifier = identifierParser.parseIdentifier( - roleIdentifierParam - ); - - final Optional roleResult; - switch (roleIdentifier.getType()) { - case ID: - roleResult = roleRepo.findById( - Long.parseLong(roleIdentifier.getIdentifier()) - ); - break; - case UUID: - roleResult = roleRepo.findByUuid( - roleIdentifier.getIdentifier() - ); - break; - default: - roleResult = roleRepo.findByName( - roleIdentifier.getIdentifier() - ); - break; + if (!adminPermissionsChecker.canAdministerRoles(section)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifierParam + ); } + final Optional roleResult = findRole(roleIdentifierParam); if (!roleResult.isPresent()) { - models.put("roleIdentifier", roleIdentifierParam); - return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + return showRoleNotFound(section, roleIdentifierParam); } final Role role = roleResult.get(); sectionManager.removeRoleFromContentSection(section, role); @@ -1060,6 +704,34 @@ public class ConfigurationRolesController { ); } + private Optional findRole(final String roleIdentifierParam) { + final Identifier roleIdentifier = identifierParser.parseIdentifier( + roleIdentifierParam + ); + switch (roleIdentifier.getType()) { + case ID: + return roleRepo.findById( + Long.parseLong(roleIdentifier.getIdentifier()) + ); + case UUID: + return roleRepo.findByUuid( + roleIdentifier.getIdentifier() + ); + default: + return roleRepo.findByName( + roleIdentifier.getIdentifier() + ); + } + } + + private String showRoleNotFound( + final ContentSection section, final String roleName + ) { + models.put("sectionIdentifier", section.getLabel()); + models.put("roleName", roleName); + return "org/librecms/ui/contentsection/configuration/role-not-found.xhtml"; + } + private RoleListItemModel buildRoleListModel(final Role role) { final RoleListItemModel model = new RoleListItemModel(); model.setRoleId(role.getRoleId()); @@ -1083,18 +755,6 @@ public class ConfigurationRolesController { return model; } - private boolean onlyContentSectionPermissions( - final Permission permission, final ContentSection section - ) { - final Folder rootDocumentsFolder = section.getRootDocumentsFolder(); - final Folder rootAssetsFolder = section.getRootAssetsFolder(); - - final CcmObject object = permission.getObject(); - return section.equals(object) - || rootDocumentsFolder.equals(object) - || rootAssetsFolder.equals(object); - } - private List buildRolePermissions( final Role role, final ContentSection section ) { diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java index d699366f8..ff632d003 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java @@ -7,7 +7,6 @@ package org.librecms.ui.contentsections; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.libreccm.api.Identifier; import org.libreccm.api.IdentifierParser; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.AuthorizationRequired; @@ -20,7 +19,6 @@ import org.librecms.contentsection.ContentItemL10NManager; import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentTypeRepository; import org.librecms.contentsection.DocumentFolderEntry; @@ -105,12 +103,6 @@ public class DocumentFolderController { @Inject private Models models; - @Inject - private IdentifierParser identifierParser; - - @Inject - private PermissionChecker permissionChecker; - @Inject private PermissionManager permissionManager;