diff --git a/backend/src/app/rpc/commands/profile.clj b/backend/src/app/rpc/commands/profile.clj index 6449bef09c..d57d4b6523 100644 --- a/backend/src/app/rpc/commands/profile.clj +++ b/backend/src/app/rpc/commands/profile.clj @@ -471,6 +471,26 @@ (-> (rph/wrap nil) (rph/with-transform (session/delete-fn cfg))))) +(def sql:get-subscription-editors + "SELECT DISTINCT + p.id, + p.fullname AS name, + p.email AS email + FROM team_profile_rel AS tpr1 + JOIN team_profile_rel AS tpr2 + ON (tpr1.team_id = tpr2.team_id) + JOIN profile AS p + ON (tpr2.profile_id = p.id) + WHERE tpr1.profile_id = ? + AND tpr1.is_owner IS true + AND tpr2.can_edit IS true") + +(sv/defmethod ::get-subscription-usage + {::doc/added "2.9"} + [cfg {:keys [::rpc/profile-id]}] + (let [editors (db/exec! cfg [sql:get-subscription-editors profile-id])] + {:editors editors})) + ;; --- HELPERS (def sql:owned-teams diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index a099223b83..95fa381146 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -142,7 +142,18 @@ ELSE COALESCE(p.props->'~:subscription'->>'~:status', 'incomplete') END, '~:seats', p.props->'~:subscription'->'~:quantity' - ) AS subscription + ) AS subscription, + + (SELECT count(distinct p.id) + FROM team_profile_rel AS tpr1 + JOIN team_profile_rel AS tpr2 + ON (tpr1.team_id = tpr2.team_id) + JOIN profile AS p + ON (tpr2.profile_id = p.id) + WHERE tpr1.profile_id = p.id + AND tpr1.is_owner IS true + AND tpr2.can_edit IS true) AS unique_editors + FROM team_profile_rel AS tp JOIN team AS t ON (t.id = tp.team_id) JOIN team_profile_rel AS tpr