[Admin Tools | log4j2]: Allow curators with profile to be invisible in the Gateway | Dynamically align custom menu.

1. Curator.java & CuratorResponse.java: Added field private boolean visible = true; to allow curators have a profile but not be visible in the Gateway.
2. CuratorService.java: In method "getCurators()" called by /{pid}/curator, return curators that have a profile and the profile is visible.
3. MenuAlignment.java: Enum created for menu alignment options.
4. Menu.java & MenuFull.java: Added field public MenuAlignment featuredAlignment = MenuAlignment.CENTER; to allow dynamic alignment of the Gateway custom menu.
5. MenuController.java: Added api method "alignMenu()" (/community/{pid}/menu/align), to change alignment of the custom menu.
6. MenuService.java: Added method "alignMenu()" | Set featuredAlignment field (default to "CENTER").
This commit is contained in:
Konstantina Galouni 2022-12-09 15:01:00 +02:00
parent 22d010c096
commit 4f62befa74
8 changed files with 79 additions and 9 deletions

View File

@ -1,9 +1,6 @@
package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import eu.dnetlib.uoaadmintools.entities.menu.MenuFull;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
import eu.dnetlib.uoaadmintools.entities.menu.*;
import eu.dnetlib.uoaadmintools.services.MenuService;
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
@ -209,4 +206,13 @@ public class MenuController {
public Menu toggleMenu(@PathVariable(value = "pid") String pid, @RequestParam String status, @RequestParam(value="featured", required=false) String isFeatured) throws Exception {
return menuService.toggleMenu(pid, status, isFeatured);
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator('community')," +
"@AuthorizationService.manager('community', #pid))")
@RequestMapping(value = {"/community/{pid}/menu/align"}, method = RequestMethod.POST)
public Menu alignMenu(@PathVariable(value = "pid") String pid, @RequestParam String alignment) throws Exception {
return menuService.alignMenu(pid, alignment);
}
}

View File

@ -16,6 +16,7 @@ public class Curator {
private List<Affiliation> affiliations;
private String photo;
private String bio;
private boolean visible = true;
public Curator() {}
@ -66,4 +67,12 @@ public class Curator {
public void setBio(String bio) {
this.bio = bio;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
}

View File

@ -10,6 +10,7 @@ public class CuratorResponse {
private List<Affiliation> affiliations;
private String photo;
private String bio;
private boolean visible = true;
public CuratorResponse() {
}
@ -52,4 +53,12 @@ public class CuratorResponse {
public void setBio(String bio) {
this.bio = bio;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
}

View File

@ -14,6 +14,7 @@ public class Menu {
public boolean isMenuEnabled;
public List<String> featuredMenuItems;
public List<String> menuItems;
public MenuAlignment featuredAlignment = MenuAlignment.CENTER;
public Menu(String portalPid) {
this.setPortalPid(portalPid);
@ -21,6 +22,7 @@ public class Menu {
this.setFeaturedMenuEnabled(true);
this.setMenuItems(new ArrayList<>());
this.setFeaturedMenuItems(new ArrayList<>());
this.setFeaturedAlignment(MenuAlignment.CENTER.name());
}
public String getPortalPid() {
@ -62,4 +64,20 @@ public class Menu {
public void setMenuItems(List<String> menuItems) {
this.menuItems = menuItems;
}
public String getFeaturedAlignment() {
if(featuredAlignment == null) {
return null;
}
return featuredAlignment.name();
}
public void setFeaturedAlignment(String featuredAlignment) {
if(featuredAlignment == null) {
this.featuredAlignment = null;
} else {
MenuAlignment alignment = MenuAlignment.valueOf(featuredAlignment);
this.featuredAlignment = alignment;
}
}
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.uoaadmintools.entities.menu;
public enum MenuAlignment {
LEFT, CENTER, RIGHT
}

View File

@ -8,6 +8,7 @@ public class MenuFull {
public boolean isMenuEnabled;
public List<MenuItemFull> featuredMenuItems;
public List<MenuItemFull> menuItems;
public MenuAlignment featuredAlignment = MenuAlignment.CENTER;
public String getPortalPid() {
return portalPid;
@ -48,4 +49,20 @@ public class MenuFull {
public void setMenuItems(List<MenuItemFull> menuItems) {
this.menuItems = menuItems;
}
public String getFeaturedAlignment() {
if(featuredAlignment == null) {
return null;
}
return featuredAlignment.name();
}
public void setFeaturedAlignment(String featuredAlignment) {
if(featuredAlignment == null) {
this.featuredAlignment = null;
} else {
MenuAlignment alignment = MenuAlignment.valueOf(featuredAlignment);
this.featuredAlignment = alignment;
}
}
}

View File

@ -29,7 +29,7 @@ public class CuratorService {
List<CuratorResponse> curators = new ArrayList<>();
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
Curator curator = curatorDAO.findById(parseId(manager.getId()));
if (curator != null) {
if (curator != null && curator.isVisible()) {
curators.add(new CuratorResponse(curator));
}
}

View File

@ -2,10 +2,7 @@ package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import eu.dnetlib.uoaadmintools.entities.menu.MenuFull;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
import eu.dnetlib.uoaadmintools.entities.menu.*;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import org.apache.logging.log4j.LogManager;
@ -86,6 +83,7 @@ public class MenuService {
if(menu == null) {
menuFull.setFeaturedMenuEnabled(true);
menuFull.setMenuEnabled(true);
menuFull.setFeaturedAlignment(MenuAlignment.CENTER.name());
} else {
for (String menuItemId : menu.getFeaturedMenuItems()) {
featuredMenuItems.add(getFullRootMenuItemById(menuItemId, portalPid, true));
@ -97,6 +95,7 @@ public class MenuService {
menuFull.setFeaturedMenuEnabled(menu.getIsFeaturedMenuEnabled());
menuFull.setMenuEnabled(menu.getIsMenuEnabled());
menuFull.setFeaturedAlignment(menu.getFeaturedAlignment());
}
menuFull.setPortalPid(portalPid);
@ -366,4 +365,11 @@ public class MenuService {
}
return menuDAO.save(menu);
}
public Menu alignMenu(String pid, String alignment) {
Menu menu = menuDAO.findByPortalPid(pid);
menu.setFeaturedAlignment(alignment);
return menuDAO.save(menu);
}
}