From 83a2a7aebf1fb3d1c7e94f7f7576f0d28df09597 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Mon, 3 Jun 2024 18:37:15 +0100 Subject: [PATCH] feat: Add Permission choice when creating Portlet Instance - MEED-6982 - Meeds-io/MIPs#139 (#100) --- .../layout/entity/PortletInstanceEntity.java | 3 - .../meeds/layout/model/PortletInstance.java | 2 - .../model/PortletInstanceDescriptor.java | 2 - .../PortletInstanceImportService.java | 1 - .../io/meeds/layout/util/EntityMapper.java | 4 +- .../layout-rdbms.db.changelog-1.0.0.xml | 16 ---- .../src/main/resources/portlet-instances.json | 96 +++++++++---------- .../service/PortletInstanceServiceTest.java | 3 +- .../locale/portlet/LayoutEditor_en.properties | 9 +- .../instances/drawer/InstanceDrawer.vue | 65 +++++++++++-- 10 files changed, 110 insertions(+), 91 deletions(-) diff --git a/layout-service/src/main/java/io/meeds/layout/entity/PortletInstanceEntity.java b/layout-service/src/main/java/io/meeds/layout/entity/PortletInstanceEntity.java index c6bc6cc2b..1de4f92cc 100644 --- a/layout-service/src/main/java/io/meeds/layout/entity/PortletInstanceEntity.java +++ b/layout-service/src/main/java/io/meeds/layout/entity/PortletInstanceEntity.java @@ -66,9 +66,6 @@ public class PortletInstanceEntity implements Serializable { @Column(name = "IS_SYSTEM") private boolean system; - @Column(name = "IS_SPACE_APPLICATION") - private boolean spaceApplication; - @Column(name = "IS_DISABLED") private boolean disabled; diff --git a/layout-service/src/main/java/io/meeds/layout/model/PortletInstance.java b/layout-service/src/main/java/io/meeds/layout/model/PortletInstance.java index c208d29ad..2994ebdce 100644 --- a/layout-service/src/main/java/io/meeds/layout/model/PortletInstance.java +++ b/layout-service/src/main/java/io/meeds/layout/model/PortletInstance.java @@ -51,6 +51,4 @@ public class PortletInstance { private boolean disabled; - private boolean spaceApplication; - } diff --git a/layout-service/src/main/java/io/meeds/layout/model/PortletInstanceDescriptor.java b/layout-service/src/main/java/io/meeds/layout/model/PortletInstanceDescriptor.java index 3ca26df36..e48d74b1f 100644 --- a/layout-service/src/main/java/io/meeds/layout/model/PortletInstanceDescriptor.java +++ b/layout-service/src/main/java/io/meeds/layout/model/PortletInstanceDescriptor.java @@ -46,8 +46,6 @@ public class PortletInstanceDescriptor { private boolean system; - private boolean spaceApplication; - private String illustrationPath; } diff --git a/layout-service/src/main/java/io/meeds/layout/service/injection/PortletInstanceImportService.java b/layout-service/src/main/java/io/meeds/layout/service/injection/PortletInstanceImportService.java index 77cf592dc..baac6f466 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/injection/PortletInstanceImportService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/injection/PortletInstanceImportService.java @@ -301,7 +301,6 @@ protected PortletInstance savePortletInstance(PortletInstanceDescriptor d, long portletInstance.setCategoryId(getCategorySettingValue(d.getCategoryNameId())); portletInstance.setPermissions(d.getPermissions()); portletInstance.setPreferences(d.getPreferences()); - portletInstance.setSpaceApplication(d.isSpaceApplication()); portletInstance.setSystem(d.isSystem()); if (isNew) { return portletInstanceService.createPortletInstance(portletInstance); diff --git a/layout-service/src/main/java/io/meeds/layout/util/EntityMapper.java b/layout-service/src/main/java/io/meeds/layout/util/EntityMapper.java index b7c4d1896..af9fa1077 100644 --- a/layout-service/src/main/java/io/meeds/layout/util/EntityMapper.java +++ b/layout-service/src/main/java/io/meeds/layout/util/EntityMapper.java @@ -64,8 +64,7 @@ public static PortletInstance fromEntity(PortletInstanceEntity entity, PortletDe entity.getPermissions().stream().filter(StringUtils::isNotBlank).toList(), portlet == null ? null : portlet.getSupportedModes(), entity.isSystem(), - entity.isDisabled(), - entity.isSpaceApplication()); + entity.isDisabled()); } public static PortletInstanceCategoryEntity toEntity(PortletInstanceCategory instance) { @@ -82,7 +81,6 @@ public static PortletInstanceEntity toEntity(PortletInstance instance) { instance.getPermissions(), getPreferencesString(instance), instance.isSystem(), - instance.isSpaceApplication(), instance.isDisabled(), Objects.hash(instance.getCategoryId(), getPreferencesString(instance), diff --git a/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml b/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml index d9a757690..fe849c890 100644 --- a/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml +++ b/layout-service/src/main/resources/changelog/layout-rdbms.db.changelog-1.0.0.xml @@ -503,22 +503,6 @@ - - - - - - - - - - - diff --git a/layout-service/src/main/resources/portlet-instances.json b/layout-service/src/main/resources/portlet-instances.json index a52d93252..6d84cc7c4 100644 --- a/layout-service/src/main/resources/portlet-instances.json +++ b/layout-service/src/main/resources/portlet-instances.json @@ -17,8 +17,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":true + "system":true }, { "nameId":"SpaceSettingPortlet", @@ -37,8 +36,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":true + "system":true }, { "nameId":"Image", @@ -57,8 +55,7 @@ "permissions":[ "Everyone" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"Links", @@ -77,8 +74,7 @@ "permissions":[ "Everyone" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"ExternalSpacesList", @@ -97,8 +93,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"GettingStarted", @@ -111,10 +106,10 @@ "en":"layout.portletInstance.GettingStarted.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"SpaceBannerPortlet", @@ -133,8 +128,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"WhoIsOnLinePortlet", @@ -153,8 +147,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"PeopleOverview", @@ -173,8 +166,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"SpaceActivityStreamPortlet", @@ -193,8 +185,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":true + "system":true }, { "nameId":"SpacesOverview", @@ -211,10 +202,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"SuggestionsPeopleAndSpace", @@ -231,10 +222,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"UserActivityStreamPortlet", @@ -251,10 +242,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"SpaceInfos", @@ -273,8 +264,7 @@ "permissions":[ "*:/platform/users" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"VerticalMenu", @@ -291,10 +281,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"VerticalMenu", @@ -311,10 +301,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"Breadcrumb", @@ -331,10 +321,10 @@ ], "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], - "system":true, - "spaceApplication":false + "system":true }, { "nameId":"GeneralSettings", @@ -347,7 +337,8 @@ "en":"layout.portletInstance.GeneralSettings.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -362,7 +353,8 @@ "en":"layout.portletInstance.UserSettingLanguage.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -377,7 +369,8 @@ "en":"layout.portletInstance.UserSettingNotifications.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -392,7 +385,8 @@ "en":"layout.portletInstance.UserSettingSecurity.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -407,7 +401,8 @@ "en":"layout.portletInstance.ProfileAboutMe.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -422,7 +417,8 @@ "en":"layout.portletInstance.ProfileContactInformation.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -437,7 +433,8 @@ "en":"layout.portletInstance.ProfileHeader.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true }, @@ -452,7 +449,8 @@ "en":"layout.portletInstance.ProfileWorkExperience.description" }, "permissions":[ - "*:/platform/users" + "*:/platform/administrators", + "*:/platform/web-contributors" ], "system":true } diff --git a/layout-service/src/test/java/io/meeds/layout/service/PortletInstanceServiceTest.java b/layout-service/src/test/java/io/meeds/layout/service/PortletInstanceServiceTest.java index 9c248d709..74f26dc37 100644 --- a/layout-service/src/test/java/io/meeds/layout/service/PortletInstanceServiceTest.java +++ b/layout-service/src/test/java/io/meeds/layout/service/PortletInstanceServiceTest.java @@ -515,8 +515,7 @@ private PortletInstance newPortletInstance() { Collections.singletonList("Everyone"), Collections.singletonList("edit"), true, - false, - true); + false); } } diff --git a/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties b/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties index a61c48f91..685b31d7d 100644 --- a/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties +++ b/layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties @@ -275,8 +275,6 @@ layout.category.placeholder=Select a category layout.portlet=Portlet layout.portlet.placeholder=Select a portlet -layout.portlet.allowUsingInSpaceContext=Allow space hosts use it for space apps - layout.portletInstance.add=Add layout.portletInstanceCategoryCreatedSuccessfully=Portlet Instance Category created successfully @@ -295,5 +293,10 @@ portlets.noPreviewAvailable=No preview available portlets.switchToEditMode=Edit mode portlets.switchToViewMode=View mode portlets.emptyPortletInstanceContent=Empty portlet instance +portlets.selectWhoCanAddIt=Select who can add it inside a page +portlets.administratorsMandatorySelectionTooltip=Admin has to access this app +portlets.administrators=Administrators +portlets.contentManagers=Content Managers +portlets.spaceHost=Space Host -layout.editPortletInstance=Edit portlet instance {0} +layout.editPortletInstance=Edit portlet instance {0} \ No newline at end of file diff --git a/layout-webapp/src/main/webapp/vue-app/portlets/components/instances/drawer/InstanceDrawer.vue b/layout-webapp/src/main/webapp/vue-app/portlets/components/instances/drawer/InstanceDrawer.vue index 79f8bbd95..fccb92a5c 100644 --- a/layout-webapp/src/main/webapp/vue-app/portlets/components/instances/drawer/InstanceDrawer.vue +++ b/layout-webapp/src/main/webapp/vue-app/portlets/components/instances/drawer/InstanceDrawer.vue @@ -86,12 +86,33 @@ v-model="contentId" :disabled="!isNew || disableSelectedPortlet" class="mt-4" /> -
- -
{{ $t('layout.portlet.allowUsingInSpaceContext') }}
+
+
{{ $t('portlets.selectWhoCanAddIt') }}
+ + + {{ $t('portlets.administratorsMandatorySelectionTooltip') }} + + +
p.includes('Everyone')) + || !!instance.permissions?.find?.(p => p.includes('/platform/users')); + this.aclContributors = this.aclSpaceHost || !!instance.permissions?.find?.(p => p.includes('/platform/web-contributors')); } else { this.categoryId = this.$root?.selectedCategoryId; + this.aclSpaceHost = true; + this.aclContributors = true; } this.contentId = instance?.contentId || contentId; - this.spaceApplication = instance?.spaceApplication || false; this.title = instance?.name || null; this.titleTranslations = {}; this.descriptionTranslations = {}; @@ -193,7 +231,7 @@ export default { this.$portletInstanceService.getPortletInstance(this.instanceId) .then(instance => { instance.categoryId = this.categoryId; - instance.spaceApplication = this.spaceApplication; + instance.permissions = this.getPermissions(); return this.$portletInstanceService.updatePortletInstance(instance) .then(() => { this.$root.$emit('portlet-instance-updated', instance); @@ -204,7 +242,7 @@ export default { : this.$portletInstanceService.createPortletInstance({ categoryId: this.categoryId, contentId: this.contentId, - spaceApplication: this.spaceApplication, + permissions: this.getPermissions(), }) .then(instance => { this.$root.$emit('portlet-instance-created', instance); @@ -228,6 +266,13 @@ export default { }) .finally(() => this.saving = false); }, + getPermissions() { + const permissions = [this.aclSpaceHost && '*:/platform/users' || '*:/platform/administrators']; + if (this.aclContributors) { + permissions.push('*:/platform/web-contributors'); + } + return permissions; + }, checkCKEdtiorDisplay() { if (this.$refs.portletInstanceDescriptionEditor?.editor && this.description !== this.$refs.portletInstanceDescriptionEditor.inputVal) {