diff s4-funcs.sh @ 245:b915381669d6

Do not search from unreadable blogs
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 10 Jul 2016 23:25:49 +0859
parents 466ea3e4b039
children de0a9f5cc1cf
line wrap: on
line diff
--- a/s4-funcs.sh	Sun Jul 10 20:40:33 2016 +0859
+++ b/s4-funcs.sh	Sun Jul 10 23:25:49 2016 +0859
@@ -2095,6 +2095,31 @@
 $2
 EOF
 }
+sql4readableblogs() {
+  # Create view of blogs that can be readable to $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)
+  cat<<EOF | tee tmp/sql.out
+CREATE TEMPORARY VIEW readableblogs AS
+ SELECT blog.rowid rid, id, author
+ FROM blog
+      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
+	    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
+	    ELSE 1
+       END;
+EOF
+}
 editheading() {	# $1=rowid-of-heading
   rowid=${1%%[!A-Z0-9a-z_]*}
   if [ -z "$rowid" ]; then

yatex.org