mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
✨ Add the ability to known the subscription status on teams list
This commit is contained in:
parent
18c7890f65
commit
38728eb342
1 changed files with 42 additions and 12 deletions
|
@ -126,16 +126,38 @@
|
||||||
(get-teams conn profile-id)))
|
(get-teams conn profile-id)))
|
||||||
|
|
||||||
(def sql:get-teams-with-permissions
|
(def sql:get-teams-with-permissions
|
||||||
"select t.*,
|
"SELECT t.*,
|
||||||
tp.is_owner,
|
tp.is_owner,
|
||||||
tp.is_admin,
|
tp.is_admin,
|
||||||
tp.can_edit,
|
tp.can_edit,
|
||||||
(t.id = ?) as is_default
|
(t.id = ?) AS is_default
|
||||||
from team_profile_rel as tp
|
FROM team_profile_rel AS tp
|
||||||
join team as t on (t.id = tp.team_id)
|
JOIN team AS t ON (t.id = tp.team_id)
|
||||||
where t.deleted_at is null
|
WHERE t.deleted_at IS null
|
||||||
and tp.profile_id = ?
|
AND tp.profile_id = ?
|
||||||
order by tp.created_at asc")
|
ORDER BY tp.created_at ASC")
|
||||||
|
|
||||||
|
(def sql:get-teams-with-permissions-and-subscription
|
||||||
|
"SELECT t.*,
|
||||||
|
tp.is_owner,
|
||||||
|
tp.is_admin,
|
||||||
|
tp.can_edit,
|
||||||
|
(t.id = ?) AS is_default,
|
||||||
|
CASE COALESCE(p.props->'~:subscription'->>'~:status', 'unknown')
|
||||||
|
WHEN 'unknown' THEN false
|
||||||
|
WHEN 'canceled' THEN false
|
||||||
|
WHEN 'unpaid' THEN false
|
||||||
|
ELSE true
|
||||||
|
END AS is_subscription_active
|
||||||
|
FROM team_profile_rel AS tp
|
||||||
|
JOIN team AS t ON (t.id = tp.team_id)
|
||||||
|
JOIN team_profile_rel AS tpr
|
||||||
|
ON (tpr.team_id = t.id AND tpr.is_owner IS true)
|
||||||
|
JOIN profile AS p
|
||||||
|
ON (tpr.profile_id = p.id)
|
||||||
|
WHERE t.deleted_at IS null
|
||||||
|
AND tp.profile_id = ?
|
||||||
|
ORDER BY tp.created_at ASC;")
|
||||||
|
|
||||||
(defn process-permissions
|
(defn process-permissions
|
||||||
[team]
|
[team]
|
||||||
|
@ -150,13 +172,21 @@
|
||||||
(dissoc :is-owner :is-admin :can-edit)
|
(dissoc :is-owner :is-admin :can-edit)
|
||||||
(assoc :permissions permissions))))
|
(assoc :permissions permissions))))
|
||||||
|
|
||||||
|
(def ^:private
|
||||||
|
xform:process-teams
|
||||||
|
(comp
|
||||||
|
(map decode-row)
|
||||||
|
(map process-permissions)))
|
||||||
|
|
||||||
(defn get-teams
|
(defn get-teams
|
||||||
[conn profile-id]
|
[conn profile-id]
|
||||||
(let [profile (profile/get-profile conn profile-id)]
|
(let [profile (profile/get-profile conn profile-id)
|
||||||
(->> (db/exec! conn [sql:get-teams-with-permissions (:default-team-id profile) profile-id])
|
sql (if (contains? cf/flags :subscriptions)
|
||||||
(map decode-row)
|
sql:get-teams-with-permissions-and-subscription
|
||||||
(map process-permissions)
|
sql:get-teams-with-permissions)]
|
||||||
(vec))))
|
|
||||||
|
(->> (db/exec! conn [sql (:default-team-id profile) profile-id])
|
||||||
|
(into [] xform:process-teams))))
|
||||||
|
|
||||||
;; --- Query: Team (by ID)
|
;; --- Query: Team (by ID)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue