Skip to content

Commit

Permalink
feat: Improve Site Template Attributes Mapping - MEED-8094 - Meeds-io…
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored and exo-swf committed Jan 17, 2025
1 parent 5895353 commit 4343353
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--);
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
flat
@click="$root.$emit('layout-illustration-preview', illustrationSrc, illustrationAction, title, description)">
<div class="d-flex flex-column flex-grow-1 align-center justify-center">
<v-icon size="32" class="py-4">{{ siteTemplate.icon }}</v-icon>
<v-icon size="32" class="py-4">{{ siteTemplate.icon || 'fa-globe' }}</v-icon>
<p
v-if="title"
v-sanitized-html="title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<!-- Illustration -->
<!-- name -->
<td colspan="2" align="left" class="pe-0">
<div class="d-flex">
<div class="d-flex align-center text-start">
<v-card
color="transparent"
min-width="35"
class="me-4"
class="me-4 d-flex align-center"
flat>
<v-icon size="28">{{ site.icon || 'fa-globe' }}</v-icon>
</v-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<!-- Illustration -->
<!-- name -->
<td colspan="2" align="left" class="pe-0">
<div class="d-flex">
<div class="d-flex align-center text-start">
<v-card
color="transparent"
min-width="35"
class="me-4"
class="me-4 d-flex align-center"
flat>
<v-icon size="28">{{ siteTemplate.icon || 'fa-globe' }}</v-icon>
</v-card>
Expand Down

0 comments on commit 4343353

Please sign in to comment.