Skip to content

Commit

Permalink
Merge pull request cyrusimap#4742 from cyrusimap/prune_calendareventn…
Browse files Browse the repository at this point in the history
…otifs

Remove jmap_expire and automatically prune calendareventnotifs
  • Loading branch information
rsto authored Dec 15, 2023
2 parents 37b803e + 0fd56ad commit 07d6e26
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 631 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ imap/imapd
imap/ipurge
imap/jmap_err.c
imap/jmap_err.h
imap/jmap_expire
imap/lmtp_err.c
imap/lmtp_err.h
imap/lmtpd
Expand Down
7 changes: 0 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ endif # SERVER

endif # SIEVE

if JMAP
sbin_PROGRAMS += imap/jmap_expire
endif # JMAP

EXTRA_DIST = \
COPYING \
README.md \
Expand Down Expand Up @@ -965,9 +961,6 @@ imap_idled_LDADD = $(LD_UTILITY_ADD)
imap_calalarmd_SOURCES = imap/calalarmd.c imap/mutex_fake.c
imap_calalarmd_LDADD = $(LD_SERVER_ADD)

imap_jmap_expire_SOURCES = imap/cli_fatal.c imap/jmap_expire.c imap/mutex_fake.c
imap_jmap_expire_LDADD = $(LD_UTILITY_ADD)

imap_imapd_SOURCES = \
imap/imap_proxy.c \
imap/imap_proxy.h \
Expand Down
5 changes: 5 additions & 0 deletions cassandane/Cassandane/Cyrus/TestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ magic(NoCheckSyslog => sub {
my $self = shift;
$self->{no_check_syslog} = 1;
});
magic(JmapMaxCalendarEventNotifs => sub {
my $conf = shift;
# set to some small number
$conf->config_set('jmap_max_calendareventnotifs' => 10);
});

# Run any magic handlers indicated by the test name or attributes
sub _run_magic
Expand Down
128 changes: 128 additions & 0 deletions cassandane/tiny-tests/JMAPCalendars/calendareventnotification-prune
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}});
}
16 changes: 0 additions & 16 deletions changes/next/cyr_expire_jmap

This file was deleted.

15 changes: 15 additions & 0 deletions changes/next/prune_calendareventnotifs
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.
5 changes: 0 additions & 5 deletions doc/examples/cyrus_conf/normal-master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ EVENTS {

# this is only necessary if caching TLS sessions
tlsprune cmd="tls_prune" at=0400

# this is only necessary if CalDAV or JMAP are enabled
# expire JMAP notifications after 7 days and
# unlink expired JMAP notifications after 1 day
jmapprune cmd="jmap_expire -E 7d -X 1d" at 0500
}

DAEMON {
Expand Down
5 changes: 0 additions & 5 deletions doc/examples/cyrus_conf/normal-replica.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ EVENTS {

# this is only necessary if caching TLS sessions
tlsprune cmd="tls_prune" at=0400

# this is only necessary if CalDAV or JMAP are enabled
# expire JMAP notifications after 7 days and
# unlink expired JMAP notifications after 1 day
jmapprune cmd="jmap_expire -E 7d -X 1d" at 0500
}

DAEMON {
Expand Down
5 changes: 0 additions & 5 deletions doc/examples/cyrus_conf/normal.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ EVENTS {

# this is only necessary if caching TLS sessions
tlsprune cmd="tls_prune" at=0400

# this is only necessary if CalDAV or JMAP are enabled
# expire JMAP notifications after 7 days and
# unlink expired JMAP notifications after 1 day
jmapprune cmd="jmap_expire -E 7d -X 1d" at 0500
}

DAEMON {
Expand Down
5 changes: 0 additions & 5 deletions doc/examples/cyrus_conf/small.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ EVENTS {

# this is only necessary if caching TLS sessions
tlsprune cmd="tls_prune" at=0400

# this is only necessary if CalDAV or JMAP are enabled
# expire JMAP notifications after 7 days and
# unlink expired JMAP notifications after 1 day
jmapprune cmd="jmap_expire -E 7d -X 1d" at 0500
}

DAEMON {
Expand Down
138 changes: 0 additions & 138 deletions docsrc/imap/reference/manpages/systemcommands/jmap_expire.rst

This file was deleted.

Loading

0 comments on commit 07d6e26

Please sign in to comment.