Index: openacs-4/packages/acs-subsite/www/permissions/grant-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/permissions/Attic/grant-oracle.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-subsite/www/permissions/grant-oracle.xql 3 Oct 2003 18:34:45 -0000 1.4 +++ openacs-4/packages/acs-subsite/www/permissions/grant-oracle.xql 7 Oct 2003 16:55:37 -0000 1.5 @@ -9,13 +9,6 @@ - - - select privilege, child_privilege - from acs_privilege_hierarchy - - - select acs_permission.grant_permission(:object_id, :party_id, :privilege) Index: openacs-4/packages/acs-subsite/www/permissions/grant-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/permissions/Attic/grant-postgresql.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-subsite/www/permissions/grant-postgresql.xql 29 Sep 2003 14:53:37 -0000 1.4 +++ openacs-4/packages/acs-subsite/www/permissions/grant-postgresql.xql 7 Oct 2003 16:55:37 -0000 1.5 @@ -8,15 +8,6 @@ - - - select p.privilege, tree_level(h.tree_sortkey) as level - from acs_privileges p - left join acs_privilege_hierarchy_index h on p.privilege=h.privilege - order by h.tree_sortkey - - - select acs_permission__grant_permission(:object_id, :party_id, :privilege) Index: openacs-4/packages/acs-subsite/www/permissions/grant.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/permissions/grant.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-subsite/www/permissions/grant.adp 3 Oct 2003 18:42:47 -0000 1.2 +++ openacs-4/packages/acs-subsite/www/permissions/grant.adp 7 Oct 2003 16:55:37 -0000 1.3 @@ -21,7 +21,12 @@     + + + + + Index: openacs-4/packages/acs-subsite/www/permissions/grant.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/permissions/grant.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-subsite/www/permissions/grant.tcl 3 Oct 2003 18:42:47 -0000 1.6 +++ openacs-4/packages/acs-subsite/www/permissions/grant.tcl 7 Oct 2003 16:55:37 -0000 1.7 @@ -21,123 +21,115 @@ set context [list [list one?[export_url_vars object_id] "[_ acs-subsite.Permissions_for_name]"] [_ acs-subsite.Grant]] -set existing_privs [list] -set hierarchy [list] -set maxlevel 1 +# Compute a hierarchical tree representation of the contents of +# acs_privileges. Note that nodes can appear more than one time in the +# tree. +set existing_privs [db_list select_privileges_list { }] -# Fill a multirow that contains a hierarchical tree representation of -# the acs_privileges. +# The maximum level that has been reached within the hierarchy. +set maxlevel 1 -if { [db_type] == "oracle" } { - # Unfortunately it is not possible to write a query that returns - # all the desired data with the current datamodel consisting of - # only the tables acs_privileges and acs_privilege_hierarchy. This - # is partly due to the restriction that a JOINed query cannot deal - # with CONNECT BY in oracle 8i. See - # http://openacs.org/forums/message-view?message_id=125969 for the - # gory details. That's why this page resorts to a hack and builds - # the tree structure manually in tcl. (-til) +# Initialize the $hierarchy datastructure which is a list of +# lists. The inner lists consist of two elements: 1. level, +# 2. privilege +set hierarchy [list] +foreach privilege $existing_privs { + lappend hierarchy [list 0 $privilege] +} - set existing_privs [db_list select_privileges_list { }] - - # Initialize the $hierarchy datastructure which is a list of - # lists. The inner lists consist of two elements: 1. level, - # 2. privilege - foreach privilege $existing_privs { - lappend hierarchy [list 0 $privilege] +# Loop through each row in acs_privilege_hierarchy and shuffle the +# $hierarchy list accordingly. +db_foreach select_privileges_hierarchy { } { + + if { [set start_pos [lsearch -regexp $hierarchy "\\m$child_privilege\\M"]] == -1 } { + # child_privilege of this relation not in privileges - skip. + continue } + if { [lsearch -regexp $hierarchy "\\m$privilege\\M"] == -1 } { + # privilege of this relation not in privileges - skip. + continue + } - # Loop through each row in acs_privilege_hierarchy and shuffle the - # $hierarchy list accordingly. - db_foreach select_privileges_hierarchy { } { + # the level of the first privilege element that we move + set start_pos_level [lindex [lindex $hierarchy $start_pos] 0] - if { [set start_pos [lsearch -regexp $hierarchy "\\m$child_privilege\\M"]] == -1 } { - # child_privilege of this relation not in privileges - skip. - continue + # find the end position up to where the block extends that we have + # to move + set end_pos $start_pos + for { set i [expr $start_pos + 1] } { $i <= [llength $hierarchy] } { incr i } { + set level [lindex [lindex $hierarchy $i] 0] + if { $level <= $start_pos_level } { + break } - if { [lsearch -regexp $hierarchy "\\m$privilege\\M"] == -1 } { - # privilege of this relation not in privileges - skip. - continue - } + incr end_pos + } - # the level of the first privilege element that we move - set start_pos_level [lindex [lindex $hierarchy $start_pos] 0] - - # find the end position up to where the block extends that we have - # to move - set end_pos $start_pos - for { set i [expr $start_pos + 1] } { $i <= [llength $hierarchy] } { incr i } { - set level [lindex [lindex $hierarchy $i] 0] - if { $level <= $start_pos_level } { - break - } - incr end_pos - } - - # cut out the block - set block_to_move [lrange $hierarchy $start_pos $end_pos] + # define the block + set block_to_move [lrange $hierarchy $start_pos $end_pos] + # Only cut out the block if it is on the toplevel, which means it + # hasn't been moved yet. Otherwise the block will appear in two + # places intentionally. + if { [lindex [lindex $hierarchy $start_pos] 0] == 0 } { set hierarchy [lreplace $hierarchy $start_pos $end_pos] + } - if { [set target_pos [lsearch -regexp $hierarchy "\\m$privilege\\M"]] == -1 } { - # target not found, something is broken with the - # hierarchy. insert the block back to where it was - eval "set hierarchy \[linsert \$hierarchy $start_pos $block_to_move\]" - continue - } - set target_level [lindex [lindex $hierarchy $target_pos] 0] - - # insert the block to the new position, looping through the block - foreach element $block_to_move { - incr target_pos - set level_to_move [expr [lindex $element 0] + $target_level + 1] - set privilege_to_move [lindex $element 1] - set hierarchy [linsert $hierarchy $target_pos [list $level_to_move $privilege_to_move]] - - if { $maxlevel < $level_to_move } { set maxlevel $level_to_move } - } + if { [set target_pos [lsearch -regexp $hierarchy "\\m$privilege\\M"]] == -1 } { + # target not found, something is broken with the + # hierarchy. + continue } + set target_level [lindex [lindex $hierarchy $target_pos] 0] -} else { - # We are not on oracle - use the table - # acs_privilege_hierarchy_index. + # remember the starting level in the block + set offset [lindex [lindex $block_to_move 0] 0] - db_foreach select_privileges_hierarchy { } { - if { [lsearch $existing_privs $privilege] > -1 } { - # skip double entries - continue - } else { - lappend existing_privs $privilege - lappend hierarchy [list $level $privilege] - } + # insert the block to the new position, looping through the block + foreach element $block_to_move { + incr target_pos + set level_to_move [expr [lindex $element 0] + $target_level + 1 - $offset] + set privilege_to_move [lindex $element 1] + set hierarchy [linsert $hierarchy $target_pos [list $level_to_move $privilege_to_move]] - if { $level > $maxlevel } { - set maxlevel $level - } + if { $maxlevel < $level_to_move } { set maxlevel $level_to_move } } - - incr maxlevel } +incr maxlevel -multirow create mu_privileges privilege level inverted_level selected id -# Preserve checked value of the privilege checkboxes for re-submitted -# form status. +# Now the $hierarchy datastructure is ready, use it to build the +# multirow that will be used for display. +multirow create mu_privileges privilege level inverted_level selected id standard_priv_p foreach elm $hierarchy { foreach { level privilege } $elm {} + + # Preserve checked value of the privilege checkboxes for + # re-submitted form status. if { [info exists privileges] && [lsearch $privileges $privilege]>-1 } { set selected "CHECKED" } else { set selected "" } - multirow append mu_privileges $privilege [expr $level+1] [expr $maxlevel - $level] $selected $privilege + + # set standard_priv_p to emphasize standard privileges in the + # layout + if { [lsearch {admin create write delete read} $privilege] > -1 } { + set standard_priv_p 1 + } else { + set standard_priv_p 0 + } + + multirow append mu_privileges $privilege [expr $level+1] [expr $maxlevel - $level] $selected $privilege $standard_priv_p } +# build an html tr line manually to layout the table +set first_tr "" for { set i 0 } { $i < $maxlevel } { incr i } { append first_tr "   " } +append first_tr "" form create grant @@ -177,6 +169,7 @@ } } - ad_returnredirect "one?[export_url_vars object_id]" + ad_returnredirect "one?[export_vars [list object_id application_url]]" + ad_script_abort } Index: openacs-4/packages/acs-subsite/www/permissions/grant.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/permissions/grant.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-subsite/www/permissions/grant.xql 29 Sep 2003 14:53:37 -0000 1.2 +++ openacs-4/packages/acs-subsite/www/permissions/grant.xql 7 Oct 2003 16:55:37 -0000 1.3 @@ -1,6 +1,14 @@ + + + select privilege, child_privilege + from acs_privilege_hierarchy + order by privilege desc, child_privilege desc + + +