Skip to content

Commit 6c939ae

Browse files
committed
Revert "Revert "Move users endpoint to v1.1""
This reverts commit 68f1167.
1 parent bce8d66 commit 6c939ae

File tree

5 files changed

+73
-31
lines changed

5 files changed

+73
-31
lines changed

src-cljs/frontend/api/path.cljs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns frontend.api.path
22
(:require [goog.string :as gstring]))
33

4-
(defn base-project-url-path [vcs-type]
4+
(defn- base-project-url-path [vcs-type]
55
(case vcs-type
66
"bitbucket" (gstring/format
77
"/api/dangerzone/project/%s"
@@ -69,6 +69,20 @@
6969
"%s/%s/enable"
7070
(base-project-url-path vcs-type) project))
7171

72+
(defn project-users [vcs-type project-name]
73+
(gstring/format "%s/%s/users"
74+
(base-project-url-path vcs-type)
75+
project-name))
76+
77+
(defn project-users-invite [vcs-type project-name]
78+
(gstring/format "%s/%s/users/invite"
79+
(base-project-url-path vcs-type)
80+
project-name))
81+
82+
(defn organization-invite [vcs-type org-name]
83+
(gstring/format "%s/invite"
84+
(base-organization-url-path vcs-type org-name)))
85+
7286
(defn build-retry [vcs-type org-name repo-name build-num]
7387
(gstring/format
7488
"%s/%s/%s/%s/retry"

src-cljs/frontend/components/build.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
(when (build-model/display-build-invite build)
144144
(om/build invites/build-invites
145145
(:invite-data data)
146-
{:opts {:project-name (vcs-url/project-name (:vcs_url build))}}))]]])))))
146+
{:opts {:vcs-type (vcs-url/vcs-type (:vcs_url build))
147+
:project-name (vcs-url/project-name (:vcs_url build))}}))]]])))))
147148

148149
(defn container-result-icon [{:keys [name]} owner]
149150
(reify

src-cljs/frontend/components/invites.cljs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
:on-click #(raise! owner [:invited-github-users
7272
(merge {:invitees users-to-invite}
7373
(if (:project-name opts)
74-
{:project-name (:project-name opts)}
74+
{:project-name (:project-name opts)
75+
:vcs-type (:vcs-type opts)}
7576
{:org-name (:org-name opts)}))])})
7677

7778
"Send Invites "
@@ -81,8 +82,10 @@
8182
(reify
8283
om/IWillMount
8384
(will-mount [_]
84-
(let [project-name (:project-name opts)]
85-
(raise! owner [:load-first-green-build-github-users {:project-name project-name}])))
85+
(let [project-name (:project-name opts)
86+
vcs-type (:vcs-type opts)]
87+
(raise! owner [:load-first-green-build-github-users {:vcs-type vcs-type
88+
:project-name project-name}])))
8689
om/IRender
8790
(render [_]
8891
(let [project-name (:project-name opts)

src-cljs/frontend/controllers/controls.cljs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -843,33 +843,36 @@
843843

844844

845845
(defmethod post-control-event! :load-first-green-build-github-users
846-
[target message {:keys [project-name]} previous-state current-state]
847-
(ajax/ajax :get
848-
(gstring/format "/api/v1/project/%s/users" project-name)
849-
:first-green-build-github-users
850-
(get-in current-state [:comms :api])
851-
:context {:project-name project-name}))
852-
846+
[target message {:keys [vcs-type project-name]} previous-state current-state]
847+
(if (or (nil? vcs-type) (= "github" vcs-type))
848+
(ajax/ajax :get
849+
(api-path/project-users vcs-type project-name)
850+
:first-green-build-github-users
851+
(get-in current-state [:comms :api])
852+
:context {:project-name project-name})))
853853

854854
(defmethod post-control-event! :invited-github-users
855-
[target message {:keys [project-name org-name invitees]} previous-state current-state]
856-
(let [context (if project-name
857-
;; TODO: non-hackish way to indicate the type of invite
858-
{:project project-name :first_green_build true}
859-
{:org org-name})]
860-
(button-ajax :post
861-
(if project-name
862-
(gstring/format "/api/v1/project/%s/users/invite" project-name)
863-
(gstring/format "/api/v1/organization/%s/invite" org-name))
864-
:invite-github-users
865-
(get-in current-state [:comms :api])
866-
:context context
867-
:params invitees
868-
:events {:success #(analytics/track {:event-type :teammates-invited
869-
:current-state current-state
870-
:properties {:vcs-type :github
871-
:invitees invitees
872-
:invitee-count (count invitees)}})})))
855+
[target message {:keys [vcs-type project-name org-name invitees]} previous-state current-state]
856+
(if (or (nil? vcs-type) (= "github" vcs-type))
857+
(let [project-vcs-type (or vcs-type "github")
858+
org-vcs-type "github"
859+
context (if project-name
860+
;; TODO: non-hackish way to indicate the type of invite
861+
{:project project-name :first_green_build true}
862+
{:org org-name})]
863+
(button-ajax :post
864+
(if project-name
865+
(api-path/project-users-invite project-vcs-type project-name)
866+
(api-path/organization-invite org-vcs-type org-name))
867+
:invite-github-users
868+
(get-in current-state [:comms :api])
869+
:context context
870+
:params invitees
871+
:events {:success #(analytics/track {:event-type :teammates-invited
872+
:current-state current-state
873+
:properties {:vcs-type :github
874+
:invitees invitees
875+
:invitee-count (count invitees)}})}))))
873876

874877
(defmethod post-control-event! :report-build-clicked
875878
[target message {:keys [build-url]} previous-state current-state]

test-cljs/frontend/controllers/controls_test.cljs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[frontend.state :as state]
55
[frontend.utils.ajax :as ajax]
66
[frontend.analytics.core :as analytics]
7+
[frontend.api.path :as api-path]
78
[frontend.controllers.controls :as controls]
89
[bond.james :as bond :include-macros true]
910
[goog.string :as gstring])
@@ -207,6 +208,7 @@
207208
(deftest post-control-event-invited-github-users-works
208209
(let [calls (atom [])
209210
project-name "proj"
211+
vcs-type "github"
210212
invitees ["me@foo.com", "you@bar.co"]
211213
control-data {:project-name project-name
212214
:org-name "org"
@@ -221,9 +223,28 @@
221223
args (-> calls first :args)]
222224
(is (= (count calls) 1))
223225
(is (= (nth args 0) :post))
224-
(is (= (nth args 1) (gstring/format "/api/v1/project/%s/users/invite" project-name)))
226+
(is (= (nth args 1) (api-path/project-users-invite vcs-type project-name)))
225227
(is (= (nth args 2) :invite-github-users))
226228
(is (= (nth args 3) api-ch))
227229
(is (= (->> (nth args 4) (apply hash-map) :context) {:project project-name
228230
:first_green_build true}))
229231
(is (= (->> (nth args 4) (apply hash-map) :params) invitees)))))))
232+
233+
(deftest post-control-event-invited-github-users-does-nothing-for-bb-projects
234+
(let [calls (atom [])
235+
project-name "proj"
236+
vcs-type "bitbucket"
237+
invitees ["me@foo.com", "you@bar.co"]
238+
control-data {:project-name project-name
239+
:vcs-type vcs-type
240+
:org-name "org"
241+
:invitees ["me@foo.com", "you@bar.co"]}
242+
api-ch "api-ch"
243+
current-state {:comms {:api api-ch}}]
244+
(testing "the post-control-event invite-github-users does nothing for bitbucket projects"
245+
(with-redefs [controls/button-ajax (fn [method url message channel & opts]
246+
(swap! calls conj {:args (list method url message channel opts)}))]
247+
(controls/post-control-event! {} :invited-github-users control-data {} current-state)
248+
(let [calls @calls
249+
args (-> calls first :args)]
250+
(is (= (count calls) 0)))))))

0 commit comments

Comments
 (0)