Skip to content
Snippets Groups Projects
Commit 3f02229c authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #216 from metabase/ag-org-create-admin-perm

when we create a new org via api lets automatically add the creator as an admin member.
parents f6073bd2 802da8f7
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,14 @@
(require-params name slug)
;; user must be a superuser to proceed
(check-403 (:is_superuser @*current-user*))
(->> (util/select-non-nil-keys body :slug :name :description :logo_url)
(mapply ins Org)))
;; create the new org
(let-500 [{:keys [id] :as new-org} (->> (util/select-non-nil-keys body :slug :name :description :logo_url)
(mapply ins Org))]
;; now that the Org exists, add the creator as the first admin member
(grant-org-perm id *current-user-id* true)
;; make sure the api response is still the newly created org
new-org))
(defendpoint GET "/:id" [id]
(->404 (sel :one Org :id id)
......
......@@ -95,7 +95,13 @@
:description nil
:logo_url nil
:inherits false})
(create-org org-name)))
(let [new-org (create-org org-name)
org-perm (sel :one OrgPerm :organization_id (:id new-org))]
;; do a quick validation that the creator is now an admin of the new org
(assert (= (:user_id org-perm) (user->id :crowberto)))
(assert (:admin org-perm))
;; return the original api response, which should be the newly created org
new-org)))
;; Test input validations on org create
(expect "'name' is a required param."
......@@ -296,7 +302,7 @@
(let [test-org-name (random-name)]
(expect-eval-actual-first
(let [{my-org-id :id} (sel :one Org :name test-org-name)]
(match-$ (first (sel :many OrgPerm :organization_id my-org-id))
(match-$ (sel :one OrgPerm :organization_id my-org-id :user_id [not= (user->id :crowberto)])
{:id $
:admin true
:user_id $
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment