]> WPIA git - gigi.git/commitdiff
add: functionality to promote a user via test manager to RA Agent
authorINOPIAE <m.maengel@inopiae.de>
Tue, 24 Jul 2018 11:44:53 +0000 (13:44 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 1 Dec 2019 05:10:54 +0000 (06:10 +0100)
Change-Id: Ic954b854bca4c32860db2a707f9cbbe6ecb4b179

util-testing/club/wpia/gigi/pages/Manager.java
util-testing/club/wpia/gigi/pages/Manager.templ

index 6cce345eec5c4cb722165a52d87f6fa02450047b..bd90d2629fb1c05901785bc190cedaff0671b72c 100644 (file)
@@ -409,33 +409,16 @@ public class Manager extends Page {
             }
 
             int vp = 0;
-            int agentNumber = 0;
 
             try {
-                try {
-                    vp = Integer.parseInt(verificationPoints);
-                } catch (NumberFormatException e) {
-                    throw new GigiApiException("No valid Verification Points entered.");
-                }
-
-                if (vp > 100) { // only allow max 100 Verification points
-                    vp = 100;
-                }
-
-                while (vp > 0) {
-                    int currentVP = 10;
-                    if (vp < 10) {
-                        currentVP = vp;
-                    }
-                    Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
-                    agentNumber += 1;
-                    vp -= currentVP;
-                }
-
-            } catch (GigiApiException e) {
-                throw new Error(e);
+                vp = Integer.parseInt(verificationPoints);
+            } catch (NumberFormatException e) {
+                resp.getWriter().println("No valid Verification Points entered.</br>");
+                vp = 0;
             }
 
+            int agentNumber = addVerificationPoints(vp, byEmail);
+
             resp.getWriter().println("User has been verified " + agentNumber + " times.");
 
         } else if (req.getParameter("letverify") != null) {
@@ -503,10 +486,54 @@ public class Manager extends Page {
             pingExempt.remove(dom);
             resp.getWriter().println("Updated domains exempt from pings. Current set: <br/>");
             resp.getWriter().println(HTMLEncoder.encodeHTML(pingExempt.toString()));
+        } else if (req.getParameter("makeAgent") != null) {
+            User u = User.getByEmail(req.getParameter("agentEmail"));
+            if (u == null) {
+                resp.getWriter().println("User not found, or found user is not allowed to verify.");
+            } else {
+                if (u.getVerificationPoints() < 100) {
+                    addVerificationPoints(100, u);
+                }
+                if ( !u.hasPassedCATS()) {
+                    passCATS(u, CATSType.AGENT_CHALLENGE);
+                }
+                if ( !Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)) {
+                    try {
+                        new Contract(u, Contract.ContractType.RA_AGENT_CONTRACT);
+                    } catch (GigiApiException e) {
+                        throw new Error(e);
+                    }
+                }
+                resp.getWriter().println("User has all requirements to be an RA Agent");
+            }
         }
         resp.getWriter().println("<br/><a href='" + PATH + "'>Go back</a>");
     }
 
+    private int addVerificationPoints(int vp, User byEmail) throws Error {
+        int agentNumber = 0;
+
+        try {
+            if (vp > 100) { // only allow max 100 Verification points
+                vp = 100;
+            }
+
+            while (vp > 0) {
+                int currentVP = 10;
+                if (vp < 10) {
+                    currentVP = vp;
+                }
+                Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
+                agentNumber += 1;
+                vp -= currentVP;
+            }
+
+        } catch (GigiApiException e) {
+            throw new Error(e);
+        }
+        return agentNumber;
+    }
+
     private void fetchMails(HttpServletRequest req, HttpServletResponse resp, String mail) throws IOException {
         final LinkedList<String> mails = emails.get(mail);
         HashMap<String, Object> vars = new HashMap<>();
index 857a6d18da61656c2c7afda202bb2eee98792af2..89627aeea5fb50dfdfdda21378252e2d9e1ef5a1 100644 (file)
@@ -52,6 +52,17 @@ Email: <input type="text" name="catsEmail"/>
 <input type="submit" value="Add Challenge" name="cats"/>
 <input type="submit" value="Set Challenge expired" name="catsexpire"/>
 </td></tr>
+
+</td></tr>
+<tr><td>
+Make RA Agent:
+</td><td>
+Email: <input type="text" name="agentEmail"/>
+</td><td>
+Current requirements: 100 VP, passed Assurer Challenge, signed RA Agent Contract</br>
+<input type="submit" value="Add requirements" name="makeAgent"/>
+</td></tr>
+
 <tr><td>
 Add 100 Verification Points:
 </td><td>
@@ -59,7 +70,6 @@ Email: <input type="text" name="verifyEmail"/>
 </td><td>
 Verification Points to issue to preferred name: </br>
 <input type="text" name="verificationPoints" value="100"/> <input type="submit" value="Add Points" name="verify"/>
-
 </td></tr>
 
 <tr><td>