diff --git a/backend/src/app/rpc/management/nitrate.clj b/backend/src/app/rpc/management/nitrate.clj index 42e0e10375..23a8dcaa37 100644 --- a/backend/src/app/rpc/management/nitrate.clj +++ b/backend/src/app/rpc/management/nitrate.clj @@ -9,7 +9,7 @@ organization management and token validation endpoints." (:require [app.common.schema :as sm] - [app.common.types.profile :refer [schema:profile]] + [app.common.types.profile :refer [schema:profile, schema:basic-profile]] [app.common.types.team :refer [schema:team]] [app.common.uuid :as uuid] [app.db :as db] @@ -80,3 +80,35 @@ :team-id id :organization-id organization-id :organization-name organization-name}))) + + +;; ---- API: get-managed-profiles + +(def ^:private sql:get-managed-profiles + "SELECT DISTINCT p.id, p.fullname as name, p.email + FROM profile p + JOIN team_profile_rel tpr_member + ON tpr_member.profile_id = p.id + WHERE p.id <> ? + AND EXISTS ( + SELECT 1 + FROM team_profile_rel tpr_owner + JOIN team t + ON t.id = tpr_owner.team_id + WHERE tpr_owner.profile_id = ? + AND tpr_owner.team_id = tpr_member.team_id + AND tpr_owner.is_owner IS TRUE + AND t.is_default IS FALSE + AND t.deleted_at IS NULL);") + +(def schema:managed-profile-result + [:vector schema:basic-profile]) + +(sv/defmethod ::get-managed-profiles + "List profiles that belong to teams for which current user is owner" + {::doc/added "2.14" + ::sm/params [:map] + ::sm/result schema:managed-profile-result} + [cfg {:keys [::rpc/profile-id]}] + (let [current-user-id (-> (profile/get-profile cfg profile-id) :id)] + (db/exec! cfg [sql:get-managed-profiles current-user-id current-user-id]))) diff --git a/common/src/app/common/types/profile.cljc b/common/src/app/common/types/profile.cljc index 24272cab67..c0c0834611 100644 --- a/common/src/app/common/types/profile.cljc +++ b/common/src/app/common/types/profile.cljc @@ -21,3 +21,10 @@ ;; Only present on resolved profile objects, the resolve process ;; takes the photo-id or geneates an image from the name [:photo-url {:optional true} :string]]) + + +(def schema:basic-profile + [:map {:title "Basic profile"} + [:id ::sm/uuid] + [:name {:optional true} :string] + [:email {:optional true} :string]])