Skip to content

Commit 53e45af

Browse files
committed
Add self-service parent-based group verification
This will allow a user to self-verify a group that is a subgroup of an already verified group.
1 parent ac6ab0e commit 53e45af

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed

src/clojars/routes/verify.clj

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
[ring.util.response :refer [redirect]]
88
[compojure.core :as compojure :refer [GET POST]]))
99

10+
(defn verify-via-parent
11+
[db username params]
12+
(let [request (merge {:username username}
13+
(select-keys params [:group]))]
14+
(log/with-context (assoc request :tag :verify-group-via-parent-group)
15+
(let [result (verification/verify-group-by-parent-group db request)]
16+
(if-some [error (:error result)]
17+
(log/info {:status :failed
18+
:error error})
19+
(do
20+
(log/info {:status :succeeded})
21+
(log/audit db {:tag :group-verified-via-parent-group
22+
:message (format "group '%s' verified" (:group request))})))
23+
(-> (redirect "/verify/group")
24+
(assoc :flash (merge request result)))))))
25+
1026
(defn verify-via-TXT
1127
[db username params]
1228
(let [request (merge {:username username}
@@ -18,13 +34,16 @@
1834
:error error})
1935
(do
2036
(log/info {:status :succeeded})
21-
(log/audit db {:tag :group-verified
37+
(log/audit db {:tag :group-verified-via-TXT
2238
:message (format "group '%s' verified" (:group request))})))
2339
(-> (redirect "/verify/group")
2440
(assoc :flash (merge request result)))))))
2541

2642
(defn routes [db]
2743
(compojure/routes
44+
(POST "/verify/group/parent" {:keys [params]}
45+
(auth/with-account
46+
#(verify-via-parent db % params)))
2847
(POST "/verify/group/txt" {:keys [params]}
2948
(auth/with-account
3049
#(verify-via-TXT db % params)))

src/clojars/web/group_verification.clj

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
[hiccup.form :refer [label submit-button text-field]]))
77

88
(defn- flash-details
9-
[{:keys [domain group txt-records]}]
9+
[{:keys [domain group parent-group txt-records]}]
1010
[:div#details
1111
[:p "Group: " group]
12-
[:p "Domain: " domain]
12+
(when domain
13+
[:p "Domain: " domain])
14+
(when parent-group
15+
[:p "Parent group: " parent-group])
1316
(when txt-records
1417
(list
1518
[:p "TXT records:"
@@ -53,6 +56,29 @@
5356
"an issue")
5457
" if you run in to any problems verifying your group name."])))
5558

59+
(def ^:private parent-help
60+
(list
61+
[:p "A subgroup is based on a (potential) subdomain of another group. To
62+
verify it, the parent group has to be verified."]
63+
[:p "This will create the group if it doesn't already exist, and can also
64+
be used to verify an existing group."]
65+
[:p "For example, if you are trying to verify the subgroup "
66+
[:code "com.example.ham"]
67+
", and you have already verified "
68+
[:code "com.example"]
69+
", then you can use this verification option."]
70+
[:p "If you haven't verified the parent group and don't need to, you can
71+
verify the group using the TXT record method above, but note that the TXT
72+
record will need to be on the corresponding subdomain."]
73+
[:p "See "
74+
(link-to "https://github.com/clojars/clojars-web/wiki/Verified-Group-Names"
75+
"the wiki")
76+
" for more details on verified group names."]
77+
[:p "Please "
78+
(link-to "https://github.com/clojars/administration/issues/new/choose"
79+
"an issue")
80+
" if you run in to any problems verifying your group name."]))
81+
5682
(defn index
5783
[account flash-data]
5884
(html-doc
@@ -61,7 +87,7 @@
6187
[:div.col-xs-6
6288
[:h1 "Group Verification"]
6389
(format-flash flash-data)
64-
[:div
90+
[:div.via-txt
6591
[:h2 "Verification by TXT Record"]
6692
[:details.help
6793
[:summary "Help"]
@@ -75,4 +101,15 @@
75101
(text-field {:required true
76102
:placeholder "example.com"}
77103
:domain)
104+
(submit-button "Verify Group"))]
105+
[:div.via-parent
106+
[:h2 "Verification by Parent Group"]
107+
[:details.help
108+
[:summary "Help"]
109+
parent-help]
110+
(form-to [:post "/verify/group/parent"]
111+
(label :group "Group name")
112+
(text-field {:required true
113+
:placeholder "com.example.ham"}
114+
:group)
78115
(submit-button "Verify Group"))]]))

test/clojars/integration/group_verification_test.clj

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
(register-as "dantheman" "test@example.org" "password")
1818
(follow-redirect)
1919
(visit "/verify/group")
20-
(fill-in "Group name" "com.example")
21-
(fill-in "Domain with TXT record" "example.com")
22-
(press "Verify Group")
20+
(within [:div.via-txt]
21+
(fill-in "Group name" "com.example")
22+
(fill-in "Domain with TXT record" "example.com")
23+
(press "Verify Group"))
2324
(follow-redirect)
2425
(within [:div.info]
2526
(has (some-text? "The group 'com.example' has been verified"))))))
@@ -30,9 +31,43 @@
3031
(register-as "dantheman" "test@example.org" "password")
3132
(follow-redirect)
3233
(visit "/verify/group")
33-
(fill-in "Group name" "com.example")
34-
(fill-in "Domain with TXT record" "example.org")
35-
(press "Verify Group")
34+
(within [:div.via-txt]
35+
(fill-in "Group name" "com.example")
36+
(fill-in "Domain with TXT record" "example.org")
37+
(press "Verify Group"))
3638
(follow-redirect)
3739
(within [:div.error]
3840
(has (some-text? "Group and domain do not correspond with each other"))))))
41+
42+
(deftest user-can-verify-sub-group
43+
(help/with-TXT ["clojars dantheman"]
44+
(-> (session (help/app))
45+
(register-as "dantheman" "test@example.org" "password")
46+
(follow-redirect)
47+
(visit "/verify/group")
48+
(within [:div.via-txt]
49+
(fill-in "Group name" "com.example")
50+
(fill-in "Domain with TXT record" "example.com")
51+
(press "Verify Group"))
52+
(follow-redirect)
53+
(within [:div.info]
54+
(has (some-text? "The group 'com.example' has been verified")))
55+
56+
(within [:div.via-parent]
57+
(fill-in "Group name" "com.example.ham")
58+
(press "Verify Group"))
59+
(follow-redirect)
60+
(within [:div.info]
61+
(has (some-text? "The group 'com.example.ham' has been verified"))))))
62+
63+
(deftest user-cannot-verify-subgroup-with-non-verified-parent
64+
(-> (session (help/app))
65+
(register-as "dantheman" "test@example.org" "password")
66+
(follow-redirect)
67+
(visit "/verify/group")
68+
(within [:div.via-parent]
69+
(fill-in "Group name" "com.example")
70+
(press "Verify Group"))
71+
(follow-redirect)
72+
(within [:div.error]
73+
(has (some-text? "The group is not a subgroup of a verified group")))))

0 commit comments

Comments
 (0)