From 1edb2c9a220a40c38f8a9d0ecc85e4004fe1f086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Wed, 18 Jan 2023 22:16:51 +0100 Subject: [PATCH] Nedestruktivni mazani skupin pri syncronizaci, individualni opravneni uzivatele --- VERSION | 2 +- lib/SeMeet/Controller/Auth.pm | 9 ++++++++- lib/SeMeet/Controller/Groups.pm | 3 ++- lib/SeMeet/Schema/Result/Group.pm | 1 + lib/SeMeet/Schema/Result/User.pm | 7 +++++++ script/sync_octopus_groups | 4 +++- sql/migrations.sql | 6 ++++++ 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index a3df0a6..ac39a10 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.0 +0.9.0 diff --git a/lib/SeMeet/Controller/Auth.pm b/lib/SeMeet/Controller/Auth.pm index fa7f1d6..e0dbf87 100644 --- a/lib/SeMeet/Controller/Auth.pm +++ b/lib/SeMeet/Controller/Auth.pm @@ -31,8 +31,15 @@ sub callback ($c) { my @groups = (); my $permissions = {}; + foreach my $permission ( @{ $user->permissions || [] } ) { + $permissions->{$permission} = 1; + } + my $groups = $c->schema->resultset('Group')->search( - { octid => { '-in' => $octopus_user->{groups} }}, + { + deleted => undef, + octid => { '-in' => $octopus_user->{groups} }, + }, { columns => ['id', 'permissions'] } ); diff --git a/lib/SeMeet/Controller/Groups.pm b/lib/SeMeet/Controller/Groups.pm index a98755d..505b8e6 100644 --- a/lib/SeMeet/Controller/Groups.pm +++ b/lib/SeMeet/Controller/Groups.pm @@ -6,7 +6,8 @@ sub list($c) { my $args = $c->validation->output; my $groups = $c->schema->resultset('Group')->search({ - name => { ilike => '%' . $args->{search} . '%' } + name => { ilike => '%' . $args->{search} . '%' }, + deleted => undef, }, { order_by => 'name', diff --git a/lib/SeMeet/Schema/Result/Group.pm b/lib/SeMeet/Schema/Result/Group.pm index 23af7d4..17bb0d0 100644 --- a/lib/SeMeet/Schema/Result/Group.pm +++ b/lib/SeMeet/Schema/Result/Group.pm @@ -17,6 +17,7 @@ __PACKAGE__->add_columns( sequence => 'uid_seq' }, qw( + deleted octid name permissions diff --git a/lib/SeMeet/Schema/Result/User.pm b/lib/SeMeet/Schema/Result/User.pm index e630aeb..288b4c1 100644 --- a/lib/SeMeet/Schema/Result/User.pm +++ b/lib/SeMeet/Schema/Result/User.pm @@ -25,6 +25,7 @@ __PACKAGE__->add_columns( uuid username displayname + permissions ), ); @@ -43,6 +44,12 @@ __PACKAGE__->has_many( { 'foreign.owner_id' => 'self.id', }, ); +__PACKAGE__->inflate_column('permissions', { + inflate => sub { + return [ split /\W+/, shift ]; + }, +}); + sub api_token { my $self = shift; my $args = shift; diff --git a/script/sync_octopus_groups b/script/sync_octopus_groups index f018fec..3a309ed 100755 --- a/script/sync_octopus_groups +++ b/script/sync_octopus_groups @@ -47,7 +47,9 @@ foreach my $group ( @{ $octopus_groups } ) { } # Cleanup -$schema->resultset('Group')->search({octid => {-not_in => \@exists}})->delete; +$schema->resultset('Group')->search({octid => {-not_in => \@exists}})->update({ + deleted => \'now()' +}); # Update cache my $meets = $schema->resultset('Meet')->search({deleted => undef}); diff --git a/sql/migrations.sql b/sql/migrations.sql index 968a2e3..665c8f0 100644 --- a/sql/migrations.sql +++ b/sql/migrations.sql @@ -84,3 +84,9 @@ join "users" on ("users"."id" = "meets_users"."user_id") -- 6 up drop table "moderators"; alter table "users" drop column "octid"; + +-- 7 up +alter table "users" add column "permissions" text; + +-- 8 up +alter table "groups" add column "deleted" timestamp(0); -- GitLab