Skip to content

Commit

Permalink
Allow disabling all repositories notifications (#3612)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
  • Loading branch information
tegioz authored Jan 15, 2024
1 parent a569d6f commit e264036
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
-- provided for the given event kind. At the moment, the user owning a given
-- repository or all the users who belong to the organization which owns the
-- repository are considered to be subscribed to the repository, unless they
-- have opted out of notifications for that repository and event.
-- have opted out of notifications for that repository and event or they've
-- fully disabled the repositories notifications.
create or replace function get_repository_subscriptors(p_repository_id uuid, p_event_kind_id int)
returns setof json as $$
select coalesce(json_agg(json_build_object(
Expand All @@ -27,5 +28,9 @@ returns setof json as $$
from opt_out
where repository_id = p_repository_id
and event_kind_id = p_event_kind_id
union
select user_id
from "user"
where repositories_notifications_disabled = true
);
$$ language sql;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
alter table "user" add column repositories_notifications_disabled boolean;
create index if not exists user_repositories_notifications_disabled_idx
on "user" (user_id)
where repositories_notifications_disabled = true;

---- create above / drop below ----

drop index if exists user_repositories_notifications_disabled_idx;
alter table "user" drop column repositories_notifications_disabled;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ select plan(2);
\set user3ID '00000000-0000-0000-0000-000000000003'
\set user4ID '00000000-0000-0000-0000-000000000004'
\set user5ID '00000000-0000-0000-0000-000000000005'
\set user6ID '00000000-0000-0000-0000-000000000006'
\set org1ID '00000000-0000-0000-0000-000000000001'
\set repo1ID '00000000-0000-0000-0000-000000000001'
\set repo2ID '00000000-0000-0000-0000-000000000002'
Expand All @@ -23,12 +24,15 @@ insert into "user" (user_id, alias, email)
values (:'user4ID', 'user4', 'user4@email.com');
insert into "user" (user_id, alias, email)
values (:'user5ID', 'user5', 'user5@email.com');
insert into "user" (user_id, alias, email, repositories_notifications_disabled)
values (:'user6ID', 'user6', 'user6@email.com', true);
insert into organization (organization_id, name, display_name, description, home_url)
values (:'org1ID', 'org1', 'Organization 1', 'Description 1', 'https://org1.com');
insert into user__organization (user_id, organization_id, confirmed) values(:'user2ID', :'org1ID', true);
insert into user__organization (user_id, organization_id, confirmed) values(:'user3ID', :'org1ID', true);
insert into user__organization (user_id, organization_id, confirmed) values(:'user4ID', :'org1ID', false);
insert into user__organization (user_id, organization_id, confirmed) values(:'user5ID', :'org1ID', true);
insert into user__organization (user_id, organization_id, confirmed) values(:'user6ID', :'org1ID', true);
insert into repository (repository_id, name, display_name, url, repository_kind_id, user_id)
values (:'repo1ID', 'repo1', 'Repo 1', 'https://repo1.com', 0, :'user1ID');
insert into repository (repository_id, name, display_name, url, repository_kind_id, organization_id)
Expand Down
6 changes: 4 additions & 2 deletions database/tests/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ select columns_are('user', array[
'created_at',
'tfa_enabled',
'tfa_recovery_codes',
'tfa_url'
'tfa_url',
'repositories_notifications_disabled'
]);
select columns_are('user_starred_package', array[
'user_id',
Expand Down Expand Up @@ -390,7 +391,8 @@ select indexes_are('subscription', array[
select indexes_are('user', array[
'user_pkey',
'user_alias_key',
'user_email_key'
'user_email_key',
'user_repositories_notifications_disabled_idx'
]);
select indexes_are('user__organization', array[
'user__organization_pkey'
Expand Down

0 comments on commit e264036

Please sign in to comment.