forked from cyrusimap/cyrus-imapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jmap_notif: automatically prune calendar event notifications
Mark all JMAP CalendarEventNotification objects but the last 200 items as expunged, each time a new one is created. The maximum count can be set in the jmap_max_calendareventnotifs config option. Signed-off-by: Robert Stepanek <[email protected]>
- Loading branch information
Showing
5 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
cassandane/tiny-tests/JMAPCalendars/calendareventnotification-prune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!perl | ||
use Cassandane::Tiny; | ||
|
||
sub test_calendareventnotification_prune | ||
:min_version_3_9 :needs_component_jmap :JmapMaxCalendarEventNotifs | ||
{ | ||
my ($self) = @_; | ||
my $jmap = $self->{jmap}; | ||
|
||
my $jmap_max_calendareventnotifs = $self->{instance}->{ | ||
config}->get('jmap_max_calendareventnotifs'); | ||
$self->assert_not_null($jmap_max_calendareventnotifs); | ||
|
||
my ($manJmap) = $self->create_user('manifold'); | ||
$manJmap->DefaultUsing([ | ||
'urn:ietf:params:jmap:core', | ||
'urn:ietf:params:jmap:calendars', | ||
'urn:ietf:params:jmap:principals', | ||
'https://cyrusimap.org/ns/jmap/calendars', | ||
]); | ||
|
||
xlog $self, "Share calendar"; | ||
my $res = $jmap->CallMethods([ | ||
['Calendar/set', { | ||
update => { | ||
Default => { | ||
shareWith => { | ||
manifold => { | ||
mayReadFreeBusy => JSON::true, | ||
mayReadItems => JSON::true, | ||
mayUpdatePrivate => JSON::true, | ||
mayWriteOwn => JSON::true, | ||
mayAdmin => JSON::false | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, 'R1'], | ||
]); | ||
$self->assert(exists $res->[0][1]{updated}{Default}); | ||
|
||
xlog $self, "Create event notification"; | ||
my $res = $jmap->CallMethods([ | ||
['CalendarEvent/set', { | ||
create => { | ||
event1 => { | ||
title => 'event1', | ||
calendarIds => { | ||
Default => JSON::true, | ||
}, | ||
start => '2011-01-01T04:05:06', | ||
duration => 'PT1H', | ||
}, | ||
}, | ||
}, 'R1'], | ||
]); | ||
$self->assert_not_null($res->[0][1]{created}{event1}); | ||
|
||
xlog $self, "Get event notification"; | ||
$res = $manJmap->CallMethods([ | ||
['CalendarEventNotification/get', { | ||
accountId => 'cassandane', | ||
}, 'R1'], | ||
]); | ||
$self->assert_num_equals(1, scalar @{$res->[0][1]{list}}); | ||
my $notif1Id = $res->[0][1]{list}[0]{id}; | ||
$self->assert_not_null($notif1Id); | ||
|
||
xlog $self, "Create maximum count of allowed notifications"; | ||
for my $i (2 .. $jmap_max_calendareventnotifs) { | ||
my $res = $jmap->CallMethods([ | ||
['CalendarEvent/set', { | ||
create => { | ||
"event$i" => { | ||
title => "event$i", | ||
calendarIds => { | ||
Default => JSON::true, | ||
}, | ||
start => '2011-01-01T04:05:06', | ||
duration => 'PT1H', | ||
}, | ||
}, | ||
}, 'R1'], | ||
]); | ||
$self->assert_not_null($res->[0][1]{created}{"event$i"}); | ||
} | ||
|
||
xlog $self, "Get event notifications"; | ||
$res = $manJmap->CallMethods([ | ||
['CalendarEventNotification/get', { | ||
accountId => 'cassandane', | ||
properties => ['id'], | ||
}, 'R1'], | ||
]); | ||
$self->assert_num_equals($jmap_max_calendareventnotifs, scalar @{$res->[0][1]{list}}); | ||
|
||
xlog $self, "Assert first event notification exists"; | ||
$self->assert_equals(1, scalar grep { $_->{id} eq $notif1Id } @{$res->[0][1]{list}}); | ||
|
||
xlog $self, "Create one more event notification"; | ||
my $res = $jmap->CallMethods([ | ||
['CalendarEvent/set', { | ||
create => { | ||
eventX => { | ||
title => 'eventX', | ||
calendarIds => { | ||
Default => JSON::true, | ||
}, | ||
start => '2011-01-01T04:05:06', | ||
duration => 'PT1H', | ||
}, | ||
}, | ||
}, 'R1'], | ||
]); | ||
$self->assert_not_null($res->[0][1]{created}{eventX}); | ||
|
||
xlog $self, "Get event notifications"; | ||
$res = $manJmap->CallMethods([ | ||
['CalendarEventNotification/get', { | ||
accountId => 'cassandane', | ||
properties => ['id'], | ||
}, 'R1'], | ||
]); | ||
$self->assert_num_equals($jmap_max_calendareventnotifs, scalar @{$res->[0][1]{list}}); | ||
|
||
xlog $self, "Assert first event notification does not exist"; | ||
$self->assert_equals(0, scalar grep { $_->{id} eq $notif1Id } @{$res->[0][1]{list}}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Description: | ||
|
||
Prune JMAP CalendarEventNotification objects each time a new one is created. | ||
|
||
|
||
Config changes: | ||
|
||
jmap_max_calendareventnotifs | ||
|
||
|
||
Upgrade instructions: | ||
|
||
The default maximum count of CalendarEventNotifications is set to 200 | ||
per account. Installations that need any other count or want to not | ||
prune notifications must update the jmap_max_calendareventnotifs config. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters