Permalink
Browse files

Added ability to specify multiple user types for a single access level

  • Loading branch information...
jbroadway committed Jan 28, 2013
1 parent 5eba14b commit c81f4351c658360445acea81abd82abf5f5f781e
Showing with 28 additions and 16 deletions.
  1. +3 −1 apps/user/conf/config.php
  2. +25 −15 apps/user/models/User.php
@@ -38,7 +38,9 @@
; The value "admin" is short for "type:admin".
; To specify a custom access level for a custom user type, enter
; "client = type:client" or simply "client = client".
; "client = type:client" or simply "client = client". To enter
; multiple user types, separate each value with a comma, e.g.,
; "shared = group_a, group_b, group_c".
public = all
member = login
View
@@ -306,26 +306,36 @@ public static function access ($access) {
return FALSE;
}
if (self::$acl[$access] === 'all') {
return TRUE;
if (! is_array (self::$acl[$access])) {
if (strpos (self::$acl[$access], ',') !== false) {
self::$acl[$access] = preg_split ('/, ?/', self::$acl[$access]);
} else {
self::$acl[$access] = array (self::$acl[$access]);
}
}
if (self::$acl[$access] === 'login' && self::is_valid ()) {
return TRUE;
}
foreach (self::$acl[$access] as $access_level) {
if ($access_level === 'all') {
return TRUE;
}
if (self::$acl[$access] === 'admin' && self::is ('admin')) {
return TRUE;
}
if ($access_level === 'login' && self::is_valid ()) {
return TRUE;
}
if (strpos (self::$acl[$access], 'type:') === 0) {
$type = str_replace ('type:', '', self::$acl[$access]);
} else {
$type = self::$acl[$access];
}
if ($access_level === 'admin' && self::is ('admin')) {
return TRUE;
}
if (self::is ($type)) {
return TRUE;
if (strpos ($access_level, 'type:') === 0) {
$type = str_replace ('type:', '', $access_level);
} else {
$type = $access_level;
}
if (self::is ($type)) {
return TRUE;
}
}
return FALSE;

0 comments on commit c81f435

Please sign in to comment.