]> WPIA git - gigi.git/commitdiff
ADD: Delete affiliations + testcase
authorFelix Dörre <felix@dogcraft.de>
Mon, 27 Oct 2014 20:27:39 +0000 (21:27 +0100)
committerJanis Streib <janis@dogcraft.de>
Wed, 31 Dec 2014 01:35:49 +0000 (02:35 +0100)
src/org/cacert/gigi/pages/orga/AffiliationForm.java
src/org/cacert/gigi/pages/orga/AffiliationForm.templ
tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java [new file with mode: 0644]
tests/org/cacert/gigi/testUtils/ManagedTest.java

index e9ab64b4a56f631be54925c39b5e5514ba88875a..b9a42e7acbfc368d7badc2ca593678e18f42fbcc 100644 (file)
@@ -30,7 +30,15 @@ public class AffiliationForm extends Form {
 
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
-        o.addAdmin(User.getByEmail(req.getParameter("email")), LoginPage.getUser(req), req.getParameter("master") != null);
+        User toRemove = User.getByEmail(req.getParameter("del"));
+        if (toRemove != null) {
+            o.removeAdmin(toRemove, LoginPage.getUser(req));
+        }
+
+        User byEmail = User.getByEmail(req.getParameter("email"));
+        if (byEmail != null) {
+            o.addAdmin(byEmail, LoginPage.getUser(req), req.getParameter("master") != null);
+        }
         return true;
     }
 
@@ -48,6 +56,7 @@ public class AffiliationForm extends Form {
                 Affiliation aff = iter.next();
                 vars.put("name", aff.getTarget().getName());
                 vars.put("master", aff.isMaster() ? l.getTranslation("master") : "");
+                vars.put("e-mail", aff.getTarget().getEmail());
                 return true;
             }
         });
index e3d2410c114b2687cb17c83b4d86787bbad4f3d4..7fbc513caa1dc1fe33ea15c3860db6bd566fa370 100644 (file)
@@ -2,16 +2,19 @@
   <tr>
     <th><?=_Name?></th>
     <th><?=_Master?></th>
+    <th> </th>
   </tr>
 <? foreach($admins) { ?>
   <tr>
     <td><?=$name?></td>
     <td><?=$master?></td>
+    <td><button type="submit" name="del" value="<?=$e-mail?>">X</button> </td>
   </tr>
 <? } ?>
 </table>
 <?=_Add new admin?>:
 <input type="text" name="email">
 <?=_Master?>?
+<input type="hidden" name="affiliate" value="y">
 <input type="checkbox" name="master" value="y">
-<input type="submit" name="affiliate" value="<?=_Add?>">
+<input type="submit" value="<?=_Add?>">
diff --git a/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java b/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java
new file mode 100644 (file)
index 0000000..90355a4
--- /dev/null
@@ -0,0 +1,66 @@
+package org.cacert.gigi.pages.orga;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
+
+import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.dbObjects.Organisation;
+import org.cacert.gigi.dbObjects.Organisation.Affiliation;
+import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.testUtils.ManagedTest;
+import org.junit.Test;
+
+public class TestOrgaManagement extends ManagedTest {
+
+    public User u = User.getById(createVerifiedUser("testuser", "testname", uniq + "@testdom.com", TEST_PASSWORD));
+
+    public String session;
+
+    public TestOrgaManagement() throws IOException {
+        u.grantGroup(u, Group.getByString("orgassurer"));
+        clearCaches();
+        session = login(uniq + "@testdom.com", TEST_PASSWORD);
+    }
+
+    @Test
+    public void testAdd() throws IOException {
+        executeBasicWebInteraction(session, CreateOrgPage.DEFAULT_PATH, "O=name&contact=&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0);
+        Organisation[] orgs = Organisation.getOrganisations(0, 30);
+        assertEquals(1, orgs.length);
+        assertEquals("name", orgs[0].getName());
+        assertEquals("Köln", orgs[0].getCity());
+        assertEquals("ÜÖÄß", orgs[0].getProvince());
+
+        User u2 = User.getById(createVerifiedUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD));
+        executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&affiliate=y&master=y", 1);
+        List<Affiliation> allAdmins = orgs[0].getAllAdmins();
+        assertEquals(1, allAdmins.size());
+        Affiliation affiliation = allAdmins.get(0);
+        assertSame(u2, affiliation.getTarget());
+        assertTrue(affiliation.isMaster());
+
+        executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&affiliate=y", 1);
+        allAdmins = orgs[0].getAllAdmins();
+        assertEquals(2, allAdmins.size());
+        Affiliation affiliation2 = allAdmins.get(0);
+        if (affiliation2.getTarget().getId() == u2.getId()) {
+            affiliation2 = allAdmins.get(1);
+        }
+        assertSame(u.getId(), affiliation2.getTarget().getId());
+        assertFalse(affiliation2.isMaster());
+
+        executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&email=&affiliate=y", 1);
+        assertEquals(1, orgs[0].getAllAdmins().size());
+
+        executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&email=&affiliate=y", 1);
+        assertEquals(0, orgs[0].getAllAdmins().size());
+
+        executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "O=name1&contact=&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0);
+        clearCaches();
+        orgs = Organisation.getOrganisations(0, 30);
+        assertEquals("name1", orgs[0].getName());
+    }
+}
index a65d3f243f655acb20d3abddbc18fd780a2bc54d..2303ef70a3dcb8b7b96eb61535e2d1f32e9ca186 100644 (file)
@@ -155,8 +155,12 @@ public class ManagedTest extends ConfiguredTest {
             e.printStackTrace();
         }
         System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
-        String type = testProps.getProperty("type");
+        clearCaches();
+    }
+
+    public static void clearCaches() throws IOException {
         ObjectCache.clearAllCaches();
+        String type = testProps.getProperty("type");
         if (type.equals("local")) {
             URL u = new URL("https://" + getServerName() + "/manage");
             u.openConnection().getHeaderField("Location");