changeset 957:4961963431f9 draft

Exclude quiz/enquete articles from new posts list of other users
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 09 Dec 2021 08:40:17 +0900
parents b8ce08814228
children a0b1e62df613
files s4-funcs.sh
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/s4-funcs.sh	Thu Nov 25 11:18:25 2021 +0900
+++ b/s4-funcs.sh	Thu Dec 09 08:40:17 2021 +0900
@@ -72,6 +72,7 @@
 "
 file_warn="$file_accept_help
 [編集]リンクから修正してください。"
+hidden_mode="('quiz', 'enquete')"
 blogreadflagrowid=0
 blogcutoffflagrowid=-1
 nonewgroupworld=${NONEWGROUPWORLD:-*archive*}
@@ -2104,7 +2105,7 @@
       NATURAL JOIN
       (SELECT id, val owner FROM blog_s WHERE key='owner') bs
  WHERE CASE WHEN (SELECT name FROM user where name=bs.owner) IS NOT NULL
-	     THEN 1		-- blog owner is an user, READABLE
+	     THEN 1		-- blog owner is an user, READABLE when
 	    WHEN (SELECT user FROM grp_mem
 		  WHERE gname=bs.owner AND user='$user') IS NULL
 	    THEN 0
@@ -2358,6 +2359,7 @@
   shortval=${shortval:-val}
 
   # The m.aid in the next line is suspicious.  But works fine in SQLite3...
+  # $hidden_mode is defined in global section
   DT_SQL="SELECT b.rowid || '#' || m.aid LINK,
        ctime,
        (SELECT $shortval FROM blog_s WHERE key='title' AND id=b.id) title,
@@ -2372,7 +2374,13 @@
       ON a.id=s.id AND a.author='$uname' AND s.key='ctime'
       GROUP BY blogid ORDER BY val DESC LIMIT 50
      ) m
-     ON b.id=m.blogid;"
+     ON b.id=m.blogid
+      AND
+       ('$uname' = '$user'			-- user can read all own posts
+          OR
+	  -- exclude posts of others in quiz/enquete blogs
+        NOT EXISTS (SELECT * FROM blog_s
+       	   	   WHERE id=b.id AND key='mode' AND val IN $hidden_mode));"
   # This should be as follows
   : <<EOF
 WITH arts AS(
@@ -3324,12 +3332,15 @@
 EOF
 }
 sql4readableblogs() {
-  # Create view of blogs that can be readable to $user
+  # Create view of blogs that can be readable by $user
   # Blog is readable when:
   #  1: blog owner is an user
   #  2: else, 2.1: owner-group where the $user belongs
   #           2.2: else, owner-group is not moderated
   # blog(id, author), blog_s(id, key='owner', val= ->owner)
+
+  # $hidden_mode is defined in global section at head
+
   cat<<EOF ## | tee tmp/sql.out
 CREATE TEMPORARY VIEW readableblogs AS
  SELECT blog.rowid rid, id, author
@@ -3340,14 +3351,15 @@
       	      max(CASE key WHEN 'mode' THEN val END) mode
        FROM blog_s GROUP by id) bs
  WHERE CASE WHEN (SELECT name FROM user where name=bs.owner) IS NOT NULL
-	     THEN 1		-- blog owner is an user, READABLE
+	     THEN 		-- blog owner is an user, READABLE
+		NOT mode IN $hidden_mode
 	    WHEN (SELECT val FROM grp_s
 		  WHERE gname=bs.owner AND key='regmode') = 'moderated'
 	      AND
 		 (SELECT user FROM grp_mem
 		  WHERE gname=bs.owner AND user='$user') IS NULL
 	    THEN 0
-	    WHEN mode IN ('quiz', 'enquete')
+	    WHEN mode IN $hidden_mode
 	    THEN 0		-- "quiz" mode blog cannot be searched
 	    ELSE 1
        END;

yatex.org