From 0c11666b574c264606556560591a6df69b61bde4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Fri, 30 Oct 2020 18:48:29 +0100
Subject: [PATCH] Rozsireni ACL o delsi opravneni

---
 lib/PiTube/Schema/Result/ACL.pm    |  1 +
 lib/PiTube/Schema/ResultSet/ACL.pm | 11 +++++------
 sql/migrations.sql                 |  2 ++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/PiTube/Schema/Result/ACL.pm b/lib/PiTube/Schema/Result/ACL.pm
index 7c62c3b..0673b04 100644
--- a/lib/PiTube/Schema/Result/ACL.pm
+++ b/lib/PiTube/Schema/Result/ACL.pm
@@ -18,6 +18,7 @@ __PACKAGE__->add_columns(
     },
     qw(
         stream_id
+        rights
         class
         value
     ),
diff --git a/lib/PiTube/Schema/ResultSet/ACL.pm b/lib/PiTube/Schema/ResultSet/ACL.pm
index 2d8c4a6..a444b67 100644
--- a/lib/PiTube/Schema/ResultSet/ACL.pm
+++ b/lib/PiTube/Schema/ResultSet/ACL.pm
@@ -9,17 +9,17 @@ sub user_acl {
     my $class = shift;
     my $user  = shift;
 
-    my $grants = {};
+    my $rights = {};
 
     # verejne streamy
 
     my $streams = $class->result_source->schema->resultset('Stream')->search(
-        { is_public => 1 }
+        { is_public => 't' }
     );
 
     STREAM:
     while ( my $stream = $streams->next ) {
-        $grants->{ $stream->key} = 1; #TODO: read|write
+        $rights->{ $stream->key } = 4;
     }
 
     # na zaklade clenstvi ve skupine, role nebo user.id
@@ -49,13 +49,12 @@ sub user_acl {
         }
     );
 
-
     ACL:
     while ( my $acl = $acls->next ) {
-        $grants->{ $acl->stream->key} = 1; #TODO: read|write
+        $rights->{ $acl->stream->key } |= $acl->rights;
     }
 
-    return $grants;
+    return $rights;
 
 }
 
diff --git a/sql/migrations.sql b/sql/migrations.sql
index 4dd308c..87e3102 100644
--- a/sql/migrations.sql
+++ b/sql/migrations.sql
@@ -28,6 +28,7 @@ create table "streams" (
 create table "acl" (
     "id" integer not null default nextval('uid_seq'),
     "stream_id" integer not null,
+    "rights" smallint, -- 4 - play, 2 - push, 1 - admin
     "class" text,
     "value" text,
     primary key("id"),
@@ -51,3 +52,4 @@ drop sequence "uid_seq";
 
 -- 2 up
 alter table "streams" add "description" text;
+
-- 
GitLab