add: management of groups by user
authorINOPIAE <m.maengel@inopiae.de>
Fri, 19 Aug 2016 11:19:17 +0000 (13:19 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 21 Aug 2016 17:40:31 +0000 (19:40 +0200)
Change-Id: Ie64d48e7bafdde77338b2fc816a328dde8764164

src/org/cacert/gigi/pages/account/MyDetailsForm.java
src/org/cacert/gigi/pages/account/MyDetailsRoles.templ

index d6b65e0..8139022 100644 (file)
@@ -15,6 +15,7 @@ import org.cacert.gigi.output.ArrayIterable;
 import org.cacert.gigi.output.CountrySelector;
 import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.output.GroupIterator;
+import org.cacert.gigi.output.GroupSelector;
 import org.cacert.gigi.output.NameInput;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.Template;
@@ -38,6 +39,8 @@ public class MyDetailsForm extends Form {
 
     private CountrySelector cs;
 
+    private GroupSelector selectedGroup = new GroupSelector("groupToModify", false);
+
     public MyDetailsForm(HttpServletRequest hsr, User target) {
         super(hsr);
         this.target = target;
@@ -100,6 +103,18 @@ public class MyDetailsForm extends Form {
                 cs.update(req);
                 target.setResidenceCountry(cs.getCountry());
             }
+
+            if ("addGroup".equals(action) || "removeGroup".equals(action)) {
+                selectedGroup.update(req);
+                Group toMod = selectedGroup.getGroup();
+                if ("addGroup".equals(action)) {
+                    target.grantGroup(target, toMod);
+                } else {
+                    target.revokeGroup(target, toMod);
+                }
+                return true;
+            }
+
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
             return false;
@@ -136,13 +151,8 @@ public class MyDetailsForm extends Form {
 
         });
         vars.put("name", ni);
-        final Set<Group> gr = target.getGroups();
         names.output(out, l, vars);
 
-        vars.put("support-groups", new GroupIterator(gr.iterator(), true));
-        vars.put("groups", new GroupIterator(gr.iterator(), false));
-        roles.output(out, l, vars);
-
         vars.put("residenceCountry", cs);
         if (target.getReceivedAssurances().length == 0) {
             vars.put("DoB", ds);
@@ -152,6 +162,11 @@ public class MyDetailsForm extends Form {
             assured.output(out, l, vars);
         }
 
+        final Set<Group> gr = target.getGroups();
+        vars.put("support-groups", new GroupIterator(gr.iterator(), true));
+        vars.put("groups", new GroupIterator(gr.iterator(), false));
+        vars.put("groupSelector", selectedGroup);
+        roles.output(out, l, vars);
     }
 
 }
index d01dd3f..d4d7c2f 100644 (file)
@@ -5,5 +5,7 @@
   <? foreach($support-groups) { ?><?=$group_concat?><?=$group?><? } ?>
   <h4><?=_User Managed Permissions?>:</h4>
   <? foreach($groups) { ?><?=$group_concat?><?=$group?><? } ?>
+  <h4><?=_Set User Managed Permissions?>:</h4>
+  <?=$groupSelector?> <button class="btn btn-info" name="action" value="addGroup"><?=_Add Group?></button> <button class="btn btn-info" name="action" value="removeGroup"><?=_Remove Group?></button>
   </div>
-</div>
\ No newline at end of file
+</div>