]> WPIA git - gigi.git/commitdiff
Merge changes Ica9a9fc2,I5effef05
authorFelix Dörre <felix@dogcraft.de>
Sun, 18 Feb 2018 16:00:30 +0000 (17:00 +0100)
committerGerrit Code Review <gigi-system@dogcraft.de>
Sun, 18 Feb 2018 16:00:30 +0000 (17:00 +0100)
* changes:
  chg: reword error message to match conditions
  chg: enable support to find organisation domains

src/club/wpia/gigi/Gigi.java
src/club/wpia/gigi/dbObjects/Organisation.java
src/club/wpia/gigi/pages/admin/support/FindUserByDomainForm.java
src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.java [new file with mode: 0644]
src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.templ [new file with mode: 0644]
tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java

index 035f1a6f5430997139c9c8060212cddd5ee8494b..15a52143e745394df63b579e7dedb1ac2c14e003 100644 (file)
@@ -64,6 +64,7 @@ import club.wpia.gigi.pages.admin.support.FindCertPage;
 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
 import club.wpia.gigi.pages.admin.support.FindUserByEmailPage;
 import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
+import club.wpia.gigi.pages.admin.support.SupportOrgDomainPage;
 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
 import club.wpia.gigi.pages.error.AccessDenied;
 import club.wpia.gigi.pages.error.PageNotFound;
@@ -175,6 +176,7 @@ public final class Gigi extends HttpServlet {
 
             Menu account = createMenu("My Account");
             putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage(), null);
+            putPage(SupportOrgDomainPage.PATH + "*", new SupportOrgDomainPage(), null);
             putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), account);
             putPage(History.PATH, new History(false), account);
             putPage(FindAgentAccess.PATH, new OneFormPage("Access to Find Agent", FindAgentAccess.class), account);
index c9754565744b0d107baee2515f802e2e2cae9fbe..0e1c8661fab8b5033072f9d9cb3603935e196dae 100644 (file)
@@ -152,7 +152,7 @@ public class Organisation extends CertificateOwner {
 
     public synchronized void addAdmin(User admin, User actor, boolean master) throws GigiApiException {
         if (actor == admin) {
-            throw new GigiApiException("You may not add yourself as Organisation Admin. Ask another Organisation Agent to do so.");
+            throw new GigiApiException("You may not add yourself as Organisation Admin. Ask another Organisation Agent or Organisation Admin to do so.");
         }
         if ( !admin.canVerify()) {
             throw new GigiApiException("Cannot add person who is not RA Agent.");
index 75c8c590166e1afe36485d2421d34b29c8f76225..500a3b0ae5e886cce3ba87859b338a6dfc9feab0 100644 (file)
@@ -59,7 +59,7 @@ public class FindUserByDomainForm extends Form {
         if (res instanceof User) {
             return new RedirectResult(SupportUserDetailsPage.PATH + res.getId() + "/");
         } else if (res instanceof Organisation) {
-            return new RedirectResult("/support/domain/" + res.getId());
+            return new RedirectResult(SupportOrgDomainPage.PATH + d.getId());
         } else {
             throw new PermamentFormException(new GigiApiException("Unknown owner type."));
         }
diff --git a/src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.java b/src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.java
new file mode 100644 (file)
index 0000000..019f249
--- /dev/null
@@ -0,0 +1,59 @@
+package club.wpia.gigi.pages.admin.support;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import club.wpia.gigi.dbObjects.Domain;
+import club.wpia.gigi.dbObjects.Organisation;
+import club.wpia.gigi.pages.Page;
+import club.wpia.gigi.util.AuthorizationContext;
+
+public class SupportOrgDomainPage extends Page {
+
+    public static final String PATH = "/support/domain/";
+
+    public SupportOrgDomainPage() {
+        super("Support: Organisation Domain");
+    }
+
+    @Override
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac != null && ac.canSupport();
+    }
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        Domain orgDomain = getDomain(req, resp);
+        if (orgDomain == null) {
+            return;
+        }
+
+        Organisation org = Organisation.getById(orgDomain.getOwner().getId());
+        Map<String, Object> vars = getDefaultVars(req);
+        vars.put("domain", orgDomain.getSuffix());
+        vars.put("organisation", org.getName());
+
+        getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
+    }
+
+    private Domain getDomain(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+        int id = -1;
+        String[] idP = req.getPathInfo().split("/");
+        try {
+            id = Integer.parseInt(idP[idP.length - 1]);
+        } catch (NumberFormatException e) {
+            resp.sendError(400);
+            return null;
+        }
+        final Domain domain = Domain.getById(id);
+        if (domain == null) {
+            resp.sendError(400);
+            return null;
+        }
+        return domain;
+    }
+
+}
diff --git a/src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.templ b/src/club/wpia/gigi/pages/admin/support/SupportOrgDomainPage.templ
new file mode 100644 (file)
index 0000000..79f5e34
--- /dev/null
@@ -0,0 +1 @@
+<?=_The domain '${domain}' is linked to the organisation '${organisation}'.?>
index 383d23265094a5af76d339a773a31a0d22493103..d820a1d18cc464f35d38ddad25bae17ab36c9a26 100644 (file)
@@ -1,9 +1,11 @@
 package club.wpia.gigi.pages.admin;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URLConnection;
 import java.net.URLEncoder;
@@ -13,9 +15,14 @@ import org.junit.Assume;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.Country;
+import club.wpia.gigi.dbObjects.Country.CountryCodeType;
 import club.wpia.gigi.dbObjects.Domain;
+import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.Organisation;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
+import club.wpia.gigi.pages.admin.support.SupportOrgDomainPage;
 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.SEClientTest;
@@ -72,4 +79,38 @@ public class TestSEAdminPageUserDomainSearch extends SEClientTest {
         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
+
+    @Test
+    public void testOrgDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
+        // generate organisation with domain
+        u.grantGroup(getSupporter(), Group.ORG_AGENT);
+        Organisation o1 = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
+        String dom = createUniqueName() + ".de";
+        Domain d = new Domain(u, o1, dom);
+
+        // test
+        URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(dom, "UTF-8"));
+
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportOrgDomainPage.PATH + d.getId(), uc.getHeaderField("Location"));
+
+        String s = IOUtils.readURL(get(cookie, SupportOrgDomainPage.PATH + d.getId()));
+        assertThat(s, containsString(dom));
+        assertThat(s, containsString(o1.getName()));
+
+        // test malformated id
+        HttpURLConnection uc1 = get(SupportOrgDomainPage.PATH + d.getId() + "a");
+        assertEquals(400, uc1.getResponseCode());
+
+        // test non existing id
+        uc1 = get(SupportOrgDomainPage.PATH + "5000");
+        assertEquals(400, uc1.getResponseCode());
+
+    }
+
+    @Test
+    public void testDomainSearchByMalformatedId() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
+        URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId() + "a");
+        assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
+    }
+
 }