mirror of
https://github.com/flarum/core.git
synced 2025-10-18 10:16:09 +02:00
Begin implementing permissions page
This commit is contained in:
@@ -36,4 +36,14 @@ class Group extends Model
|
||||
{
|
||||
return $this->belongsToMany('Flarum\Core\Users\User', 'users_groups');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the group's permissions.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->hasMany('Flarum\Core\Groups\Permission');
|
||||
}
|
||||
}
|
||||
|
55
src/Core/Groups/Permission.php
Executable file
55
src/Core/Groups/Permission.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php namespace Flarum\Core\Groups;
|
||||
|
||||
use Flarum\Core\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* @todo document database columns with @property
|
||||
*/
|
||||
class Permission extends Model
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $table = 'permissions';
|
||||
|
||||
/**
|
||||
* Define the relationship with the group that this permission is for.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return $this->belongsTo('Flarum\Core\Groups\Group', 'group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
{
|
||||
$query->where('group_id', $this->group_id)
|
||||
->where('permission', $this->permission);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a map of permissions to the group IDs that have them.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public static function map()
|
||||
{
|
||||
$permissions = [];
|
||||
|
||||
foreach (static::get() as $permission) {
|
||||
$permissions[$permission->permission][] = $permission->group_id;
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user