X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FViewOrgPage.java;h=887761076759dd37df1fd5170f2cfa481172f7d8;hb=d7ca3ea303443dbe54163c06c2b097c8d14b6e6f;hp=c8259412ae4dca1452d0b33189079ce859203d5b;hpb=c6ddac41eea60b524e52f192e4d53b327a476f75;p=gigi.git diff --git a/src/org/cacert/gigi/pages/orga/ViewOrgPage.java b/src/org/cacert/gigi/pages/orga/ViewOrgPage.java index c8259412..88776107 100644 --- a/src/org/cacert/gigi/pages/orga/ViewOrgPage.java +++ b/src/org/cacert/gigi/pages/orga/ViewOrgPage.java @@ -9,23 +9,23 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Organisation; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.localisation.Language; import org.cacert.gigi.output.template.Form; +import org.cacert.gigi.output.template.Form.CSRFException; import org.cacert.gigi.output.template.IterableDataset; import org.cacert.gigi.output.template.Template; import org.cacert.gigi.pages.LoginPage; -import org.cacert.gigi.pages.Page; +import org.cacert.gigi.pages.ManagedMultiFormPage; import org.cacert.gigi.pages.account.domain.DomainManagementForm; import org.cacert.gigi.util.AuthorizationContext; -public class ViewOrgPage extends Page { +public class ViewOrgPage extends ManagedMultiFormPage { - private final Template orgas = new Template(ViewOrgPage.class.getResource("ViewOrgs.templ")); + private static final Template orgas = new Template(ViewOrgPage.class.getResource("ViewOrgs.templ")); - private final Template mainTempl = new Template(ViewOrgPage.class.getResource("EditOrg.templ")); + private static final Template mainTempl = new Template(ViewOrgPage.class.getResource("EditOrg.templ")); public static final String DEFAULT_PATH = "/orga"; @@ -39,38 +39,21 @@ public class ViewOrgPage extends Page { } @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - User u = LoginPage.getUser(req); - if (req.getParameter("do_affiliate") != null || req.getParameter("del") != null) { - AffiliationForm form = Form.getForm(req, AffiliationForm.class); - if (form.submit(resp.getWriter(), req)) { - resp.sendRedirect(DEFAULT_PATH + "/" + form.getOrganisation().getId()); - } - return; - } else { - if ( !u.isInGroup(CreateOrgPage.ORG_ASSURER)) { - resp.sendError(403, "Access denied"); - return; - } - - if (req.getParameter("addDomain") != null) { - OrgDomainAddForm form = Form.getForm(req, OrgDomainAddForm.class); - if (form.submit(resp.getWriter(), req)) { - resp.sendRedirect(DEFAULT_PATH + "/" + form.getOrganisation().getId()); - } - } else if (req.getParameter("delete") != null) { - DomainManagementForm form = Form.getForm(req, DomainManagementForm.class); - if (form.submit(resp.getWriter(), req)) { - resp.sendRedirect(DEFAULT_PATH + "/" + form.getTarget().getId()); - } - } else { - Form.getForm(req, CreateOrgForm.class).submit(resp.getWriter(), req); - } + public Form getForm(HttpServletRequest req) throws CSRFException { + if (req.getParameter("do_affiliate") != null || req.getParameter("del") != null) { + return Form.getForm(req, AffiliationForm.class); + } else { + if ( !getUser(req).isInGroup(CreateOrgPage.ORG_ASSURER)) { + return null; } - } catch (GigiApiException e) { - e.format(resp.getWriter(), getLanguage(req)); + if (req.getParameter("addDomain") != null) { + return Form.getForm(req, OrgDomainAddForm.class); + } else if (req.getParameter("delete") != null) { + return Form.getForm(req, DomainManagementForm.class); + } else { + return Form.getForm(req, CreateOrgForm.class); + } } } @@ -81,16 +64,16 @@ public class ViewOrgPage extends Page { Language lang = getLanguage(req); PrintWriter out = resp.getWriter(); if (idS.length() < DEFAULT_PATH.length() + 2) { - final Organisation[] orgas = Organisation.getOrganisations(0, 30); + final Organisation[] orgList = Organisation.getOrganisations(0, 30); HashMap map = new HashMap<>(); final List myOrgs = u.getOrganisations(true); final boolean orgAss = u.isInGroup(CreateOrgPage.ORG_ASSURER); if (orgAss) { - map.put("orgas", makeOrgDataset(orgas)); + map.put("orgas", makeOrgDataset(orgList)); } else { map.put("orgas", makeOrgDataset(myOrgs.toArray(new Organisation[myOrgs.size()]))); } - this.orgas.output(out, lang, map); + orgas.output(out, lang, map); return; } idS = idS.substring(DEFAULT_PATH.length() + 1); @@ -134,7 +117,7 @@ public class ViewOrgPage extends Page { Organisation org = orgas[count++]; vars.put("id", Integer.toString(org.getId())); vars.put("name", org.getName()); - vars.put("country", org.getState()); + vars.put("country", org.getState().getCode()); return true; } };