[ENTITY][Actor] Add helper function for checking if the current actor can admin another
This commit is contained in:
parent
63679426b6
commit
80ebd6fb7b
|
@ -261,6 +261,7 @@ class Actor extends Entity
|
|||
'subscriber' => "subscriber-{$actor_id}",
|
||||
'subscribed' => "subscribed-{$actor_id}",
|
||||
'relative-nickname' => "actor-{$actor_id}-relative-nickname-{$other}", // $other is $nickname
|
||||
'can-admin' => "actor-{$actor_id}-can-admin-{$other}", // $other is an actor id
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -595,6 +596,29 @@ class Actor extends Entity
|
|||
return true; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether $this has permission for performing actions on behalf of $other
|
||||
*/
|
||||
public function canAdmin(self $other): bool
|
||||
{
|
||||
switch ($other->getType()) {
|
||||
case self::GROUP:
|
||||
return Cache::get(
|
||||
self::cacheKeys($this->getId(), $other->getId())['can-admin'],
|
||||
function () use ($other) {
|
||||
try {
|
||||
return DB::findOneBy('group_member', ['group_id' => $other->getId(), 'actor_id' => $this->getId()])->getIsAdmin();
|
||||
} catch (NotFoundException) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
|
|
Loading…
Reference in New Issue
Block a user