From 9ec3295c48604be5f6171ad3899ea15eff7f2306 Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Sat, 22 Jan 2011 22:17:48 -0500 Subject: added code to hide and unhde user groups Ignore-this: dbe47375875cb902b86559c535ba97f1 darcs-hash:20110123031748-067c0-55d73253b3199939c6c813a03ecf4934ecf600e6.gz --- GradeBook.tcl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'GradeBook.tcl') diff --git a/GradeBook.tcl b/GradeBook.tcl index a080e10..966de76 100755 --- a/GradeBook.tcl +++ b/GradeBook.tcl @@ -62,7 +62,7 @@ proc AddUserNonWeb { first_name last_name user_name password_hash {group_name {g } proc CreateGradesTable {db} { - set err [catch {db eval {CREATE TABLE GradesTable(FirstName text, LastName text, UserName text, PasswordHash text, GroupName text, UserHiddenColums text)} } errStat] + set err [catch {db eval {CREATE TABLE GradesTable(FirstName text, LastName text, UserName text, PasswordHash text, GroupName text, UserHiddenColums text, UserHiddenGroups text)} } errStat] if { $err } { htmlErrorMsg $errStat dbg "the following error happen: $errStat" 1 @@ -79,7 +79,7 @@ proc CreateGradesTable {db} { AddUserNonWeb Jon "Jonovich" jon [::md5::md5 -hex qwerty] student AddUserNonWeb Ins "Instruch I" instructor [::md5::md5 -hex qwerty] instructor # reasonable defaults for hidden columns - set instructor_hidden_columns [list UserHiddenColums PasswordHash] + set instructor_hidden_columns [list UserHiddenColums PasswordHash UserHiddenGroups] UpdateColValue4GroupNameNonWeb UserHiddenColums instructor $instructor_hidden_columns } @@ -117,6 +117,8 @@ proc CreateAccessRightsTable {db} { AddAccessRightNonWeb changeusername 1 0 0 0 AddAccessRightNonWeb userhidecolumn 1 1 1 0 AddAccessRightNonWeb userunhidecolumn 1 1 1 0 + AddAccessRightNonWeb userhidegroup 1 0 0 0 + AddAccessRightNonWeb userunhidegroup 1 0 0 0 } proc htmlErrorMsg { msg } { @@ -169,8 +171,21 @@ proc htmlDBout {db permission_list user {sort_col {}}} { } set sql_column_str [colList2sqlColStr $column_list] # set users of what group user can see, i.e. set WHERE statement + set where_statement {} switch $permission(GroupName) { - instructor { set where_statement {} } + instructor { + # hide unwanted user groups + set user_groups_for_hide [SelectColValue4User UserHiddenGroups $user] + if {$user_groups_for_hide != {} } { + foreach grp $user_groups_for_hide { + if { $where_statement == {} } { + set where_statement "WHERE GroupName<>\"$grp\"" + } else { + set where_statement [concat $where_statement "AND GroupName<>\"$grp\""] + } + } + } + } ta { set where_statement "WHERE GroupName=\"student\"" } student { set where_statement "WHERE UserName=\"$user\"" } guest { dbg "Guest must not be allowed to set table view port. Aborting. This line is never executed" 0; exit } @@ -374,6 +389,10 @@ proc ChoseAction {action permission_list user} { htmlDefaultView $permission_list $user } userunhidecolumn { UserUnHideColumn $permission_list $user htmlDefaultView $permission_list $user } + userhidegroup { UserHideGroup $permission_list $user + htmlDefaultView $permission_list $user } + userunhidegroup { UserUnHideGroup $permission_list $user + htmlDefaultView $permission_list $user } showgrades { htmlGradesTable db $permission_list $user } defaultview { htmlDefaultView $permission_list $user } default { htmlErrorMsg "requested action $action is granted but not implemented yet" } @@ -384,6 +403,19 @@ proc ChoseAction {action permission_list user} { } } +proc UserUnHideGroup { permission_list user } { + set groupname [::ncgi::value groupname {}] + set currently_hidden_groups [SelectColValue4User UserHiddenGroups $user] + set currently_hidden_groups [removeElementFromList $groupname $currently_hidden_groups] + UpdateColValue4UserNameNonWeb UserHiddenGroups $user $currently_hidden_groups +} +proc UserHideGroup { permission_list user } { + set groupname [::ncgi::value groupname {}] + set currently_hidden_groups [SelectColValue4User UserHiddenGroups $user] + lappend currently_hidden_groups $groupname + UpdateColValue4UserNameNonWeb UserHiddenGroups $user $currently_hidden_groups +} + proc UserHideColumn { permission_list user } { set columnname [::ncgi::value columnname {}] set currently_hidden_columns [SelectColValue4User UserHiddenColums $user] @@ -720,6 +752,29 @@ proc ShowControls { permission_list user } { puts "$col" } } + # hide user groups + set user_groups_for_hide [list inforow student ta instructor] + set currently_hidden_groups [SelectColValue4User UserHiddenGroups $user] + # remove already hidden group from offering + foreach grp $currently_hidden_groups { + set user_groups_for_hide [removeElementFromList $grp $user_groups_for_hide] + } + # output group to hide offering + if { $user_groups_for_hide ne "" } { + puts "
" + puts "HideGroup: " + foreach grp $user_groups_for_hide { + puts "$grp" + } + } + if { $currently_hidden_groups ne "" } { + puts "
" + puts {Unhide groups: } + foreach grp $currently_hidden_groups { + puts "$grp" + } + } + puts "" } -- cgit v1.2.3