diff --git a/backend/src/app/rpc/mutations/teams.clj b/backend/src/app/rpc/mutations/teams.clj index 09d0f112df..64386e4456 100644 --- a/backend/src/app/rpc/mutations/teams.clj +++ b/backend/src/app/rpc/mutations/teams.clj @@ -104,6 +104,8 @@ ;; --- Mutation: Leave Team +(declare role->params) + (s/def ::reassign-to ::us/uuid) (s/def ::leave-team (s/keys :req-un [::profile-id ::id] @@ -120,7 +122,7 @@ ;; besides the current profile (<= (count members) 1) (ex/raise :type :validation - :code :cant-leave-team + :code :no-enough-members-for-leave :context {:members (count members)}) ;; if the `reassign-to` is filled and has a different value @@ -183,7 +185,6 @@ ;; --- Mutation: Team Update Role (declare retrieve-team-member) -(declare role->params) (s/def ::team-id ::us/uuid) (s/def ::member-id ::us/uuid) diff --git a/backend/src/app/rpc/queries/teams.clj b/backend/src/app/rpc/queries/teams.clj index 4072372374..49fbd66c15 100644 --- a/backend/src/app/rpc/queries/teams.clj +++ b/backend/src/app/rpc/queries/teams.clj @@ -21,8 +21,10 @@ tpr.is_admin, tpr.can_edit from team_profile_rel as tpr + join team as t on (t.id = tpr.team_id) where tpr.profile_id = ? - and tpr.team_id = ?") + and tpr.team_id = ? + and t.deleted_at is null") (defn get-permissions [conn profile-id team-id] diff --git a/backend/test/app/services_teams_test.clj b/backend/test/app/services_teams_test.clj index 6e2aaeea7b..4124325b3b 100644 --- a/backend/test/app/services_teams_test.clj +++ b/backend/test/app/services_teams_test.clj @@ -33,7 +33,6 @@ :role :editor :profile-id (:id profile1)}] - ;; invite external user without complaints (let [data (assoc data :email "foo@bar.com") out (th/mutation! data)] @@ -136,9 +135,10 @@ :profile-id (:id profile1)} out (th/query! data)] ;; (th/print-result! out) - (t/is (nil? (:error out))) - (let [result (:result out)] - (t/is (= 0 (count result))))) + (let [error (:error out) + error-data (ex-data error)] + (t/is (th/ex-info? error)) + (t/is (= (:type error-data) :not-found)))) ;; run permanent deletion (let [result (task {:max-age (dt/duration 0)})] diff --git a/frontend/resources/styles/main/partials/exception-page.scss b/frontend/resources/styles/main/partials/exception-page.scss index d46261f89c..f0815818b1 100644 --- a/frontend/resources/styles/main/partials/exception-page.scss +++ b/frontend/resources/styles/main/partials/exception-page.scss @@ -12,6 +12,7 @@ display: flex; align-items: center; padding: 32px; + z-index: 1000; cursor: pointer; diff --git a/frontend/src/app/main/data/dashboard.cljs b/frontend/src/app/main/data/dashboard.cljs index d7d85d94fa..18399a582a 100644 --- a/frontend/src/app/main/data/dashboard.cljs +++ b/frontend/src/app/main/data/dashboard.cljs @@ -16,6 +16,7 @@ [app.main.repo :as rp] [app.util.i18n :as i18n :refer [tr]] [app.util.router :as rt] + [app.util.timers :as tm] [beicon.core :as rx] [cljs.spec.alpha :as s] [potok.core :as ptk])) @@ -402,7 +403,7 @@ (uuid? reassign-to) (assoc :reassign-to reassign-to))] (->> (rp/mutation! :leave-team params) - (rx/tap on-success) + (rx/tap #(tm/schedule on-success)) (rx/catch on-error)))))) (defn invite-team-member diff --git a/frontend/src/app/main/ui/dashboard/sidebar.cljs b/frontend/src/app/main/ui/dashboard/sidebar.cljs index efdd15d7b6..9634608705 100644 --- a/frontend/src/app/main/ui/dashboard/sidebar.cljs +++ b/frontend/src/app/main/ui/dashboard/sidebar.cljs @@ -28,6 +28,7 @@ [app.util.i18n :as i18n :refer [tr]] [app.util.object :as obj] [app.util.router :as rt] + [beicon.core :as rx] [cljs.spec.alpha :as s] [goog.functions :as f] [rumext.alpha :as mf])) @@ -287,27 +288,39 @@ members-map (mf/deref refs/dashboard-team-members) members (vals members-map) - on-rename-clicked - (st/emitf (modal/show :team-form {:team team})) - - on-leaved-success - (fn [] - (st/emit! (modal/hide) - (du/fetch-teams))) - - leave-fn - (st/emitf (dd/leave-team (with-meta {} {:on-success on-leaved-success}))) - - leave-and-reassign-fn - (fn [member-id] - (let [params {:reassign-to member-id}] - (st/emit! (dd/go-to-projects (:default-team-id profile)) - (dd/leave-team (with-meta params {:on-success on-leaved-success}))))) - - delete-fn + on-success (fn [] (st/emit! (dd/go-to-projects (:default-team-id profile)) - (dd/delete-team (with-meta team {:on-success on-leaved-success})))) + (modal/hide) + (du/fetch-teams))) + + on-error + (fn [{:keys [code] :as error}] + (condp = code + :no-enough-members-for-leave + (rx/of (dm/error (tr "errors.team-leave.insufficient-members"))) + + :member-does-not-exist + (rx/of (dm/error (tr "errors.team-leave.member-does-not-exists"))) + + :owner-cant-leave-team + (rx/of (dm/error (tr "errors.team-leave.owner-cant-leave"))) + + (rx/throw error))) + + leave-fn + (fn [member-id] + (let [params (cond-> {} (uuid? member-id) (assoc :reassign-to member-id))] + (st/emit! (dd/leave-team (with-meta params + {:on-success on-success + :on-error on-error}))))) + delete-fn + (fn [] + (st/emit! (dd/delete-team (with-meta team {:on-success on-success + :on-error on-error})))) + on-rename-clicked + (fn [] + (st/emit! (modal/show :team-form {:team team}))) on-leave-clicked (st/emitf (modal/show @@ -324,7 +337,7 @@ {:type ::leave-and-reassign :profile profile :team team - :accept leave-and-reassign-fn}))) + :accept leave-fn}))) on-delete-clicked (st/emitf diff --git a/frontend/src/app/main/ui/static.cljs b/frontend/src/app/main/ui/static.cljs index fc1fe6e085..3ada96ac18 100644 --- a/frontend/src/app/main/ui/static.cljs +++ b/frontend/src/app/main/ui/static.cljs @@ -23,7 +23,7 @@ (fn [] (let [profile (deref refs/profile)] (if (du/is-authenticated? profile) - (let [team-id (du/get-current-team-id profile)] + (let [team-id (:default-team-id profile)] (st/emit! (rt/nav :dashboard-projects {:team-id team-id}))) (st/emit! (rt/nav :auth-login {}))))))] diff --git a/frontend/translations/en.po b/frontend/translations/en.po index b0f876821c..3c5db28bfc 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -3245,4 +3245,13 @@ msgid "workspace.updates.update" msgstr "Update" msgid "workspace.viewport.click-to-close-path" -msgstr "Click to close the path" \ No newline at end of file +msgstr "Click to close the path" + +msgid "errors.team-leave.member-does-not-exists" +msgstr "The member you try to assign does not exist." + +msgid "errors.team-leave.owner-cant-leave" +msgstr "Owner can't leave team, you must reassign the owner role." + +msgid "errors.team-leave.insufficient-members" +msgstr "Insufficient members to leave team, you probably want to delete it."