Update Kirby and dependencies
This commit is contained in:
parent
503b339974
commit
399fa20902
439 changed files with 66915 additions and 64442 deletions
|
@ -18,128 +18,128 @@ namespace Kirby\Cms;
|
|||
*/
|
||||
class Roles extends Collection
|
||||
{
|
||||
/**
|
||||
* Returns a filtered list of all
|
||||
* roles that can be created by the
|
||||
* current user
|
||||
*
|
||||
* @return $this|static
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function canBeChanged()
|
||||
{
|
||||
if (App::instance()->user()) {
|
||||
return $this->filter(function ($role) {
|
||||
$newUser = new User([
|
||||
'email' => 'test@getkirby.com',
|
||||
'role' => $role->id()
|
||||
]);
|
||||
/**
|
||||
* Returns a filtered list of all
|
||||
* roles that can be created by the
|
||||
* current user
|
||||
*
|
||||
* @return $this|static
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function canBeChanged()
|
||||
{
|
||||
if (App::instance()->user()) {
|
||||
return $this->filter(function ($role) {
|
||||
$newUser = new User([
|
||||
'email' => 'test@getkirby.com',
|
||||
'role' => $role->id()
|
||||
]);
|
||||
|
||||
return $newUser->permissions()->can('changeRole');
|
||||
});
|
||||
}
|
||||
return $newUser->permissions()->can('changeRole');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a filtered list of all
|
||||
* roles that can be created by the
|
||||
* current user
|
||||
*
|
||||
* @return $this|static
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function canBeCreated()
|
||||
{
|
||||
if (App::instance()->user()) {
|
||||
return $this->filter(function ($role) {
|
||||
$newUser = new User([
|
||||
'email' => 'test@getkirby.com',
|
||||
'role' => $role->id()
|
||||
]);
|
||||
/**
|
||||
* Returns a filtered list of all
|
||||
* roles that can be created by the
|
||||
* current user
|
||||
*
|
||||
* @return $this|static
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function canBeCreated()
|
||||
{
|
||||
if (App::instance()->user()) {
|
||||
return $this->filter(function ($role) {
|
||||
$newUser = new User([
|
||||
'email' => 'test@getkirby.com',
|
||||
'role' => $role->id()
|
||||
]);
|
||||
|
||||
return $newUser->permissions()->can('create');
|
||||
});
|
||||
}
|
||||
return $newUser->permissions()->can('create');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $roles
|
||||
* @param array $inject
|
||||
* @return static
|
||||
*/
|
||||
public static function factory(array $roles, array $inject = [])
|
||||
{
|
||||
$collection = new static();
|
||||
/**
|
||||
* @param array $roles
|
||||
* @param array $inject
|
||||
* @return static
|
||||
*/
|
||||
public static function factory(array $roles, array $inject = [])
|
||||
{
|
||||
$collection = new static();
|
||||
|
||||
// read all user blueprints
|
||||
foreach ($roles as $props) {
|
||||
$role = Role::factory($props, $inject);
|
||||
$collection->set($role->id(), $role);
|
||||
}
|
||||
// read all user blueprints
|
||||
foreach ($roles as $props) {
|
||||
$role = Role::factory($props, $inject);
|
||||
$collection->set($role->id(), $role);
|
||||
}
|
||||
|
||||
// always include the admin role
|
||||
if ($collection->find('admin') === null) {
|
||||
$collection->set('admin', Role::admin());
|
||||
}
|
||||
// always include the admin role
|
||||
if ($collection->find('admin') === null) {
|
||||
$collection->set('admin', Role::admin());
|
||||
}
|
||||
|
||||
// return the collection sorted by name
|
||||
return $collection->sort('name', 'asc');
|
||||
}
|
||||
// return the collection sorted by name
|
||||
return $collection->sort('name', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $root
|
||||
* @param array $inject
|
||||
* @return static
|
||||
*/
|
||||
public static function load(string $root = null, array $inject = [])
|
||||
{
|
||||
$kirby = App::instance();
|
||||
$roles = new static();
|
||||
/**
|
||||
* @param string|null $root
|
||||
* @param array $inject
|
||||
* @return static
|
||||
*/
|
||||
public static function load(string $root = null, array $inject = [])
|
||||
{
|
||||
$kirby = App::instance();
|
||||
$roles = new static();
|
||||
|
||||
// load roles from plugins
|
||||
foreach ($kirby->extensions('blueprints') as $blueprintName => $blueprint) {
|
||||
if (substr($blueprintName, 0, 6) !== 'users/') {
|
||||
continue;
|
||||
}
|
||||
// load roles from plugins
|
||||
foreach ($kirby->extensions('blueprints') as $blueprintName => $blueprint) {
|
||||
if (substr($blueprintName, 0, 6) !== 'users/') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// callback option can be return array or blueprint file path
|
||||
if (is_callable($blueprint) === true) {
|
||||
$blueprint = $blueprint($kirby);
|
||||
}
|
||||
// callback option can be return array or blueprint file path
|
||||
if (is_callable($blueprint) === true) {
|
||||
$blueprint = $blueprint($kirby);
|
||||
}
|
||||
|
||||
if (is_array($blueprint) === true) {
|
||||
$role = Role::factory($blueprint, $inject);
|
||||
} else {
|
||||
$role = Role::load($blueprint, $inject);
|
||||
}
|
||||
if (is_array($blueprint) === true) {
|
||||
$role = Role::factory($blueprint, $inject);
|
||||
} else {
|
||||
$role = Role::load($blueprint, $inject);
|
||||
}
|
||||
|
||||
$roles->set($role->id(), $role);
|
||||
}
|
||||
$roles->set($role->id(), $role);
|
||||
}
|
||||
|
||||
// load roles from directory
|
||||
if ($root !== null) {
|
||||
foreach (glob($root . '/*.yml') as $file) {
|
||||
$filename = basename($file);
|
||||
// load roles from directory
|
||||
if ($root !== null) {
|
||||
foreach (glob($root . '/*.yml') as $file) {
|
||||
$filename = basename($file);
|
||||
|
||||
if ($filename === 'default.yml') {
|
||||
continue;
|
||||
}
|
||||
if ($filename === 'default.yml') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role = Role::load($file, $inject);
|
||||
$roles->set($role->id(), $role);
|
||||
}
|
||||
}
|
||||
$role = Role::load($file, $inject);
|
||||
$roles->set($role->id(), $role);
|
||||
}
|
||||
}
|
||||
|
||||
// always include the admin role
|
||||
if ($roles->find('admin') === null) {
|
||||
$roles->set('admin', Role::admin($inject));
|
||||
}
|
||||
// always include the admin role
|
||||
if ($roles->find('admin') === null) {
|
||||
$roles->set('admin', Role::admin($inject));
|
||||
}
|
||||
|
||||
// return the collection sorted by name
|
||||
return $roles->sort('name', 'asc');
|
||||
}
|
||||
// return the collection sorted by name
|
||||
return $roles->sort('name', 'asc');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue