From cbedd946de51c8ec22e2521435b40c39289be421 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Fri, 18 Dec 2020 15:33:04 +0100
Subject: [PATCH] Zruseni namdatorniho filtru typu zpravy

---
 lib/CF/Controller/Posts.pm | 17 ++++++++++++-----
 openapi.yaml               |  2 +-
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/CF/Controller/Posts.pm b/lib/CF/Controller/Posts.pm
index eac8110..54dcdab 100644
--- a/lib/CF/Controller/Posts.pm
+++ b/lib/CF/Controller/Posts.pm
@@ -47,15 +47,22 @@ sub list ($c) {
 
     my ($cond, $attrs) = $c->search_parametrs( $args );
 
-    $cond->{type} = $args->{type};
-
     if ( exists $args->{archived} && defined $args->{archived}) {
         $cond->{is_archived} = $args->{archived};
     }
 
-    # neschvalene navrhy postupu
-    if ( $args->{type} == 0 && ! $c->user_roles->{chairman} ) {
-        $cond->{state} = {'-in' => [1,2,3,4]}
+    # omezeni zobrazovani nepotvrzenych navrhu postupu
+    if ( $args->{type} ) {
+        $cond->{type} = $args->{type};
+        if ( $args->{type} == 0 && ! $c->user_roles->{chairman} ) {
+            $cond->{state} = {'-in' => [1,2,3,4]}
+        }
+    }
+    elsif (! $c->user_roles->{chairman}) {
+        $cond->{-or} => [
+            { type  => 1 },
+            { state => { '-in' => [1,2,3,4] }},
+        ];
     }
 
     my @posts = ();
diff --git a/openapi.yaml b/openapi.yaml
index a54058b..896e31d 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -176,7 +176,7 @@ paths:
       - name: type
         in: query
         description: "Typ zpravy"
-        required: true
+        required: false
         schema:
           type: integer
           enum: [0, 1]
-- 
GitLab