diff --git a/ccm-cms/src/main/java/org/librecms/assets/Organization.java b/ccm-cms/src/main/java/org/librecms/assets/Organization.java index 94d474582..442761a42 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/Organization.java +++ b/ccm-cms/src/main/java/org/librecms/assets/Organization.java @@ -21,6 +21,9 @@ package org.librecms.assets; import com.arsdigita.cms.ui.assets.forms.OrganizationForm; import org.hibernate.envers.Audited; +import org.librecms.ui.contentsections.assets.MvcAssetEditKit; +import org.librecms.ui.contentsections.assets.OrganizationCreateStep; +import org.librecms.ui.contentsections.assets.OrganizationEditStep; import java.util.Objects; @@ -41,6 +44,10 @@ import static org.librecms.assets.AssetConstants.*; labelKey = "organization.label", descriptionBundle = ASSETS_BUNDLE, descriptionKey = "organization.description") +@MvcAssetEditKit( + createStep = OrganizationCreateStep.class, + editStep = OrganizationEditStep.class +) @Entity @Audited @Table(name = "ORGANIZATIONS", schema = DB_SCHEMA) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetCreateStep.java index 8ffab45e9..773156fa4 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/AbstractMvcAssetCreateStep.java @@ -212,7 +212,7 @@ public abstract class AbstractMvcAssetCreateStep "danger", globalizationHelper .getLocalizedTextsUtil(getBundle()) - .getText("postaladdress.createstep.name.error.invalid") + .getText("createstep.name.error.invalid") ); return showCreateStep(); } @@ -224,7 +224,7 @@ public abstract class AbstractMvcAssetCreateStep "danger", globalizationHelper .getLocalizedTextsUtil(getBundle()) - .getText("postaladdress.createstep.title.error.missing") + .getText("createstep.title.error.missing") ); return showCreateStep(); } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/CmsAssetEditSteps.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/CmsAssetEditSteps.java index 9a155e039..a2d14dc46 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/CmsAssetEditSteps.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/CmsAssetEditSteps.java @@ -35,6 +35,7 @@ public class CmsAssetEditSteps implements MvcAssetEditSteps { classes.add(BookmarkEditStep.class); classes.add(FileAssetEditStep.class); classes.add(LegalMetadataEditStep.class); + classes.add(OrganizationEditStep.class); classes.add(PersonEditStep.class); classes.add(PostalAddressEditStep.class); classes.add(SideNoteEditStep.class); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationCreateStep.java new file mode 100644 index 000000000..a8ec3e418 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationCreateStep.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.assets.Organization; + +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsOrganizationCreateStep") +public class OrganizationCreateStep extends AbstractMvcAssetCreateStep { + + @Inject + private GlobalizationHelper globalizationHelper; + + @Override + public String showCreateStep() { + return "org/librecms/ui/contentsection/assets/organization/create-organization.xhtml"; + } + + @Override + public String getLabel() { + return globalizationHelper + .getLocalizedTextsUtil(getBundle()) + .getText("organization.label"); + } + + @Override + public String getDescription() { + return globalizationHelper + .getLocalizedTextsUtil(getBundle()) + .getText("organization.description"); + } + + @Override + public String getBundle() { + return MvcAssetStepsConstants.BUNDLE; + } + + @Override + protected Class getAssetClass() { + return Organization.class; + } + + @Override + protected String setAssetProperties( + final Organization organization, final Map formParams + ) { + organization.setName(formParams.get("name")[0]); + + return String.format( + "redirect:/%s/assets/%s/%s/@organization-edit", + getContentSectionLabel(), + getFolderPath(), + getName() + ); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationEditStep.java new file mode 100644 index 000000000..d7fe7f777 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/OrganizationEditStep.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +import org.libreccm.security.AuthorizationRequired; +import org.librecms.assets.Organization; +import org.librecms.assets.Person; +import org.librecms.contentsection.AssetRepository; +import org.librecms.ui.contentsections.AssetPermissionsChecker; +import org.librecms.ui.contentsections.ContentSectionNotFoundException; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.mvc.Controller; +import javax.transaction.Transactional; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Path(MvcAssetEditSteps.PATH_PREFIX + "organization-edit") +@Controller +@MvcAssetEditStepDef( + bundle = MvcAssetStepsConstants.BUNDLE, + descriptionKey = "organization.editstep.description", + labelKey = "organization.editstep.label", + supportedAssetType = Person.class +) +public class OrganizationEditStep extends AbstractContactableEntityEditStep { + + @Inject + private AssetStepsDefaultMessagesBundle messageBundle; + + @Inject + private AssetPermissionsChecker assetPermissionsChecker; + + @Inject + private AssetRepository assetRepo; + + @Inject + private AssetUi assetUi; + + @Override + public Class getStepClass() { + return OrganizationEditStep.class; + } + + @GET + @Path("/") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + @Override + public String showStep( + @PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM) + final String sectionIdentifier, + @PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME) + final String assetPath + ) { + try { + init(); + } catch (ContentSectionNotFoundException ex) { + return ex.showErrorMessage(); + } catch (AssetNotFoundException ex) { + return ex.showErrorMessage(); + } + + if (assetPermissionsChecker.canEditAsset(getAsset())) { + return "org/librecms/ui/contentsection/assets/organization/edit-organization.xhtml"; + } else { + return assetUi.showAccessDenied( + getContentSection(), + getAsset(), + messageBundle.get("asset.edit.denied")); + } + } + + @POST + @Path("/name") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + @Override + public String updateName( + @PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM) + final String sectionIdentifier, + @PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME) + final String assetPath, + @FormParam("name") @DefaultValue("") final String name + ) { + super.updateName(sectionIdentifier, assetPath, name); + + if (assetPermissionsChecker.canEditAsset(getAsset())) { + ((Organization) getAsset()).setName(name); + assetRepo.save(getAsset()); + + return buildRedirectPathForStep(); + } else { + return assetUi.showAccessDenied( + getContentSection(), + getAsset(), + messageBundle.get("asset.edit.denied")); + } + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonCreateStep.java index 34cc419c8..18e2bb971 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonCreateStep.java @@ -38,9 +38,6 @@ import javax.inject.Inject; @Named("CmsPersonCreateStep") public class PersonCreateStep extends AbstractMvcAssetCreateStep { - @Inject - private AssetRepository assetRepo; - @Inject private GlobalizationHelper globalizationHelper; diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/create-organization.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/create-organization.xhtml new file mode 100644 index 000000000..35513b649 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/create-organization.xhtml @@ -0,0 +1,64 @@ +]> + + + + +
+

#{CmsAssetsStepsDefaultMessagesBundle["organization.createform.title"]}

+ + + + +
+ + + + + + + + #{CmsAssetsStepsDefaultMessagesBundle['createform.cancel']} + + + + + +
+
+ +
+ diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/edit-organization.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/edit-organization.xhtml new file mode 100644 index 000000000..bd92c80ec --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/organization/edit-organization.xhtml @@ -0,0 +1,29 @@ +]> + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle.properties index e076acc42..9f60282ca 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle.properties @@ -283,3 +283,9 @@ assetpicker.select=Select asset assetpicker.column.name=Name assetpicker.column.type=Type assetpicker.column.action=Action +organization.label=Organization +organization.description=A record with the contact data of an organization. +organization.editstep.description=Edit an organization. +organization.editstep.label=Edit organization +organization.createform.title=Create new organization +organization.editstep.header=Edit Organization {0} diff --git a/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle_de.properties index e835306f4..56a35aaac 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/MvcAssetStepsBundle_de.properties @@ -283,3 +283,9 @@ assetpicker.select=Asset ausw\u00e4hlen assetpicker.column.name=Name assetpicker.column.type=Typ assetpicker.column.action=Aktion +organization.label=Organisation +organization.description=Ein Datensatz mit den Kontaktdaten einer Organization. +organization.editstep.description=Organization bearbeiten. +organization.editstep.label=Organization bearbeiten +organization.createform.title=Neue Organization anlegen +organization.editstep.header=Organization {0} bearbeiten