add: show assigned groups to an account in My Detail
authorINOPIAE <m.maengel@inopiae.de>
Thu, 18 Aug 2016 09:47:30 +0000 (11:47 +0200)
committerFelix Dörre <felix@dogcraft.de>
Fri, 19 Aug 2016 20:59:17 +0000 (22:59 +0200)
fixes issue #114

Change-Id: I2072080316247b6fca283cf548c4418da63ab8fc

src/org/cacert/gigi/output/GroupIterator.java [new file with mode: 0644]
src/org/cacert/gigi/output/GroupSelector.java
src/org/cacert/gigi/pages/account/MyDetailsForm.java
src/org/cacert/gigi/pages/account/MyDetailsRoles.templ [new file with mode: 0644]
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ

diff --git a/src/org/cacert/gigi/output/GroupIterator.java b/src/org/cacert/gigi/output/GroupIterator.java
new file mode 100644 (file)
index 0000000..4e35db4
--- /dev/null
@@ -0,0 +1,37 @@
+package org.cacert.gigi.output;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.IterableDataset;
+
+public class GroupIterator implements IterableDataset {
+
+    private final boolean asSupport;
+
+    private final Iterator<Group> i;
+
+    public GroupIterator(Iterator<Group> i, boolean asSupport) {
+        this.asSupport = asSupport;
+        this.i = i;
+    }
+
+    private int j = 0;
+
+    @Override
+    public boolean next(Language l, Map<String, Object> vars) {
+        while (i.hasNext()) {
+            Group g = i.next();
+            if (g.isManagedBySupport() == asSupport) {
+                vars.put("group_concat", (j > 0 ? ", " : ""));
+                vars.put("group", g.getName());
+                j++;
+                return true;
+            }
+        }
+
+        return false;
+    }
+}
index f65fab7..66236e1 100644 (file)
@@ -39,11 +39,13 @@ public class GroupSelector implements Outputable {
         out.println("<select name='" + name + "'>");
         for (Group g : Group.values()) {
             if (supportFlag == g.isManagedBySupport()) {
-                out.print("<option name='" + g.getDatabaseName());
+                out.print("<option value='" + g.getDatabaseName());
                 if (g.equals(value)) {
                     out.print(" selected");
                 }
-                out.println("'>" + g.getDatabaseName() + "</option>");
+                out.println("'>");
+                g.getName().output(out, l, vars);
+                out.println("</option>");
             }
         }
         out.println("</select>");
index a8ca49f..d6b65e0 100644 (file)
@@ -2,16 +2,19 @@ package org.cacert.gigi.pages.account;
 
 import java.io.PrintWriter;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 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.NameInput;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.Template;
@@ -25,6 +28,8 @@ public class MyDetailsForm extends Form {
 
     private static final Template names = new Template(MyDetailsForm.class.getResource("NamesForm.templ"));
 
+    private static final Template roles = new Template(MyDetailsForm.class.getResource("MyDetailsRoles.templ"));
+
     private User target;
 
     private DateSelector ds;
@@ -131,7 +136,13 @@ 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);
@@ -140,6 +151,7 @@ public class MyDetailsForm extends Form {
             vars.put("DoB", target.getDoB());
             assured.output(out, l, vars);
         }
+
     }
 
 }
diff --git a/src/org/cacert/gigi/pages/account/MyDetailsRoles.templ b/src/org/cacert/gigi/pages/account/MyDetailsRoles.templ
new file mode 100644 (file)
index 0000000..d01dd3f
--- /dev/null
@@ -0,0 +1,9 @@
+<div class="panel panel-default">
+  <div class="panel-heading"><?=_Permissions / Group Assignments?></div>
+  <div class="panel-body">
+  <h4><?=_Support Managed Permissions?>:</h4>
+  <? foreach($support-groups) { ?><?=$group_concat?><?=$group?><? } ?>
+  <h4><?=_User Managed Permissions?>:</h4>
+  <? foreach($groups) { ?><?=$group_concat?><?=$group?><? } ?>
+  </div>
+</div>
\ No newline at end of file
index df78405..28597ca 100644 (file)
@@ -1,7 +1,6 @@
 package org.cacert.gigi.pages.admin.support;
 
 import java.io.PrintWriter;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -15,9 +14,9 @@ import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.ArrayIterable;
 import org.cacert.gigi.output.DateSelector;
+import org.cacert.gigi.output.GroupIterator;
 import org.cacert.gigi.output.GroupSelector;
 import org.cacert.gigi.output.template.Form;
-import org.cacert.gigi.output.template.IterableDataset;
 import org.cacert.gigi.output.template.Outputable;
 import org.cacert.gigi.output.template.SprintfCommand;
 import org.cacert.gigi.output.template.Template;
@@ -107,20 +106,8 @@ public class SupportUserDetailsForm extends Form {
         vars.put("assurancepoints", user.getAssurancePoints());
         vars.put("exppoints", user.getExperiencePoints());
         final Set<Group> gr = user.getGroups();
-        vars.put("groups", new IterableDataset() {
-
-            Iterator<Group> i = gr.iterator();
-
-            @Override
-            public boolean next(Language l, Map<String, Object> vars) {
-                if ( !i.hasNext()) {
-                    return false;
-                }
-                Group g = i.next();
-                vars.put("group_name", g.getName());
-                return true;
-            }
-        });
+        vars.put("support-groups", new GroupIterator(gr.iterator(), true));
+        vars.put("groups", new GroupIterator(gr.iterator(), false));
         vars.put("groupSelector", value);
         t.output(out, l, vars);
     }
index e259cd2..ced40d8 100644 (file)
         </tr>
         
         <tr>
-            <td><?=_Groups?>:</td>
-            <td><p><? foreach($groups) { ?><?=$group_name?>, <? } ?></p>
+            <td><?=_Support Managed Groups?>:</td>
+            <td><p><? foreach($support-groups) { ?><?=$group_concat?><?=$group?><? } ?></p>
             <p><?=$groupSelector?><input class="btn btn-info" type='submit' value='<?=_Grant Group?>' name='grant'> <input class="btn btn-info" type='submit' value='<?=_Deny Group?>' name='deny'></p>
             </td>
         </tr>
+
+        <tr>
+            <td><?=_User Managed Groups?>:</td>
+            <td><p><? foreach($groups) { ?><?=$group_concat?><?=$group?><? } ?></p>
+            </td>
+        </tr>
+
         <tr>
             <td><?=_Reset Password?>:</td>
             <td><input type="text" name="aword"> <input class="btn btn-primary" type="submit" value="<?=_Reset Password?>" name="resetPass"></td>