changeset 56:7fa1ac62dfaf

getgroupadmins()
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 23 Jul 2015 11:08:22 +0900
parents 7f9f7e898986
children 7c61a80051f5
files s4-funcs.sh
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/s4-funcs.sh	Thu Jul 23 11:07:24 2015 +0900
+++ b/s4-funcs.sh	Thu Jul 23 11:08:22 2015 +0900
@@ -331,13 +331,18 @@
   err isgrpowner: $sql
   test -n "`query $sql`"
 )
-getgroupbyid() (
+getgroupadmins() {	# $1=group
+  # This function is called in a backquote, so needn't to be subshellized
+  qgrp=`sqlquote "$1"`
+  query "select user from grp_adm where gname=$qgrp;"
+}
+getgroupbyid() {
   # $1=id|gname
   sql="select coalesce((select gname from grp where gname=$(sqlquote $1)),
 	(select gname from grp where rowid=$(sqlquote $1)));"
 err ggbyid: `echo $sql`
   query $sql
-)
+}
 isfilereadable() { # $1=user $2=tbl $3=rowid
   # Return true if user($1) can read attachment files in tbl($2):rowid($3)
   [ -z "$1" -o -z "$2" -o -z "$3" ] && return 1 # invalid argument
@@ -1014,6 +1019,16 @@
       ;;
   esac
 }
+email4group() (
+  # Get $1=user email address(es) for group $2=group
+  qgrp=`sqlquote "$2"`
+  sql="select coalesce(s.val, g.user) from grp_mem g
+	join grp_mem_s s on g.gname=s.gname and g.user=s.user
+	and s.key='email' and g.user='$1'
+	where g.gname=$qgrp;"
+  err `echo $sql`
+  query "$sql"
+)
 collectemail() (
   # Collect email addresses for group $1
   for e; do
@@ -1030,7 +1045,7 @@
  #        on a.gname=b.gname and a.val=b.user and b.key='email'
  # where a.val in (select name from user) limit 10000;"
       # tmp tmp tmp tmp tmp tmp tmp
-      qgrp=`sqlquote $e`
+      qgrp=`sqlquote "$e"`
       sql="select coalesce(s.val,g.user) from grp_mem g left join grp_mem_s s
 	 on g.gname=s.gname and g.user=s.user and s.key='email'
 	 where g.gname=$qgrp;"

yatex.org