changeset 622:84a30765baa1

tj: Add ability for administrator users to 'list' other peoples TJs.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 Feb 2021 15:27:10 +0200
parents a1efc28ef5a4
children efc0e4919746
files tj.tcl
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tj.tcl	Wed Feb 10 15:26:10 2021 +0200
+++ b/tj.tcl	Wed Feb 10 15:27:10 2021 +0200
@@ -204,6 +204,7 @@
   }
 
   set uhand [tj_correct_handle $uhand]
+  set qadmin [matchattr $uhand n]
 
   # Check and handle arguments
   set rarglist [::textutil::split::splitx $uargs {\s+}]
@@ -378,11 +379,21 @@
     }
 
   } elseif {[tj_cmd_match "list" $rcmd]} {
-    # !tj list
+    # !tj list [name]
     # List reminders
+    if {[utl_arg_get $rarglist rindex uname 1]} {
+      set uname [tj_correct_handle $uname]
+      if {$uname != $uhand && !$qadmin} {
+        tj_msg $upublic $unick $uchan "access_denied"
+        return 1
+      }
+    } else {
+      set uname $uhand
+    }
+
     set uclock [clock seconds]
 
-    set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uhand]'"
+    set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uname]'"
     if {[catch {set nitems [tj_dbh onecolumn $usql]} uerrmsg]} {
       tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg]
       tj_log "$uerrmsg on SQL:\n$usql"
@@ -390,7 +401,7 @@
     }
 
     set nitem 0
-    set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uhand]' ORDER BY ucreated"
+    set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uname]' ORDER BY ucreated"
     tj_dbh eval $usql {
       incr nitem
       set ustamp [utl_sql_datetime_to_stamp $utarget]