diff --git a/perun-base/src/test/resources/perun-apps-config.yml b/perun-base/src/test/resources/perun-apps-config.yml index 3a6219aa21..83c7d7a1ec 100644 --- a/perun-base/src/test/resources/perun-apps-config.yml +++ b/perun-base/src/test/resources/perun-apps-config.yml @@ -10,14 +10,16 @@ brands: pwd_reset: "pwd-reset" publications: "publications" old_gui_domain: "perun-dev" + old_gui_alert: New GUI is here - name: other new_apps: - api: "" - admin: "" - consolidator: "" - linker: "" - profile: "" - pwd_reset: "" - publications: "" - old_gui_domain: "" + api: "other-api" + admin: "other-admin" + consolidator: "other-consolidator" + linker: "other-linker" + profile: "other-profile" + pwd_reset: "other-pwd-reset" + publications: "other-publication" + old_gui_domain: "other-old_gui_domain" + vos: ["test_vo", "other_vo"] ... \ No newline at end of file diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/PerunAppsConfig.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/PerunAppsConfig.java index 5ee743e94f..949238f0ad 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/PerunAppsConfig.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/PerunAppsConfig.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; +import java.util.ArrayList; import java.util.List; /** @@ -52,16 +53,32 @@ public static Brand getBrandContainingDomain(String domain) { return null; } + /** + * Iterates brands and searches for such that contains vo's shortname. + * If none found, returns default branding. + */ + public static Brand getBrandContainingVo(String voShortname) { + Brand defaultBrand = instance.getBrands() + .stream() + .filter(brand -> brand.getName().equals("default")) + .findFirst() + .orElse(null); + return instance.getBrands().stream() + .filter(brand -> brand.getVoShortnames().contains(voShortname)) + .findFirst() + .orElse(defaultBrand); + } + /** * Class holding data for a single branding. */ public static class Brand { private String name; - private String oldGuiDomain; - private NewApps newApps; + private List voShortnames = new ArrayList<>(); + private String oldGuiAlert; @JsonGetter("name") public String getName() { @@ -83,6 +100,26 @@ public void setNewApps(NewApps newApps) { this.newApps = newApps; } + @JsonGetter("voShortnames") + public List getVoShortnames() { + return voShortnames; + } + + @JsonSetter("vos") + public void setVoShortnames(List voShortnames) { + this.voShortnames = voShortnames; + } + + @JsonGetter("oldGuiAlert") + public String getOldGuiAlert() { + return oldGuiAlert; + } + + @JsonSetter("old_gui_alert") + public void setOldGuiAlert(String oldGuiAlert) { + this.oldGuiAlert = oldGuiAlert; + } + @JsonGetter("oldGuiDomain") public String getOldGuiDomain() { return oldGuiDomain; @@ -98,7 +135,9 @@ public String toString() { return "Brand{" + "name='" + name + '\'' + ", oldGuiDomain='" + oldGuiDomain + '\'' + + ", oldGuiAlert='" + oldGuiAlert + '\'' + ", newApps=" + newApps + + ", vos=" + voShortnames + '}'; } } diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/Utils.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/Utils.java index 46d6c632fb..59f4333542 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/Utils.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/Utils.java @@ -1161,8 +1161,11 @@ public static void sendPasswordResetEmail(User user, String email, String namesp } } else { // if no brand contains specified domain, set default old gui domain - brand = getInstance().getBrands().get(0); - url = brand.getOldGuiDomain(); + PerunAppsConfig.Brand defaultBrand = getInstance().getBrands().stream() + .filter(b -> b.getName().equals("default")) + .findFirst() + .orElseThrow(() -> new InternalErrorException("Default GUI branding configuration is missing")); + url = defaultBrand.getOldGuiDomain(); } } catch (MalformedURLException ex) { throw new InternalErrorException("Not valid URL of running Perun instance.", ex); diff --git a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/PerunAppsConfigLoaderTest.java b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/PerunAppsConfigLoaderTest.java index 7de1a10bca..f880b93c75 100644 --- a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/PerunAppsConfigLoaderTest.java +++ b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/PerunAppsConfigLoaderTest.java @@ -4,6 +4,8 @@ import org.junit.Before; import org.junit.Test; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -18,6 +20,7 @@ public void setUp() { expectedDefaultBrand = new PerunAppsConfig.Brand(); expectedDefaultBrand.setOldGuiDomain("perun-dev"); expectedDefaultBrand.setName("default"); + expectedDefaultBrand.setOldGuiAlert("New GUI is here"); var newApps = new PerunAppsConfig.NewApps(); newApps.setApi("api"); @@ -42,5 +45,20 @@ public void init() { assertThat(config.getBrands().get(0)) .usingRecursiveComparison() .isEqualTo(expectedDefaultBrand); + assertThat(config.getBrands().get(1).getOldGuiAlert()) + .isNull(); + } + + @Test + public void vos() { + PerunAppsConfig config = PerunAppsConfig.getInstance(); + + assertThat(config) + .isNotNull(); + assertThat(config.getBrands()) + .hasSize(2); + assertThat(config.getBrands().get(1).getVoShortnames()) + .containsAll(List.of("test_vo", "other_vo")); + assertThat(config.getBrands().get(0).getVoShortnames()).isNullOrEmpty(); } } diff --git a/perun-openapi/openapi.yml b/perun-openapi/openapi.yml index 70b92d21c0..d40c59f2f5 100644 --- a/perun-openapi/openapi.yml +++ b/perun-openapi/openapi.yml @@ -1431,6 +1431,8 @@ components: name: { type: string } oldGuiDomain: { type: string } newApps: { $ref: '#/components/schemas/NewApps' } + vos: { type: array, items: { type: string } } + oldGuiAlert: { type: string } PerunAppsConfig: type: object @@ -3537,6 +3539,19 @@ paths: default: $ref: '#/components/responses/ExceptionResponse' + /json/utils/getNewGuiAlert: + get: + tags: + - Utils + operationId: getNewGuiAlert + summary: Gets new GUI alert (banner html content) for the brand of incoming request. + description: Returns new GUI alert + responses: + '200': + $ref: '#/components/responses/StringResponse' + default: + $ref: '#/components/responses/ExceptionResponse' + ################################################# # # # AuthzResolver # diff --git a/perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/MailManagerImpl.java b/perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/MailManagerImpl.java index 755ec8c4d7..7568be03c4 100644 --- a/perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/MailManagerImpl.java +++ b/perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/MailManagerImpl.java @@ -35,6 +35,7 @@ import cz.metacentrum.perun.core.bl.MembersManagerBl; import cz.metacentrum.perun.core.bl.UsersManagerBl; import cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl; +import cz.metacentrum.perun.core.impl.PerunAppsConfig; import cz.metacentrum.perun.registrar.exceptions.ApplicationMailAlreadyRemovedException; import cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException; import cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException; @@ -1525,8 +1526,8 @@ private String substituteCommonStrings(Application app, List entitiesHistoryList = new ArrayList(); private BasicOverlayType configuration; + private String newGuiAlert; // RPC URL private String rpcUrl = ""; @@ -886,4 +887,12 @@ public BasicOverlayType getConfiguration() { public void setConfiguration(BasicOverlayType configuration) { this.configuration = configuration; } + + public String getNewGuiAlert() { + return newGuiAlert; + } + + public void setNewGuiAlert(String newGuiAlert) { + this.newGuiAlert = newGuiAlert; + } } diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/client/WebGui.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/client/WebGui.java index db6e85e34e..35b75320ee 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/client/WebGui.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/client/WebGui.java @@ -20,6 +20,7 @@ import cz.metacentrum.perun.webgui.client.resources.LargeIcons; import cz.metacentrum.perun.webgui.client.resources.SmallIcons; import cz.metacentrum.perun.webgui.json.GetGuiConfiguration; +import cz.metacentrum.perun.webgui.json.GetNewGuiAlert; import cz.metacentrum.perun.webgui.json.JsonCallbackEvents; import cz.metacentrum.perun.webgui.json.JsonUtils; import cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes; @@ -44,10 +45,14 @@ import cz.metacentrum.perun.webgui.widgets.CantLogAsServiceUserWidget; import cz.metacentrum.perun.webgui.widgets.Confirm; import cz.metacentrum.perun.webgui.widgets.NotUserOfPerunWidget; +import org.eclipse.jetty.util.ajax.JSON; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; /** * The main web GUI class. It's GWT Entry point. @@ -168,17 +173,27 @@ public void onFinished(JavaScriptObject jso) { final PerunPrincipal pp = (PerunPrincipal)jso; session.setPerunPrincipal(pp); - GetGuiConfiguration getConfig = new GetGuiConfiguration(new JsonCallbackEvents(){ + GetNewGuiAlert getNewGuiAlert = new GetNewGuiAlert(new JsonCallbackEvents() { @Override public void onFinished(JavaScriptObject jso) { + BasicOverlayType basic = (jso == null) ? null : jso.cast(); + String alert = (basic == null) ? null : basic.getString(); + session.setNewGuiAlert(alert); - session.setConfiguration((BasicOverlayType)jso.cast()); - - String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert"); + String newGuiAlertContent = session.getNewGuiAlert(); if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) { - DOM.getElementById("perun-new-gui-alert").setInnerHTML(newGuiAlertContent); + DOM.getElementById("perun-new-gui-alert").setInnerHTML(session.getNewGuiAlert()); DOM.getElementById("perun-new-gui-alert").setClassName("newGuiAlertActive"); } + } + }); + getNewGuiAlert.retrieveData(); + + GetGuiConfiguration getConfig = new GetGuiConfiguration(new JsonCallbackEvents(){ + @Override + public void onFinished(JavaScriptObject jso) { + + session.setConfiguration((BasicOverlayType)jso.cast()); // check if user exists if (session.getUser() == null && !pp.getRoles().hasAnyRole()) { diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/json/GetNewGuiAlert.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/json/GetNewGuiAlert.java new file mode 100644 index 0000000000..52968ab19c --- /dev/null +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/json/GetNewGuiAlert.java @@ -0,0 +1,58 @@ +package cz.metacentrum.perun.webgui.json; + +import com.google.gwt.core.client.JavaScriptObject; +import cz.metacentrum.perun.webgui.client.PerunWebSession; +import cz.metacentrum.perun.webgui.model.PerunError; + +/** + * Class to get new GUI alert + */ +public class GetNewGuiAlert implements JsonCallback { + + // SESSION + private PerunWebSession session = PerunWebSession.getInstance(); + + // PARAMS + private JsonCallbackEvents events = new JsonCallbackEvents(); + + // URLs + static private final String URL = "utils/getNewGuiAlert"; + + /** + * New callback instance + */ + public GetNewGuiAlert() {} + + /** + * New callback instance + */ + public GetNewGuiAlert(JsonCallbackEvents events) { + this.events = events; + } + + @Override + public void retrieveData() { + + JsonClient js = new JsonClient(); + js.retrieveData(URL, this); + + } + + @Override + public void onFinished(JavaScriptObject jso) { + session.getUiElements().setLogText("Loading new GUI alert finished."); + events.onFinished(jso); + } + + @Override + public void onError(PerunError error) { + session.getUiElements().setLogErrorText("Error while loading new GUI alert."); + events.onError(error); + } + + @Override + public void onLoadingStart() { + events.onLoadingStart(); + } + +} diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/AttributeDefinitionDetailTabItem.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/AttributeDefinitionDetailTabItem.java index ce591b68db..398595df0d 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/AttributeDefinitionDetailTabItem.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/AttributeDefinitionDetailTabItem.java @@ -223,9 +223,11 @@ public void onClick(ClickEvent event) { for (int i=0; iSetting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

" + newGuiAlertContent); + String alertText = "

Setting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

"; + if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) alertText += newGuiAlertContent; + alert.setHTML(0,0, alertText); TabMenu menu = new TabMenu(); menu.addWidget(UiElements.getRefreshButton(this)); diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/CreateAttributeDefinitionTabItem.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/CreateAttributeDefinitionTabItem.java index 4f5255f494..57a373be25 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/CreateAttributeDefinitionTabItem.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/attributestabs/CreateAttributeDefinitionTabItem.java @@ -221,9 +221,11 @@ public void onClick(ClickEvent clickEvent) { } })); - String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert"); + String newGuiAlertContent = session.getNewGuiAlert(); final FlexTable alert = new FlexTable(); - alert.setHTML(0,0,"

Setting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

"+ newGuiAlertContent); + String alertText = "

Setting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

"; + if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) alertText += newGuiAlertContent; + alert.setHTML(0,0,alertText); vp.add(layout); vp.add(alert); diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/entitylessattributestabs/EntitylessAttributesDetailTabItem.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/entitylessattributestabs/EntitylessAttributesDetailTabItem.java index 55361b1d53..df4697d20c 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/entitylessattributestabs/EntitylessAttributesDetailTabItem.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/entitylessattributestabs/EntitylessAttributesDetailTabItem.java @@ -202,9 +202,11 @@ public void onLoadingStart() { showKeys.addClickHandler(clickEvent -> session.getTabManager().addTab(new EntitylessAttributeEditKeyTabItem(def))); menu.addWidget(showKeys); - String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert"); + String newGuiAlertContent = session.getNewGuiAlert(); final FlexTable alert = new FlexTable(); - alert.setHTML(0,0,"

Setting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

" + newGuiAlertContent); + String alertText = "

Setting attribute rights is no longer supported in this GUI. In order to set attribute rights please use the New GUI.

"; + if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) alertText += newGuiAlertContent; + alert.setHTML(0,0,alertText); // create new instance for jsonCall final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId()); diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/CreateMailTabItem.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/CreateMailTabItem.java index dd671b63db..d9be0f64c4 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/CreateMailTabItem.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/CreateMailTabItem.java @@ -371,6 +371,7 @@ private Widget availableTagsTab() { "

{appDetailUrl-krb} - link for Kerberos authentication" + "
{appDetailUrl-fed} - link for Shibboleth IdP (federation) authentication" + "
{appDetailUrl-cert} - link for personal certificate authentication" + + "
{appDetailUrl-newGUI} - link for new admin GUI" + "

Perun GUI links for administrators:" + @@ -382,6 +383,7 @@ private Widget availableTagsTab() { "

{perunGuiUrl-krb} - link for Kerberos authentication" + "
{perunGuiUrl-fed} - link for Shibboleth IdP (federation) authentication" + "
{perunGuiUrl-cert} - link for personal certificate authentication" + + "
{perunGuiUrl-newGUI} - link for new admin GUI" + "

User invitations:" + diff --git a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/EditMailTabItem.java b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/EditMailTabItem.java index 1269179591..268944ce10 100644 --- a/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/EditMailTabItem.java +++ b/perun-web-gui/src/main/java/cz/metacentrum/perun/webgui/tabs/registrartabs/EditMailTabItem.java @@ -306,6 +306,7 @@ private Widget availableTagsTab() { "

{appDetailUrl-krb} - link for Kerberos authentication" + "
{appDetailUrl-fed} - link for Shibboleth IdP (federation) authentication" + "
{appDetailUrl-cert} - link for personal certificate authentication" + + "
{appDetailUrl-newGUI} - link for new admin GUI" + "

Perun GUI links for administrators:" + @@ -317,6 +318,7 @@ private Widget availableTagsTab() { "

{perunGuiUrl-krb} - link for Kerberos authentication" + "
{perunGuiUrl-fed} - link for Shibboleth IdP (federation) authentication" + "
{perunGuiUrl-cert} - link for personal certificate authentication" + + "
{perunGuiUrl-newGUI} - link for new admin GUI" + "

User invitations:" +