From 4461dcf01e77ac0bfd32de2b833783ba94969949 Mon Sep 17 00:00:00 2001 From: Rastislav Krutak <492918@mail.muni.cz> Date: Thu, 1 Aug 2024 14:24:14 +0200 Subject: [PATCH] feat: disable groups user is already member of on embedded --- .../resources/PerunRegistrarTranslation.java | 3 +++ .../registrar/widgets/items/GroupCheckBox.java | 17 +++++++++++++---- .../PerunRegistrarTranslation_cs.properties | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation.java b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation.java index b4248139..daf5aefa 100644 --- a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation.java +++ b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation.java @@ -261,6 +261,9 @@ public interface PerunRegistrarTranslation extends PerunTranslation { @DefaultMessage("Enter value") String enterValue(); + @DefaultMessage("You are already a member of this group") + String alreadyMemberOfThisGroup(); + // -------------- SUBMITTED APPS PAGE ------------------------ // @DefaultMessage("Open applications") diff --git a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/GroupCheckBox.java b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/GroupCheckBox.java index 9aff37d7..e1586fda 100644 --- a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/GroupCheckBox.java +++ b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/GroupCheckBox.java @@ -9,11 +9,10 @@ /** * Represents checkboxes for Group selection. - * Value is a list of group names and ids, separated by "#". Groups are separated by pipe '|'. - * It does not contain unchecked values. - * + * Value is a list of group names and ids along with optional ENABLED/DISABLED flag, separated by "#". + * Groups are separated by pipe '|'. It does not contain unchecked values. * Example of a value: - * "Group A#124|Group B#1212|Group C#1212" + * "Group A#124#ENABLED|Group B#1212#DISABLED|Group C#1212#ENABLED" * * @author Vojtech Sassmann */ @@ -34,6 +33,16 @@ protected Widget initWidget() { for (Widget widget : getWidget()) { if (widget instanceof CheckBox) { CheckBox checkBox = (CheckBox) widget; + // option appended with 'DISABLED' means that the user is already a member of that group + if (checkBox.getText().split("#").length > 1) { + String disabledFlag = checkBox.getText().split("#")[1]; + checkBox.setText(checkBox.getText().split("#")[0]); + if (disabledFlag.equals("DISABLED")) { + checkBox.setEnabled(false); + checkBox.setTitle(translation.alreadyMemberOfThisGroup()); + } + } + String[] parsedGroupName = checkBox.getText().split(Window.Location.getParameter("group") + ":"); // use group name without parent group prefix only if there is one if (parsedGroupName[1] != null) { diff --git a/perun-wui-registrar/src/main/resources/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation_cs.properties b/perun-wui-registrar/src/main/resources/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation_cs.properties index 5da57c58..8a239a4a 100644 --- a/perun-wui-registrar/src/main/resources/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation_cs.properties +++ b/perun-wui-registrar/src/main/resources/cz/metacentrum/perun/wui/registrar/client/resources/PerunRegistrarTranslation_cs.properties @@ -96,6 +96,7 @@ addNewValue=Přidat hodnotu removeValue=Odstranit hodnotu enterKey=Zadejte nový klíč enterValue=Zadejte hodnotu +alreadyMemberOfThisGroup=Jste již členem této skupiny # // -------------- SUBMITTED APPS PAGE ------------------------ //