API: Add event for determining user groups for permissions

This commit is contained in:
Toby Zerner 2015-08-05 16:06:55 +09:30
parent a323efa410
commit eaf27d3499
2 changed files with 32 additions and 0 deletions

View File

@ -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);
} }

View 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;
}
}