Skip to content
Snippets Groups Projects
Verified Commit 2a64702d authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Presun notifikace do helperu

parent 976f22c3
No related branches found
No related tags found
No related merge requests found
Pipeline #6577 passed
...@@ -22,10 +22,9 @@ sub create ($c) { ...@@ -22,10 +22,9 @@ sub create ($c) {
id => $announcement->id, id => $announcement->id,
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('announcement_created',
event => 'announcement_created', $announcement->format(),
payload => $announcement->format(), );
});
$c->render( $c->render(
status => 201, status => 201,
...@@ -70,13 +69,12 @@ sub update ($c) { ...@@ -70,13 +69,12 @@ sub update ($c) {
$entry->update( $update ); $entry->update( $update );
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('announcement_changed',
event => 'announcement_changed', {
payload => {
id => $entry->id, id => $entry->id,
%{ $update }, %{ $update },
} }
}); );
$guard->commit; $guard->commit;
...@@ -93,12 +91,9 @@ sub delete ($c) { ...@@ -93,12 +91,9 @@ sub delete ($c) {
$entry->update( { deleted => \'now()'} ); $entry->update( { deleted => \'now()'} );
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('announcement_deleted',
event => 'announcement_deleted', { id => $entry->id }
payload => { );
id => $entry->id,
}
});
$guard->commit; $guard->commit;
......
...@@ -34,13 +34,12 @@ sub update ($c) { ...@@ -34,13 +34,12 @@ sub update ($c) {
$entry->update( $update ); $entry->update( $update );
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('config_entry_changed',
event => 'config_entry_changed', {
payload => {
id => $entry->id, id => $entry->id,
%{ $update }, %{ $update },
} }
}); );
$guard->commit; $guard->commit;
......
...@@ -58,10 +58,9 @@ sub create ($c) { ...@@ -58,10 +58,9 @@ sub create ($c) {
content => $args->{content}, content => $args->{content},
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('post_created',
event => 'post_created', $post->view->format(),
payload => $post->view->format(), );
});
$c->render( $c->render(
status => 201, status => 201,
...@@ -224,10 +223,9 @@ sub update ($c) { ...@@ -224,10 +223,9 @@ sub update ($c) {
id => $announcement->id id => $announcement->id
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->>notify('announcement_created',
event => 'announcement_created', $announcement->format(),
payload => $announcement->format(), );
});
} }
} }
...@@ -242,13 +240,12 @@ sub update ($c) { ...@@ -242,13 +240,12 @@ sub update ($c) {
changed => \'now()', changed => \'now()',
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('post_changed',
event => 'post_changed', {
payload => {
id => $post->id, id => $post->id,
%{ $update }, %{ $update },
} }
}); );
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
...@@ -264,12 +261,9 @@ sub delete ($c) { ...@@ -264,12 +261,9 @@ sub delete ($c) {
$post->update({ deleted => \'now()', }); $post->update({ deleted => \'now()', });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('post_deleted',
event => 'post_deleted', { id => $post->id }
payload => { );
id => $post->id,
}
});
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
...@@ -332,13 +326,12 @@ sub ranking ($c) { ...@@ -332,13 +326,12 @@ sub ranking ($c) {
}); });
} }
$c->redis->pubsub->json('notify')->notify(notify => { $c->notify('post_ranked',
event => 'post_ranked', {
payload => {
id => $post->id, id => $post->id,
%{ $update }, %{ $update },
} }
}); );
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
......
...@@ -46,13 +46,12 @@ sub update ($c) { ...@@ -46,13 +46,12 @@ sub update ($c) {
$entry->update( $update ); $entry->update( $update );
$c->redis->pubsub->json("notify")->notify(notify => { $c->notify('program_entry_changed',
event => 'program_entry_changed', {
payload => {
id => $entry->id, id => $entry->id,
%{ $update }, %{ $update },
} }
}); );
$guard->commit; $guard->commit;
......
...@@ -49,15 +49,13 @@ sub ban ($c){ ...@@ -49,15 +49,13 @@ sub ban ($c){
id => $announcement->id, id => $announcement->id,
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('announcement_created',
event => 'announcement_created', $announcement->format(),
payload => $announcement->format(),
}); });
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('user_banned',
event => 'user_banned', $c->spec_filter($user->formatted, 'User'),
payload => $c->spec_filter($user->formatted, 'User'), );
});
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
...@@ -70,10 +68,9 @@ sub unban ($c){ ...@@ -70,10 +68,9 @@ sub unban ($c){
$user->update({ banned_until => undef }); $user->update({ banned_until => undef });
#TODO: ANN #TODO: ANN
$c->redis->pubsub->json('notify')->notify( notify => { $c->notify('user_unbanned',
event => 'user_unbanned', $c->spec_filter($user->formatted, 'User'),
payload => $c->spec_filter($user->formatted, 'User'), );
});
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
......
...@@ -6,6 +6,7 @@ no warnings qw{ experimental::signatures } ; ...@@ -6,6 +6,7 @@ no warnings qw{ experimental::signatures } ;
use YAML; use YAML;
use Mojo::JWT; use Mojo::JWT;
use Mojo::JSON qw(encode_json);
sub register ($class, $self, $conf) { sub register ($class, $self, $conf) {
...@@ -199,6 +200,16 @@ 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; 1;
......
...@@ -540,7 +540,7 @@ paths: ...@@ -540,7 +540,7 @@ paths:
post: post:
x-mojo-to: events#role_add x-mojo-to: events#role_add
security: security:
- Bearer: ['*'] - Bearer: ['organizer']
tags: tags:
- events - events
summary: "Priradit roli pro udalost" summary: "Priradit roli pro udalost"
...@@ -563,20 +563,23 @@ paths: ...@@ -563,20 +563,23 @@ paths:
type: string type: string
enum: ['user', 'group'] enum: ['user', 'group']
example: 'user' example: 'user'
subject: subject_value:
type: string type: string
example: 'cen:f' example: 'cen:f'
subject_label:
type: string
example: 'Celostátní fórum'
role: role:
type: string type: string
enum: ['chairman', 'member', 'guest', 'jitsi'] enum: ['chairman', 'member', 'guest', 'jitsi']
example: 'member' example: 'member'
required: required:
- subject_class - subject_class
- subject - subject_value
- role - role
responses: responses:
201: 201:
description: Role set description: ACL record created
content: content:
application/json: application/json:
schema: schema:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment