mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 23:53:42 +08:00
API: Add event for determining user groups for permissions
This commit is contained in:
parent
a323efa410
commit
eaf27d3499
|
@ -17,6 +17,7 @@ use Flarum\Events\UserBioWasChanged;
|
||||||
use Flarum\Events\UserAvatarWasChanged;
|
use Flarum\Events\UserAvatarWasChanged;
|
||||||
use Flarum\Events\UserWasActivated;
|
use Flarum\Events\UserWasActivated;
|
||||||
use Flarum\Events\UserEmailChangeWasRequested;
|
use Flarum\Events\UserEmailChangeWasRequested;
|
||||||
|
use Flarum\Events\GetUserGroups;
|
||||||
use Flarum\Core\Support\Locked;
|
use Flarum\Core\Support\Locked;
|
||||||
use Flarum\Core\Support\VisibleScope;
|
use Flarum\Core\Support\VisibleScope;
|
||||||
use Flarum\Core\Support\EventGenerator;
|
use Flarum\Core\Support\EventGenerator;
|
||||||
|
@ -560,6 +561,8 @@ class User extends Model
|
||||||
$groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->lists('id'));
|
$groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->lists('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event(new GetUserGroups($this, $groupIds));
|
||||||
|
|
||||||
return Permission::whereIn('group_id', $groupIds);
|
return Permission::whereIn('group_id', $groupIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
framework/core/src/Events/GetUserGroups.php
Normal file
29
framework/core/src/Events/GetUserGroups.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php namespace Flarum\Events;
|
||||||
|
|
||||||
|
use Flarum\Core\Users\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `GetUserGroups` event
|
||||||
|
*/
|
||||||
|
class GetUserGroups
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $groupIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param array $groupIds
|
||||||
|
*/
|
||||||
|
public function __construct(User $user, array &$groupIds)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->groupIds = &$groupIds;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user