diff of 34ddbec81205767c79a86a75877d08b9d8ef5d08

34ddbec81205767c79a86a75877d08b9d8ef5d08
diff --git a/resources/sql/post-fns.sql b/resources/sql/post-fns.sql
index b076c4f..df2103c 100644
--- a/resources/sql/post-fns.sql
+++ b/resources/sql/post-fns.sql
@@ -17,7 +17,7 @@ SELECT p.Title AS "Title",
        p.id as "Id",
        p.Tags as "Tags"
 FROM blog.Post p
-WHERE $1 OR (NOT p.tags ? 'unlisted' AND NOT p.tags ? 'hidden')
+WHERE $1 OR (NOT p.unlisted AND NOT p.hidden)
 ORDER BY p.created_at DESC;
 
 -- name: get-by-id*
@@ -34,12 +34,12 @@ SELECT p.ID,
 			 u.Nickname,
 			 'img_location',
 			 u.Img_location) as "creator",
-       (SELECT MAX(version) + 1 FROM blog.Post_History phh WHERE (phh.id = p.id AND ((not phh.tags ? 'unlisted') OR $2) AND ((not phh.tags ? 'hidden') OR $2))) AS version,
+       (SELECT MAX(version) + 1 FROM blog.Post_History phh WHERE (phh.id = p.id AND ((not phh.unlisted) OR $2) AND ((not phh.hidden) OR $2))) AS version,
        json_agg(DISTINCT version) as "versions"
 FROM blog.Post p
 JOIN blog.Users u ON u.ID = p.creator_id
-LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND ((not ph.tags ? 'unlisted') OR $2) AND ((not ph.tags ? 'hidden') OR $2))
-WHERE p.ID = $1 AND (NOT p.tags ? 'hidden' OR (p.tags ? 'hidden' AND $2))
+LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND ((not ph.unlisted) OR $2) AND ((not ph.hidden) OR $2))
+WHERE p.ID = $1 AND (NOT p.hidden OR (p.hidden AND $2))
 GROUP BY p.ID, u.ID;
 
 -- name: get-versioned-by-id*
@@ -55,8 +55,8 @@ SELECT p.ID, p.Title, p.created_at, p.Content, p.tags, p.version, 0 AS "amount-o
      json_agg(DISTINCT ph.version) as "versions"
 FROM blog.Post_History p
 JOIN blog.Users u ON u.ID = p.creator_id
-LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND (not ph.tags ? 'unlisted') AND (not ph.tags ? 'hidden'))
-WHERE p.ID = $1 AND p.version = $2 AND not p.tags ? 'hidden'
+LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND (not ph.unlisted) AND (not ph.hidden))
+WHERE p.ID = $1 AND p.version = $2 AND not p.hidden
 GROUP BY p.ID, p.Title, p.created_at, p.Content, p.tags, p.version, "amount-of-comments", u.username, u.nickname, u.img_location;
 
 
@@ -65,7 +65,7 @@ SELECT p.id, p.Title, p.Content, p.created_at, p.tags, u.Username, u.Nickname, u
 FROM blog.Post p
 JOIN blog.Users u ON u.ID = p.creator_id
 LEFT JOIN blog.Comment c ON c.parent_post_id = p.ID
-WHERE NOT p.tags ? 'hidden'
+WHERE NOT p.hidden
 GROUP BY p.ID, u.ID
 ORDER BY p.created_at DESC
 -- this isn't going to work :)
@@ -82,9 +82,9 @@ SELECT p.ID, p.Title, p.Content, p.created_at, p.tags, COUNT(c.ID) AS "amount-of
 FROM blog.Post p
 JOIN blog.Users u ON u.ID = p.creator_id
 LEFT JOIN blog.Comment c ON c.parent_post_id = p.ID
-LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND ((not ph.tags ? 'unlisted') OR $3) AND ((not ph.tags ? 'hidden') OR $3))
-WHERE ((NOT p.tags ? 'unlisted') OR $3)
-  AND ((NOT p.tags ? 'hidden') OR $3)
+LEFT JOIN blog.Post_History ph ON (ph.id = p.id AND ((not ph.unlisted) OR $3) AND ((not ph.hidden) OR $3))
+WHERE ((NOT p.unlisted) OR $3)
+  AND ((NOT p.hidden) OR $3)
 GROUP BY p.ID, u.ID
 ORDER BY p.created_at DESC
 LIMIT $2
@@ -93,7 +93,7 @@ OFFSET $1;
 -- name: landing-page-ids*
 SELECT id
 FROM blog.Post 
-WHERE tags ? 'landing-page' AND NOT tags ? 'hidden';
+WHERE tags ? 'landing-page' AND NOT hidden;
 
 -- name: get-posts-tags* 
 SELECT tags FROM blog.Post WHERE id = :post-id;
@@ -123,13 +123,13 @@ SELECT p.ID, p.Title, p.created_at, p.Content, p.tags, u.Username, u.Nickname, u
 FROM blog.Post p
 JOIN blog.Users u ON u.ID = p.creator_id
 LEFT JOIN blog.Comment c ON c.parent_post_id = p.ID
-WHERE p.tags ? 'landing-page' AND NOT p.tags ? 'hidden'
+WHERE p.tags ? 'landing-page' AND NOT p.hidden
 GROUP BY p.ID, u.ID;
 
 -- name: landing-page-title 
 SELECT p.Title, p.Id
 FROM blog.Post p
-WHERE p.tags ? 'landing-page' AND NOT p.tags ? 'hidden';
+WHERE p.tags ? 'landing-page' AND NOT p.hidden;
 
 
 -- name: get-tagged*
@@ -138,8 +138,8 @@ SELECT p.ID, p.Title, p.Content, p.created_at, p.tags, 0 AS "amount-of-comments"
 FROM blog.Post p
 JOIN blog.Users u ON u.ID = p.creator_id
 LEFT JOIN blog.Post_History ph ON ph.id = p.id 
-WHERE p.tags ? $1 AND (NOT p.tags ? 'hidden' OR (p.tags ? 'hidden' AND $2))
-      	     	      and ((NOT p.tags ? 'unlisted') OR $2)
+WHERE p.tags ? $1 AND (NOT p.hidden OR (p.hidden AND $2))
+      	     	      and ((NOT p.unlisted) OR $2)
 GROUP BY p.ID, u.ID;
 
 -- name: insert-post
diff --git a/test/tests.lisp b/test/tests.lisp
index ffcfc78..71fb4c0 100644
--- a/test/tests.lisp
+++ b/test/tests.lisp
@@ -86,8 +86,64 @@
 
       !L
       (let ((history-data (coerce (postmodern:query "SELECT * FROM blog.Post_History where hidden" :array-hash) 'list)))
-	(is (equalp 3
-		    (length history-data))))))))
+	(is (equalp 3 (length history-data))))
+
+
+      After making sure hidden-flags pass to the history table correctly "," we should see if all the apis that have "allow-hidden?" parameter respect that.
+
+      First"," lets see if the initial state is sane
+
+      !L
+      (let ((existing-hidden-posts (postmodern:query "SELECT * FROM blog.Post where hidden or unlisted"))
+	    (existing-hidden-history-posts (postmodern:query "SELECT * FROM blog.Post_History where hidden or unlisted")))
+	(is (equalp 0 (length existing-hidden-posts)))
+	(is (equalp 3 (length existing-hidden-history-posts))))
+
+      Then we must insert a few hidden and unlisted posts. The binding we are introducing here will be used later
+
+      !L
+      (let ((hidden-post-id (caar (murja.posts.post-db:insert-post "Hidden title" "new post" user-id "[]" t nil)))
+	    (unlisted-post-id (caar (murja.posts.post-db:insert-post "Unlisted title" "new post" user-id "[]" nil t))))
+	(murja.posts.post-db:insert-post "Second title" "new post" user-id "[\"test-hidden\"]" t t)
+
+	(let ((existing-hidden-posts (postmodern:query "SELECT * FROM blog.Post where hidden"))
+	      (existing-unlisted-posts (postmodern:query "SELECT * FROM blog.Post where unlisted")))
+	  (is (equalp 2 (length existing-hidden-posts)))
+	  (is (equalp 2 (length existing-unlisted-posts))))
+
+	(literal 
+      A simple grep of the repository tells us that the interesting functions to test are":"
+      "feuer@vivacia aggressive-murja % grep -iR hidden src |grep -i defun" => 
+      - "src/posts/post-db.lisp:(defun get-titles-by-year (&key allow-hidden?)"
+      - "src/posts/post-db.lisp:(defun get-page (page page-size &key allow-hidden?)"
+      - "src/posts/post-db.lisp:(defun get-post (id &key allow-hidden?)"
+      - "src/posts/post-db.lisp:(defun get-tagged (tag &key allow-hidden?)"
+
+      !L
+      (let ((titles (murja.posts.post-db:get-titles-by-year :allow-hidden? nil))
+	    (first-page (murja.posts.post-db:get-page 1 555 :allow-hidden? nil))
+	    (hidden-post (murja.posts.post-db:get-post hidden-post-id :allow-hidden? nil))
+	    (unlisted-post (murja.posts.post-db:get-post unlisted-post-id :allow-hidden? nil))
+	    (test-hidden-tagged-posts (murja.posts.post-db:get-tagged "test-hidden" :allow-hidden? nil)))
+
+	(is (null hidden-post))
+	(is (null test-hidden-tagged-posts))
+	
+	;; unlisted posts should be always visible
+	(is (atom unlisted-post))
+	;;  just missing from the sidebar titles 
+	(is (not (member unlisted-post-id
+			 (mapcar (lambda (title) (gethash "Id" title)) titles)
+			 :test 'equal)))
+	
+
+	;; test sidebar titles 
+	(is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
+	(is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
+
+	;; test the page
+	(is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal)))
+	(is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal))))))))))
 
 ;; (setf fiveam:*run-test-when-defined* t)