diff --git a/src/metabase/api/org.clj b/src/metabase/api/org.clj index d28793f957ca27063858b2e46d8526d11432e9ac..0f32b6dc98c4a1446ccdbb65720403f42c554570 100644 --- a/src/metabase/api/org.clj +++ b/src/metabase/api/org.clj @@ -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) diff --git a/test/metabase/api/org_test.clj b/test/metabase/api/org_test.clj index 78589eb19f85a194f737b9bf7142374e879d0fe7..f5b4651576a0d46db9f418bbf738dab5574d1f9a 100644 --- a/test/metabase/api/org_test.clj +++ b/test/metabase/api/org_test.clj @@ -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 $