Skip to content

Commit

Permalink
Merge branch 'master' into 206-grant-admin-UI
Browse files Browse the repository at this point in the history
  • Loading branch information
skydread1 committed Jul 26, 2023
2 parents a7b7b1c + f229bee commit 76ab6b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions server/src/flybot/server/core/handler/operation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@
:user-email email}}

:else
(let [new-user (update user :user/roles conj {:role/name role-to-grant
:role/date-granted (utils/mk-date)})]
{:response new-user
:effects {:db {:payload [new-user]}}}))))
(let [new-role {:role/name role-to-grant :role/date-granted (utils/mk-date)}]
{:response (update user :user/roles conj new-role)
:effects {:db {:payload [(assoc user :user/roles [new-role])]}}}))))

(def grant-admin-role
#(grant-role % %2 :editor :admin))
Expand Down
9 changes: 5 additions & 4 deletions server/test/flybot/server/core/handler/operation_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@
:requested-role :owner
:user-email editor-email}}
(sut/grant-owner-role (d/db db-conn) editor-email)))))
(testing "User exits so returns user with new admin role effect."
(testing "User exits and has required role so returns user with new admin role effect."
(with-redefs [utils/mk-date (constantly s/alice-date-granted)]
(let [updated-alice (update s/alice-user :user/roles conj {:role/name :admin
:role/date-granted (utils/mk-date)})]
(let [new-role {:role/name :admin :role/date-granted (utils/mk-date)}
updated-alice (update s/alice-user :user/roles conj new-role)
effects (assoc s/alice-user :user/roles [new-role])]
(is (= {:response updated-alice
:effects {:db {:payload [updated-alice]}}}
:effects {:db {:payload [effects]}}}
(sut/grant-admin-role (d/db db-conn) (:user/email s/alice-user)))))))
(testing "User does not exist so returns error map."
(is (= {:error {:type :user/not-found
Expand Down

0 comments on commit 76ab6b7

Please sign in to comment.