diff --git a/lib/CF/Controller/Announcements.pm b/lib/CF/Controller/Announcements.pm index 7ae3cf469fe43dda5c18e2932a33f8cafe1159b6..f63227d4bef30e01e57617b154d557a8c76f1fb4 100644 --- a/lib/CF/Controller/Announcements.pm +++ b/lib/CF/Controller/Announcements.pm @@ -22,10 +22,9 @@ sub create ($c) { id => $announcement->id, }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'announcement_created', - payload => $announcement->format(), - }); + $c->notify('announcement_created', + $announcement->format(), + ); $c->render( status => 201, @@ -70,13 +69,12 @@ sub update ($c) { $entry->update( $update ); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'announcement_changed', - payload => { + $c->notify('announcement_changed', + { id => $entry->id, %{ $update }, } - }); + ); $guard->commit; @@ -93,12 +91,9 @@ sub delete ($c) { $entry->update( { deleted => \'now()'} ); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'announcement_deleted', - payload => { - id => $entry->id, - } - }); + $c->notify('announcement_deleted', + { id => $entry->id } + ); $guard->commit; diff --git a/lib/CF/Controller/Config.pm b/lib/CF/Controller/Config.pm index 8702d55d881a2ead1d870a4724795decf9033544..3117c78af46de220d6b4918e947e03d79987b600 100644 --- a/lib/CF/Controller/Config.pm +++ b/lib/CF/Controller/Config.pm @@ -34,13 +34,12 @@ sub update ($c) { $entry->update( $update ); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'config_entry_changed', - payload => { + $c->notify('config_entry_changed', + { id => $entry->id, %{ $update }, } - }); + ); $guard->commit; diff --git a/lib/CF/Controller/Posts.pm b/lib/CF/Controller/Posts.pm index 8a7130bfe5daa9f620ea9e6d0f4ee1806194f7ab..4e41fdfb80470eabe9a549ecf25da1166b84d2bf 100644 --- a/lib/CF/Controller/Posts.pm +++ b/lib/CF/Controller/Posts.pm @@ -58,10 +58,9 @@ sub create ($c) { content => $args->{content}, }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'post_created', - payload => $post->view->format(), - }); + $c->notify('post_created', + $post->view->format(), + ); $c->render( status => 201, @@ -224,10 +223,9 @@ sub update ($c) { id => $announcement->id }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'announcement_created', - payload => $announcement->format(), - }); + $c->>notify('announcement_created', + $announcement->format(), + ); } } @@ -242,13 +240,12 @@ sub update ($c) { changed => \'now()', }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'post_changed', - payload => { + $c->notify('post_changed', + { id => $post->id, %{ $update }, } - }); + ); $guard->commit; $c->render(status => 204, text => ''); @@ -264,12 +261,9 @@ sub delete ($c) { $post->update({ deleted => \'now()', }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'post_deleted', - payload => { - id => $post->id, - } - }); + $c->notify('post_deleted', + { id => $post->id } + ); $guard->commit; $c->render(status => 204, text => ''); @@ -332,13 +326,12 @@ sub ranking ($c) { }); } - $c->redis->pubsub->json('notify')->notify(notify => { - event => 'post_ranked', - payload => { + $c->notify('post_ranked', + { id => $post->id, %{ $update }, } - }); + ); $guard->commit; $c->render(status => 204, text => ''); diff --git a/lib/CF/Controller/Program.pm b/lib/CF/Controller/Program.pm index 5b8744b54ed7f6155174c4407f10094d6e4f90d7..d1b0e6699648a7f3e7bdc04dbecd6e9df7ad4fe7 100644 --- a/lib/CF/Controller/Program.pm +++ b/lib/CF/Controller/Program.pm @@ -46,13 +46,12 @@ sub update ($c) { $entry->update( $update ); - $c->redis->pubsub->json("notify")->notify(notify => { - event => 'program_entry_changed', - payload => { + $c->notify('program_entry_changed', + { id => $entry->id, %{ $update }, } - }); + ); $guard->commit; diff --git a/lib/CF/Controller/Users.pm b/lib/CF/Controller/Users.pm index 914eb0bbf63d6861e4c99c3ebfc55d9da0956625..3bf89f95413cf61c7884a21ef5e4a1e7c01f2efb 100644 --- a/lib/CF/Controller/Users.pm +++ b/lib/CF/Controller/Users.pm @@ -49,15 +49,13 @@ sub ban ($c){ id => $announcement->id, }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'announcement_created', - payload => $announcement->format(), + $c->notify('announcement_created', + $announcement->format(), }); - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'user_banned', - payload => $c->spec_filter($user->formatted, 'User'), - }); + $c->notify('user_banned', + $c->spec_filter($user->formatted, 'User'), + ); $guard->commit; $c->render(status => 204, text => ''); @@ -70,10 +68,9 @@ sub unban ($c){ $user->update({ banned_until => undef }); #TODO: ANN - $c->redis->pubsub->json('notify')->notify( notify => { - event => 'user_unbanned', - payload => $c->spec_filter($user->formatted, 'User'), - }); + $c->notify('user_unbanned', + $c->spec_filter($user->formatted, 'User'), + ); $guard->commit; $c->render(status => 204, text => ''); diff --git a/lib/CF/Helpers/Core.pm b/lib/CF/Helpers/Core.pm index 1251a2ba30429af1e00146f75292b54dc894f820..6a7dc73a114d291f0090c18a7037fb1ce0e52c81 100644 --- a/lib/CF/Helpers/Core.pm +++ b/lib/CF/Helpers/Core.pm @@ -6,6 +6,7 @@ no warnings qw{ experimental::signatures } ; use YAML; use Mojo::JWT; +use Mojo::JSON qw(encode_json); sub register ($class, $self, $conf) { @@ -199,6 +200,16 @@ sub register ($class, $self, $conf) { ); }); + + $self->helper( notify => sub ( $c, $event, $payload ) { + + my $content = encode_json ({ + event => $event, + payload => $payload, + }); + + $self->redis->pubsub->notify( notify => $content ); + } } 1; diff --git a/openapi.yaml b/openapi.yaml index 420a451fc056e2024bc470eb4e038bfa1f5b172e..abc2f274891bbbfe4aacb5fdb34b42ed94b1a355 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -540,7 +540,7 @@ paths: post: x-mojo-to: events#role_add security: - - Bearer: ['*'] + - Bearer: ['organizer'] tags: - events summary: "Priradit roli pro udalost" @@ -563,20 +563,23 @@ paths: type: string enum: ['user', 'group'] example: 'user' - subject: + subject_value: type: string example: 'cen:f' + subject_label: + type: string + example: 'Celostátní fórum' role: type: string enum: ['chairman', 'member', 'guest', 'jitsi'] example: 'member' required: - subject_class - - subject + - subject_value - role responses: 201: - description: Role set + description: ACL record created content: application/json: schema: