Skip to content

Commit 4f37c72

Browse files
committed
Not react to first-green-build and invite-users actions on BB projects
1 parent a6b990f commit 4f37c72

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

src-cljs/frontend/controllers/controls.cljs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -849,32 +849,35 @@
849849

850850
(defmethod post-control-event! :load-first-green-build-github-users
851851
[target message {:keys [vcs-type project-name]} previous-state current-state]
852-
(ajax/ajax :get
853-
(api-path/project-users vcs-type project-name)
854-
:first-green-build-github-users
855-
(get-in current-state [:comms :api])
856-
:context {:project-name project-name}))
852+
(if (or (nil? vcs-type) (= "github" vcs-type))
853+
(ajax/ajax :get
854+
(api-path/project-users vcs-type project-name)
855+
:first-green-build-github-users
856+
(get-in current-state [:comms :api])
857+
:context {:project-name project-name})))
857858

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

879882
(defmethod post-control-event! :report-build-clicked
880883
[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)