Index: openacs-4/packages/acs-admin/www/auth/authority-set-enabled-p.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/auth/authority-set-enabled-p.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-admin/www/auth/authority-set-enabled-p.tcl 21 Jan 2018 00:38:38 -0000 1.6 +++ openacs-4/packages/acs-admin/www/auth/authority-set-enabled-p.tcl 21 Dec 2018 10:57:48 -0000 1.7 @@ -6,23 +6,27 @@ @creation-date 2003-09-09 } { - authority_id:naturalnum,notnull - enabled_p:boolean + {authority_id:naturalnum,notnull} + {enabled_p:boolean} +} -validate { + authority_exists -requires {authority_id:naturalnum} { + if {![db_0or1row dbqd...check_authority_id {select authority_id from auth_authorities where authority_id = :authority_id}]} { + ad_complain "Invalid authority" + return + } + } } # Make sure we are not shutting out all site-wide-admins from the system -set allowed_p 1 -if { $enabled_p == "f" && ![auth::can_admin_system_without_authority_p -authority_id $authority_id]} { - set allowed_p 0 -} - -if { $allowed_p } { - db_dml set_enabled_p { update auth_authorities set enabled_p = :enabled_p where authority_id = :authority_id } - ad_returnredirect . -} else { +if { $enabled_p == "f" && ![auth::can_admin_system_without_authority_p -authority_id $authority_id] } { ad_return_error "Cannot disable authority" \ "Disabling this authority would mean that all site-wide administrator users are shut out from the system, meaning the system could no longer be administered." +} else { + set element_arr(enabled_p) $enabled_p + auth::authority::edit -authority_id $authority_id -array element_arr + ad_returnredirect . } + ad_script_abort # Local variables: Index: openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl 7 Aug 2017 23:47:45 -0000 1.5 +++ openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl 21 Dec 2018 10:57:48 -0000 1.6 @@ -1,63 +1,52 @@ ad_page_contract { - Move authorities up/down to control sort order + Move an authority up or down one step in the authorities sort_order hierarchy @author Simon Carstensen (simon@collaboraid.biz) @creation-date 2003-09-09 @cvs-id $Id$ } { - authority_id:naturalnum,notnull - direction -} - -# Get the authority's sort_order -db_1row select_sort_order { - select sort_order - from auth_authorities - where authority_id = :authority_id -} - -if { $direction eq "up" } { - - db_transaction { - # Increase next authority's sort_order by one - db_dml move_next_authority_down { - update auth_authorities - set sort_order = :sort_order - where sort_order = (select max(sort_order) - from auth_authorities - where sort_order < :sort_order) + {authority_id:naturalnum,notnull} + {direction:notnull,oneof(up|down)} +} -validate { + authority_exists -requires {authority_id:naturalnum} { + if {![db_0or1row dbqd...check_authority_id {select authority_id, sort_order from auth_authorities where authority_id = :authority_id}]} { + ad_complain "Invalid authority" + return } - - # Decrease authority's sort_order by one - db_dml move_authority_up { - update auth_authorities - set sort_order = :sort_order - 1 - where authority_id = :authority_id - } } +} -} elseif { $direction eq "down"} { - - db_transaction { - # Decrease previous authority's sort_order by one - db_dml move_prev_authority_up { - update auth_authorities - set sort_order = :sort_order - where sort_order = (select min(sort_order) - from auth_authorities - where sort_order > :sort_order) - } - - # Increase authority's sort_order by one - db_dml move_authority_down { - update auth_authorities - set sort_order = :sort_order + 1 - where authority_id = :authority_id; - } +# Determine the authority which is next to the passed in authority +# in the order hierarchy depending on the direction we want to move it. +switch -- $direction { + "up" { + set op "<" + set orderby_direction desc } + "down" { + set op ">" + set orderby_direction asc + } +} -} +set sql [subst {select + authority_id as swap_authority_id, + sort_order as swap_sort_order + from auth_authorities + where sort_order $op :sort_order + order by sort_order $orderby_direction + limit 1}] +if {[db_0or1row dbqd..get_swap_authority $sql]} { + # adjust sort_order of the passed in authority + set element_arr(sort_order) $swap_sort_order + auth::authority::edit -authority_id $authority_id -array element_arr + + # adjust sort_order of the swap partner authority + set element_arr(sort_order) $sort_order + auth::authority::edit -authority_id $swap_authority_id -array element_arr +} + ad_returnredirect . ad_script_abort