[ENTITY][Actor] Basic check if can admin for remote actors
This commit is contained in:
parent
b7c82b9dcb
commit
9585472679
@ -152,6 +152,24 @@ class ActivityPub extends Plugin
|
|||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill Actor->canAdmin() for Actors that came from ActivityPub
|
||||||
|
*/
|
||||||
|
public function onFreeNetworkActorCanAdmin(Actor $actor, Actor $other, bool &$canAdmin): bool
|
||||||
|
{
|
||||||
|
// Are both in AP?
|
||||||
|
if (
|
||||||
|
!\is_null($ap_actor = ActivitypubActor::getByPK(['actor_id' => $actor->getId()]))
|
||||||
|
&& !\is_null($ap_other = ActivitypubActor::getByPK(['actor_id' => $other->getId()]))
|
||||||
|
) {
|
||||||
|
// Are they both in the same server?
|
||||||
|
$canAdmin = parse_url($ap_actor->getUri(), PHP_URL_HOST) === parse_url($ap_other->getUri(), PHP_URL_HOST);
|
||||||
|
return Event::stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overload core endpoints to make resources available in ActivityStreams 2.0
|
* Overload core endpoints to make resources available in ActivityStreams 2.0
|
||||||
*
|
*
|
||||||
|
@ -517,22 +517,28 @@ class Actor extends Entity
|
|||||||
*/
|
*/
|
||||||
public function canAdmin(self $other): bool
|
public function canAdmin(self $other): bool
|
||||||
{
|
{
|
||||||
switch ($other->getType()) {
|
if ($this->getIsLocal()) {
|
||||||
case self::PERSON:
|
switch ($other->getType()) {
|
||||||
return $this->getId() === $other->getId();
|
case self::PERSON:
|
||||||
case self::GROUP:
|
return $this->getId() === $other->getId();
|
||||||
return Cache::get(
|
case self::GROUP:
|
||||||
self::cacheKeys($this->getId(), $other->getId())['can-admin'],
|
return Cache::get(
|
||||||
function () use ($other) {
|
self::cacheKeys($this->getId(), $other->getId())['can-admin'],
|
||||||
try {
|
function () use ($other) {
|
||||||
return DB::findOneBy('group_member', ['group_id' => $other->getId(), 'actor_id' => $this->getId()])->getIsAdmin();
|
try {
|
||||||
} catch (NotFoundException) {
|
return DB::findOneBy('group_member', ['group_id' => $other->getId(), 'actor_id' => $this->getId()])->getIsAdmin();
|
||||||
return false;
|
} catch (NotFoundException) {
|
||||||
}
|
return false;
|
||||||
},
|
}
|
||||||
);
|
},
|
||||||
default:
|
);
|
||||||
return false;
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$canAdmin = false;
|
||||||
|
Event::handle('FreeNetworkActorCanAdmin', [$this, $other, &$canAdmin]);
|
||||||
|
return $canAdmin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user