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) {
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;
......
......@@ -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;
......
......@@ -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 => '');
......
......@@ -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;
......
......@@ -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 => '');
......
......@@ -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;
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment