diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73ec42baa58d275f02df97c2a21032b146fa3e9b..d203b60c2143d1e43163ddc9391e0903f4578b03 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:20.10.9 variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 2.4.1 + IMAGE_VER: 2.4.2 services: - docker:20.10.9-dind diff --git a/lib/CF/Controller/Announcements.pm b/lib/CF/Controller/Announcements.pm index b4b16688bbd90a7ee8a714e1e17cd16467590c5d..7ae3cf469fe43dda5c18e2932a33f8cafe1159b6 100644 --- a/lib/CF/Controller/Announcements.pm +++ b/lib/CF/Controller/Announcements.pm @@ -9,7 +9,6 @@ sub create ($c) { $c->openapi->valid_input or return; my $args = $c->req->json; - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $announcement = $c->schema->resultset('Announcement')->create({ user_id => $c->user->{id}, @@ -23,7 +22,7 @@ sub create ($c) { id => $announcement->id, }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'announcement_created', payload => $announcement->format(), }); @@ -67,12 +66,11 @@ sub update ($c) { return $c->error(404, 'Announcement entry not found') if ! $entry; my $update = $c->prepare_update_data( $entry, $c->req->json ); - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $entry->update( $update ); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'announcement_changed', payload => { id => $entry->id, @@ -91,12 +89,11 @@ sub delete ($c) { my $entry = $c->schema->resultset('Announcement')->find( $c->stash->{id} ); return $c->error(404, 'Announcement entry not found') if ! $entry; - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $entry->update( { deleted => \'now()'} ); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'announcement_deleted', payload => { id => $entry->id, diff --git a/lib/CF/Controller/Config.pm b/lib/CF/Controller/Config.pm index 108da6d37141b9ede0967c0fdf416b6045bdc0ee..8702d55d881a2ead1d870a4724795decf9033544 100644 --- a/lib/CF/Controller/Config.pm +++ b/lib/CF/Controller/Config.pm @@ -30,12 +30,11 @@ sub update ($c) { return $c->error(403, 'Config entry protected') if $entry->is_readonly; my $update = $c->prepare_update_data( $entry, $c->req->json ); - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $entry->update( $update ); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'config_entry_changed', payload => { id => $entry->id, diff --git a/lib/CF/Controller/Posts.pm b/lib/CF/Controller/Posts.pm index 6a890ee4ce4e81ab183dc4888b5d97802c5d746f..8a7130bfe5daa9f620ea9e6d0f4ee1806194f7ab 100644 --- a/lib/CF/Controller/Posts.pm +++ b/lib/CF/Controller/Posts.pm @@ -58,9 +58,7 @@ sub create ($c) { content => $args->{content}, }); - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); - - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'post_created', payload => $post->view->format(), }); @@ -202,7 +200,6 @@ sub update ($c) { } my $update = $c->prepare_update_data( $post, $c->req->json ); - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; if ( $update->{state} && $post->state != $update->{state} ) { @@ -227,7 +224,7 @@ sub update ($c) { id => $announcement->id }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'announcement_created', payload => $announcement->format(), }); @@ -245,7 +242,7 @@ sub update ($c) { changed => \'now()', }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'post_changed', payload => { id => $post->id, @@ -263,12 +260,11 @@ sub delete ($c) { my $post = $c->schema->resultset('Post')->find($c->stash->{id}); return $c->error(404, 'Post not found') if ! $post; - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $post->update({ deleted => \'now()', }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'post_deleted', payload => { id => $post->id, @@ -322,7 +318,6 @@ sub ranking ($c) { $update->{ranking_dislikes}++ if $args->{ranking} == -1; } - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $post->update( $update ); @@ -337,7 +332,7 @@ sub ranking ($c) { }); } - $pubsub->json('notify')->notify(notify => { + $c->redis->pubsub->json('notify')->notify(notify => { event => 'post_ranked', payload => { id => $post->id, diff --git a/lib/CF/Controller/Program.pm b/lib/CF/Controller/Program.pm index e0ff9e4bb7e188485d7d99cd21edfd40010ce0e6..5b8744b54ed7f6155174c4407f10094d6e4f90d7 100644 --- a/lib/CF/Controller/Program.pm +++ b/lib/CF/Controller/Program.pm @@ -34,8 +34,7 @@ sub update ($c) { return $c->error(404, 'Program entry not found') if ! $entry; my $update = $c->prepare_update_data( $entry, $c->req->json ); -# PG_PUBSUB -# my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); + my $guard = $c->schema->txn_scope_guard; # muze byt jen jeden aktualni bod programu @@ -47,21 +46,13 @@ sub update ($c) { $entry->update( $update ); - $c->redis->pubsub->notify( - program_entry_changed => { + $c->redis->pubsub->json("notify")->notify(notify => { + event => 'program_entry_changed', + payload => { id => $entry->id, %{ $update }, } - ); - -# PG_PUBSUB -# $pubsub->json('notify')->notify( notify => { -# event => 'program_entry_changed', -# payload => { -# id => $entry->id, -# %{ $update }, -# } -# }); + }); $guard->commit; diff --git a/lib/CF/Controller/Users.pm b/lib/CF/Controller/Users.pm index d181eda583a4e59ff189232b5bdf71342bd0b6eb..914eb0bbf63d6861e4c99c3ebfc55d9da0956625 100644 --- a/lib/CF/Controller/Users.pm +++ b/lib/CF/Controller/Users.pm @@ -29,7 +29,6 @@ sub me ($c){ sub ban ($c){ my $user = $c->_get( $c->stash->{id} ) // return; - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; $user->update({ banned_until => \"now()+'8 hour'", }); @@ -50,12 +49,12 @@ sub ban ($c){ id => $announcement->id, }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'announcement_created', payload => $announcement->format(), }); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'user_banned', payload => $c->spec_filter($user->formatted, 'User'), }); @@ -66,14 +65,12 @@ sub ban ($c){ sub unban ($c){ my $user = $c->_get( $c->stash->{id} ) // return; - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; - $user->update({ banned_until => undef }); #TODO: ANN - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'user_unbanned', payload => $c->spec_filter($user->formatted, 'User'), }); diff --git a/lib/CF/Controller/Websockets.pm b/lib/CF/Controller/Websockets.pm index 41746d2192ea575d7c5a7dafc63ac5c7c67aa920..1a5d4b1a9d811745308ff7bf3175598a9aab0a81 100644 --- a/lib/CF/Controller/Websockets.pm +++ b/lib/CF/Controller/Websockets.pm @@ -22,16 +22,11 @@ sub main { $c->res->headers->add('Sec-WebSocket-Extensions' => 'permessage-deflate'); } - $c->redis->pubsub->json('notify')->listen( + $c->redis->pubsub->listen( notify => sub($pubsub, $payload) { $c->send($payload); } ); -# PG_PUBSUB -# my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); -# $pubsub->listen(notify => sub($pubsub, $payload) { -# $c->send($payload); -# }); $c->on(json => sub( $c, $message ) { if ( $message->{event} eq 'KEEPALIVE' ) { @@ -103,8 +98,6 @@ sub main { }); $c->on(finish => sub ($c, $code, $reason = undef) { -# PG_PUBSUB -# $pubsub->unlisten('notify'); $c->redis->pubsub->unlisten('notify'); $c->app->log->debug("WebSocket closed with status $code"); }); diff --git a/sql/8/up.sql b/sql/8/up.sql index a7c438c65d19f8bfc6988c32bc87e99016b30bbc..1e28781e41dc916ce76a76a424abf928c6405b2f 100644 --- a/sql/8/up.sql +++ b/sql/8/up.sql @@ -18,15 +18,4 @@ create table "events" ( foreign key ("owner_id") references "users" ("id") on update cascade on delete restrict ); -create table "events_acl" ( - "id" integer not null default nextval('uid_seq'), - "event_id" integer not null, - "subject_class" varchar(8) not null, - "subject" text not null, - "role" text, - primary key("id"), - unique("event_id", "subject_class", "subject"), - foreign key ("event_id") references "events" ("id") on update cascade on delete cascade -); - alter table "program" add column "event_id" integer;