cef8610925
* feat: add enabled column to UserFeatures and TeamFeatures for tri-state semantics - Add enabled Boolean column to UserFeatures model with default true - Add enabled Boolean column to TeamFeatures model with default true - Update FeaturesRepository to use tri-state semantics: - enabled=true: feature is explicitly enabled - enabled=false: feature is explicitly disabled (blocks inheritance) - No row: inherit from team/org level - Update SQL queries to check enabled=true for feature access - Add enableFeatureForTeam method to interface and implementation Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * update comments * add integration tests * add more test * select enabled only * no @default(true) * fix types and tests * add missing enabled * add missing enabled * rename enableFeatureForTeam to updateFeatureForTeam and support FeatureState * refactor: rename updateFeatureForTeam to setTeamFeatureState Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix integration test * fix tests * add more tests * add missing enabled --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
26 lines
971 B
SQL
26 lines
971 B
SQL
SELECT
|
|
TO_TIMESTAMP(sc."googleChannelExpiration"::bigint / 1000 - 86400)::date as "humanReadableExpireDate",
|
|
sc.*
|
|
FROM
|
|
"SelectedCalendar" sc
|
|
LEFT JOIN "users" AS u ON u.id = sc. "userId"
|
|
LEFT JOIN "Membership" AS m ON m. "userId" = u.id
|
|
LEFT JOIN "Team" AS t ON t.id = m."teamId"
|
|
LEFT JOIN "TeamFeatures" AS tf ON tf. "teamId" = t.id
|
|
WHERE
|
|
-- Only get calendars for teams where cache is enabled
|
|
tf."featureId" = 'calendar-cache'
|
|
AND tf.enabled = true
|
|
-- We currently only support google watchers
|
|
AND sc."integration" = 'google_calendar'
|
|
AND (
|
|
-- Either is a calendar pending to be watched
|
|
sc."googleChannelExpiration" IS NULL
|
|
OR (
|
|
-- Or is a calendar that is about to expire
|
|
sc."googleChannelExpiration" IS NOT NULL
|
|
-- We substract one day in seconds to renew a day before expiration
|
|
AND TO_TIMESTAMP(sc."googleChannelExpiration"::bigint / 1000 - 86400)::date < CURRENT_TIMESTAMP
|
|
)
|
|
);
|