From 4343353c819e3a596178857c6b8be4d3eef6cead Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Thu, 16 Jan 2025 06:53:22 +0100 Subject: [PATCH] feat: Improve Site Template Attributes Mapping - MEED-8094 - Meeds-io/MIPs#173 --- .../io/meeds/layout/service/SiteLayoutService.java | 1 + .../io/meeds/layout/service/SiteTemplateService.java | 6 ++---- .../main/java/io/meeds/layout/util/EntityMapper.java | 10 +++------- .../meeds/layout/service/SiteTemplateServiceTest.java | 8 +++----- .../site-management/components/SiteManagement.vue | 2 +- .../site-management/components/form/SiteTemplate.vue | 2 +- .../vue-app/site-management/components/main/Item.vue | 4 ++-- .../vue-app/site-template/components/main/Item.vue | 4 ++-- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/layout-service/src/main/java/io/meeds/layout/service/SiteLayoutService.java b/layout-service/src/main/java/io/meeds/layout/service/SiteLayoutService.java index 331ac469..c3a0381a 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/SiteLayoutService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/SiteLayoutService.java @@ -123,6 +123,7 @@ public PortalConfig createSite(SiteCreateModel createModel, String username) thr createdPortalConfig.setDisplayOrder(portalConfig.isDisplayed() ? portalConfig.getDisplayOrder() : 0); createdPortalConfig.setAccessPermissions(accessPermissions); createdPortalConfig.setEditPermission(editPermission); + createdPortalConfig.setRemovable(true); if (StringUtils.isNotBlank(portalConfig.getBannerUploadId())) { createdPortalConfig.setBannerUploadId(portalConfig.getBannerUploadId()); } diff --git a/layout-service/src/main/java/io/meeds/layout/service/SiteTemplateService.java b/layout-service/src/main/java/io/meeds/layout/service/SiteTemplateService.java index ee77c713..7ff48031 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/SiteTemplateService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/SiteTemplateService.java @@ -20,8 +20,6 @@ package io.meeds.layout.service; import static io.meeds.layout.util.EntityMapper.SITE_ENABLED_PROP; -import static io.meeds.layout.util.EntityMapper.SITE_TEMPLATE_ICON_PROP; -import static io.meeds.layout.util.EntityMapper.SITE_TEMPLATE_SYSTEM_PROP; import static io.meeds.layout.util.EntityMapper.toSiteTemplate; import java.util.List; @@ -196,10 +194,10 @@ private SiteTemplate updateSiteTemplate(SiteTemplate siteTemplate, String userna private SiteTemplate updateSiteTemplate(SiteTemplate siteTemplate, PortalConfig portalConfig) { portalConfig.setLabel(siteTemplate.getName()); portalConfig.setDescription(siteTemplate.getDescription()); + portalConfig.setRemovable(!siteTemplate.isSystem()); + portalConfig.setIcon(siteTemplate.getIcon()); portalConfig.setAccessPermissions(new String[] { UserACL.EVERYONE }); portalConfig.setEditPermission(getAdministratorsPermission()); - portalConfig.setProperty(SITE_TEMPLATE_ICON_PROP, siteTemplate.getIcon()); - portalConfig.setProperty(SITE_TEMPLATE_SYSTEM_PROP, String.valueOf(siteTemplate.isSystem())); portalConfig.setProperty(SITE_ENABLED_PROP, String.valueOf(!siteTemplate.isDisabled())); layoutService.save(portalConfig); return toSiteTemplateDetails(portalConfig, null); 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 2ac3e498..354ccbca 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 @@ -43,11 +43,7 @@ public class EntityMapper { - public static final String SITE_ENABLED_PROP = "SITE_ENABLED"; - - public static final String SITE_TEMPLATE_SYSTEM_PROP = "SITE_TEMPLATE_SYSTEM"; - - public static final String SITE_TEMPLATE_ICON_PROP = "SITE_TEMPLATE_ICON"; + public static final String SITE_ENABLED_PROP = "SITE_ENABLED"; private EntityMapper() { // Utils Class @@ -121,8 +117,8 @@ public static SiteTemplate toSiteTemplate(PortalConfig portalConfig) { SiteTemplate siteTemplate = new SiteTemplate(); siteTemplate.setId(portalConfig.getId()); siteTemplate.setLayout(portalConfig.getName()); - siteTemplate.setIcon(portalConfig.getProperty(SITE_TEMPLATE_ICON_PROP)); - siteTemplate.setSystem(StringUtils.equals(portalConfig.getProperty(SITE_TEMPLATE_SYSTEM_PROP), "true")); + siteTemplate.setIcon(portalConfig.getIcon()); + siteTemplate.setSystem(!portalConfig.isRemovable()); siteTemplate.setDisabled(StringUtils.equals(portalConfig.getProperty(SITE_ENABLED_PROP), "false")); return siteTemplate; } diff --git a/layout-service/src/test/java/io/meeds/layout/service/SiteTemplateServiceTest.java b/layout-service/src/test/java/io/meeds/layout/service/SiteTemplateServiceTest.java index a7a0bb94..4ebc9097 100644 --- a/layout-service/src/test/java/io/meeds/layout/service/SiteTemplateServiceTest.java +++ b/layout-service/src/test/java/io/meeds/layout/service/SiteTemplateServiceTest.java @@ -19,8 +19,6 @@ package io.meeds.layout.service; import static io.meeds.layout.util.EntityMapper.SITE_ENABLED_PROP; -import static io.meeds.layout.util.EntityMapper.SITE_TEMPLATE_ICON_PROP; -import static io.meeds.layout.util.EntityMapper.SITE_TEMPLATE_SYSTEM_PROP; import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -119,8 +117,8 @@ void setUp() { lenient().when(portalConfig.getId()).thenReturn(ID); lenient().when(portalConfig.getName()).thenReturn("layout"); lenient().when(portalConfig.getType()).thenReturn(PortalConfig.PORTAL_TEMPLATE); - lenient().when(portalConfig.getProperty(SITE_TEMPLATE_ICON_PROP)).thenReturn(siteTemplate.getIcon()); - lenient().when(portalConfig.getProperty(SITE_TEMPLATE_SYSTEM_PROP)).thenReturn(String.valueOf(siteTemplate.isSystem())); + lenient().when(portalConfig.getIcon()).thenReturn(siteTemplate.getIcon()); + lenient().when(portalConfig.isRemovable()).thenReturn(!siteTemplate.isSystem()); lenient().when(portalConfig.getProperty(SITE_ENABLED_PROP)).thenReturn(String.valueOf(!siteTemplate.isDisabled())); } @@ -242,7 +240,7 @@ void testDeleteSiteTemplate() { void testDeleteSiteTemplateWhenSystem() { when(aclService.isAdministrator(testuser)).thenReturn(true); when(layoutService.getPortalConfig(ID)).thenReturn(portalConfig); - when(portalConfig.getProperty(SITE_TEMPLATE_SYSTEM_PROP)).thenReturn("true"); + when(portalConfig.isRemovable()).thenReturn(false); assertThrows(IllegalAccessException.class, () -> siteTemplateService.deleteSiteTemplate(ID, testuser)); } diff --git a/layout-webapp/src/main/webapp/vue-app/site-management/components/SiteManagement.vue b/layout-webapp/src/main/webapp/vue-app/site-management/components/SiteManagement.vue index 8acce268..7fdcf5e5 100644 --- a/layout-webapp/src/main/webapp/vue-app/site-management/components/SiteManagement.vue +++ b/layout-webapp/src/main/webapp/vue-app/site-management/components/SiteManagement.vue @@ -84,7 +84,7 @@ export default { deleteSite() { this.loading++; return this.$siteLayoutService.deleteSite(this.siteToDelete.siteType, this.siteToDelete.name) - .then(() => this.refreshSites) + .then(() => this.refreshSites()) .finally(() => this.loading--); }, } diff --git a/layout-webapp/src/main/webapp/vue-app/site-management/components/form/SiteTemplate.vue b/layout-webapp/src/main/webapp/vue-app/site-management/components/form/SiteTemplate.vue index b58a4a5f..3d2c8113 100644 --- a/layout-webapp/src/main/webapp/vue-app/site-management/components/form/SiteTemplate.vue +++ b/layout-webapp/src/main/webapp/vue-app/site-management/components/form/SiteTemplate.vue @@ -36,7 +36,7 @@ flat @click="$root.$emit('layout-illustration-preview', illustrationSrc, illustrationAction, title, description)">
- {{ siteTemplate.icon }} + {{ siteTemplate.icon || 'fa-globe' }}

-

+
{{ site.icon || 'fa-globe' }} diff --git a/layout-webapp/src/main/webapp/vue-app/site-template/components/main/Item.vue b/layout-webapp/src/main/webapp/vue-app/site-template/components/main/Item.vue index f41c49cc..449c590f 100644 --- a/layout-webapp/src/main/webapp/vue-app/site-template/components/main/Item.vue +++ b/layout-webapp/src/main/webapp/vue-app/site-template/components/main/Item.vue @@ -24,11 +24,11 @@ -
+
{{ siteTemplate.icon || 'fa-globe' }}