Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- public static function has_access($class = null, $method = null, $role = 'make_magic')
- {
- //static::check() + check if user is a staff member
- if ( ! static::is_staff())
- {
- return false;
- }
- //static::$account created at login <ORM object>
- if (in_array(static::$account->name, Config::get('cms.superadmins', array()), true))
- {
- return true;
- }
- $namespace = Inflector::get_namespace($class);
- $class = Inflector::denamespace($class);
- empty($namespace) and $namespace = 'Main\\';
- $resource = $namespace.'::'.$class.'@'.$method;
- //Check cache
- if (isset(static::$roles_cache[$resource][$role]))
- {
- return static::$roles_cache[$resource][$role];
- }
- //Does the role $role is defined in given namespace?
- $role = Model_Site_Role::find()->where('namespace', $namespace)->and_where('name', $role)->get_one();
- if (empty($role))
- {
- return false;
- }
- //Find user's access information for given resource
- $access = Model_Site_Access::find()->where('account_id', static::$account->id)->and_where('resource', $resource)->get_one();
- //Chceck if user has required role
- if (in_array($role->id, $access->roles, true))
- {
- static::$roles_cache[$resource][$role] = true;
- return true;
- }
- static::$roles_cache[$resource][$role] = false;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement