Refactoring

Former-commit-id: eb0a3e61043e50467f73782c91dde61944c7bfb0
pull/10/head
Jens Pelzetter 2021-03-03 19:49:04 +01:00
parent 5c2c27e4aa
commit 71f3c07d41
5 changed files with 193 additions and 772 deletions

View File

@ -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<Role> 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);

View File

@ -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<ContentSection> 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<ContentSection> 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
);
}

View File

@ -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<ContentSection> 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<ContentSection> 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<ContentSection> 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<ContentSection> 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<ContentTypeInfo> 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<ContentSection> 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<ContentType> 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<String> roleUuids
) {
final Identifier sectionIdentifier = identifierParser.parseIdentifier(
sectionIdentifierParam
);
final Optional<ContentSection> 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<ContentSection> 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<ContentType> 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<ContentSection> 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<ContentSection> 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<ContentType> 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(

View File

@ -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<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<String> grantedPermissions
) {
final Identifier sectionIdentifier = identifierParser.parseIdentifier(
sectionIdentifierParam
);
final Optional<ContentSection> 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<ContentSection> 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<Role> 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<String> roleMembersParam
) {
final Identifier sectionIdentifier = identifierParser.parseIdentifier(
sectionIdentifierParam
);
final Optional<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<ContentSection> 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<ContentSection> 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<String> errors = new ArrayList<>();
@ -841,43 +605,18 @@ public class ConfigurationRolesController {
@PathParam("sectionIdentifier") final String sectionIdentifierParam,
@FormParam("rolesToAdd") final List<String> rolesToAdd
) {
final Identifier sectionIdentifier = identifierParser.parseIdentifier(
sectionIdentifierParam
);
final Optional<ContentSection> 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<ContentSection> 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<ContentSection> 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<ContentSection> 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<Role> 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<Role> 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<ContentSection> 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<ContentSection> 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<Role> 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<Role> 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<Role> 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<RoleSectionPermissionModel> buildRolePermissions(
final Role role, final ContentSection section
) {

View File

@ -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;