Changeset 2451
- Timestamp:
- 09/06/08 21:46:19 (3 months ago)
- Location:
- branches/schema06/system
- Files:
-
- 7 modified
-
admin/groups.php (modified) (1 diff)
-
classes/acl.php (modified) (5 diffs)
-
classes/adminhandler.php (modified) (2 diffs)
-
classes/databaseconnection.php (modified) (2 diffs)
-
classes/post.php (modified) (2 diffs)
-
classes/user.php (modified) (1 diff)
-
classes/usergroup.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/schema06/system/admin/groups.php
r2404 r2451 54 54 echo '<form method="post" action="">'; 55 55 echo '<input type="hidden" name="group" value="' . $group_edit->name . '">'; 56 echo '<table><tr><th>' . _t(' Granted') . '</th><th>' . _t('Permission') . '</th><th>' . _t('Denied') . '</th></tr>';56 echo '<table><tr><th>' . _t('Permission') . '</th><th>' . _t('Denied') . '</th><th>' . _t('Read') . '</th><th>' . _t('Write') . '</th><th>' . _t('Full') . '</th></tr>'; 57 57 foreach( $permissions as $perm ) { 58 echo '<tr>'; 59 if( isset( $permissions_granted[ $perm->id ] ) ) { 60 // indicate that this permission is granted 61 } elseif ( isset( $permissions_denied[ $perm->id ] ) ) { 62 // indicate that this permission is denied 58 echo "<tr><td> {$perm->description} </td>"; 59 foreach ( ACL::permission_ids() as $access_name => $access_id ) { 60 echo "<td><input type='checkbox' name='perm_{$perm->id}' value='{$access_name}'"; 61 if ( isset( $permissions_granted[$perm->id] ) && $permissions_granted[$perm->id] == $access_id ) { 62 echo ' checked'; 63 } 64 echo "></td><td>"; 63 65 } 64 echo "<td><input type='checkbox' name='grant[]' value='{$perm->id}'";65 if ( in_array( $perm->id, $permissions_granted ) ) {66 echo ' checked';67 }68 echo "></td><td> {$perm->description} </td><td>";69 echo "<input type='checkbox' name='deny[]' value='{$perm->id}'";70 if ( in_array( $perm->id, $permissions_denied ) ) {71 echo ' checked';72 }73 echo '></td></tr>';74 66 } 75 67 echo '<tr><td colspan="3"><input type="submit" name="permissions" value="' . _t('Submit') . '"></td>'; -
branches/schema06/system/classes/acl.php
r2445 r2451 31 31 public static function __static() 32 32 { 33 $result = DB::get_results( 'SELECT id, nameFROM {permissions};' );34 foreach ( $result as $r) {35 self::$permission_ids [$r->name] = $r->id;33 self::$permission_ids = DB::get_keyvalue( 'SELECT name, id FROM {permissions};' ); 34 if ( self::$permission_ids === FALSE ) { 35 self::$permission_ids = array(); 36 36 } 37 37 } … … 44 44 public static function permission_id( $name ) 45 45 { 46 return ( isset( self::$permission_ids[$name] ) ? self::$permission_ids[$name] : FALSE; 46 return isset( self::$permission_ids[$name] ) ? self::$permission_ids[$name] : FALSE; 47 } 48 49 /** 50 * Return all possible access names 51 * @return array An associative array of access names and ids 52 */ 53 public static function permission_ids() 54 { 55 return self::$$permission_ids; 47 56 } 48 57 … … 230 239 231 240 $result = DB::get_value( $sql ); 232 if ( $result !== FALSE&& self::$permission_ids[$result] == $access ) {241 if ( isset( $result ) && self::$permission_ids[$result] == $access ) { 233 242 // the permission has been granted to this group 234 243 return true; … … 249 258 { 250 259 // Use only numeric ids internally 251 $permission = self::token_id( $permission );260 $permission = self::token_id( $permission ); 252 261 // if we were given a user ID, use that to fetch the group membership from the DB 253 262 if ( is_int( $user) ) { … … 301 310 LIMIT 1; 302 311 SQL; 303 $result = DB::get_value( $sql, array( ':user_id' => $user_id, ':token_id' => $permission ) ;304 305 if ( $result !== FALSE && self::permission_ids[$result] == $access ) {312 $result = DB::get_value( $sql, array( ':user_id' => $user_id, ':token_id' => $permission ) ); 313 314 if ( isset( $result ) && self::$permission_ids[$result] == $access ) { 306 315 return true; 307 316 } -
branches/schema06/system/classes/adminhandler.php
r2434 r2451 1902 1902 $this->theme->users= Users::get_all(); 1903 1903 $this->theme->permissions= ACL::all_permissions( 'description' ); 1904 $this->theme->permissions_granted= $group->granted; 1905 $this->theme->permissions_denied= $group->denied; 1904 $this->theme->permissions_granted= $group->permissions; 1906 1905 } 1907 1906 } … … 1948 1947 else { 1949 1948 $grant= array(); 1950 $deny= array();1951 1949 $revoke= array(); 1952 if ( isset( $this->handler_vars['grant'] ) ) {1953 $form_grant= $this->handler_vars['grant'];1954 }1955 else {1956 $form_grant= array();1957 }1958 if ( isset( $this->handler_vars['deny'] ) ) {1959 $form_deny= $this->handler_vars['deny'];1960 }1961 else {1962 $form_deny= array();1963 }1964 1950 $group= UserGroup::get( $group_name ); 1951 1965 1952 foreach( ACL::all_permissions() as $permission ) { 1966 if ( in_array( $permission->id, $form_grant ) ) { 1967 $grant[]= (int) $permission->id; 1953 // grab the type of access for each permission 1954 if ( isset( $this->handler_vars['perm' + $permission->id] ) ) { 1955 $grant[$permission->id] = $this->handler_vars['perm' + $permission->id]; 1968 1956 } 1969 elseif ( in_array( $permission->id, $form_deny ) ) { 1970 $deny[]= (int) $permission->id; 1957 // if it isn't set, then revoke it 1958 else { 1959 $revoke[] = (int) $permission->id; 1971 1960 } 1972 else { 1973 $revoke[]= (int) $permission->id; 1974 } 1975 } 1976 if ( ! empty( $grant ) ){ 1961 } 1962 if ( ! empty( $grant ) ) { 1963 /* the following call does not yet work as used 1964 * need to re-write UserGroup::grant() */ 1977 1965 $group->grant( $grant ); 1978 }1979 if ( ! empty( $deny ) ) {1980 $group->deny( $deny );1981 1966 } 1982 1967 if ( ! empty( $revoke ) ) { -
branches/schema06/system/classes/databaseconnection.php
r2404 r2451 26 26 'crontab', 27 27 'groups', 28 'group s_permissions',28 'group_token_permissions', 29 29 'log', 30 30 'log_types', 31 'object_terms', 32 'object_types', 31 33 'options', 32 34 'permissions', 35 'post_tokens', 33 36 'postinfo', 34 37 'posts', … … 39 42 'tag2post', 40 43 'tags', 44 'terms', 45 'tokens', 41 46 'userinfo', 42 47 'users', 48 'user_token_permissions', 43 49 'users_groups', 50 'vocabularies', 44 51 ); 45 52 -
branches/schema06/system/classes/post.php
r2448 r2451 1006 1006 { 1007 1007 $token_id = ACL::token_id( $permission ); 1008 if ( $token_id !== FALSE) {1008 if ( isset( $token_id ) ) { 1009 1009 DB::insert( '{post_tokens}', array( 'post_id' => $this->id, 'token_id' => $token_id ) ); 1010 1010 } … … 1016 1016 public function delete_permissions() 1017 1017 { 1018 DB::delete( '{post_tokens}', array( 'post_id' ,=> $this->id ) );1018 DB::delete( '{post_tokens}', array( 'post_id' => $this->id ) ); 1019 1019 } 1020 1020 } -
branches/schema06/system/classes/user.php
r2448 r2451 406 406 407 407 /** 408 * Assign one or more new permissions to this user 409 * @param mixed A permission token ID, name, or array of the same 410 **/ 411 public function grant( $permissions, $access = 'full' ) 412 { 413 $permissions = Utils::single_array( $permissions ); 414 // Use ids internally for all permissions 415 $permissions = array_map(array('ACL', 'token_id'), $permissions); 416 417 foreach ( $permissions as $permission ) { 418 ACL::grant_user( $this->id, $permission, $access ); 419 } 420 } 421 422 /** 423 * Deny one or more permissions to this user 424 * @param mixed The permission ID or name to be denied, or an array of the same 425 **/ 426 public function deny( $permissions ) 427 { 428 $this->grant( $permissions, 'deny' ); 429 } 430 431 /** 432 * Remove one or more permissions from a user 433 * @param mixed a permission ID, name, or array of the same 434 **/ 435 public function revoke( $permissions ) 436 { 437 $permissions = Utils::single_array( $permissions ); 438 // get token IDs 439 $permissions = array_map(array('ACL', 'token_id'), $permissions); 440 foreach ( $permissions as $permission ) { 441 ACL::revoke_user_permission( $this->id, $permission ); 442 } 443 } 444 445 /** 408 446 * function groups 409 447 * Returns an array of groups to which this user belongs -
branches/schema06/system/classes/usergroup.php
r2445 r2451 235 235 { 236 236 $permissions = Utils::single_array( $permissions ); 237 $permissions = array_map(array('ACL', 'token_id'), $permissions); 237 238 // Remove permissions from the granted list 238 239 $this->permissions = array_diff_key( $this->permissions, $permissions );
