[CORE][Note] Implement private group scope properly
This commit is contained in:
parent
6500e99b69
commit
62bf788b90
@ -49,5 +49,8 @@ class ActorLocalRoles extends Bitmap
|
|||||||
// System Administrator
|
// System Administrator
|
||||||
public const OPERATOR = 8;
|
public const OPERATOR = 8;
|
||||||
|
|
||||||
|
// Private Group
|
||||||
|
public const PRIVATE_GROUP = 16;
|
||||||
|
|
||||||
public const PREFIX = 'ROLE_';
|
public const PREFIX = 'ROLE_';
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Core\ActorLocalRoles;
|
||||||
use App\Core\Cache;
|
use App\Core\Cache;
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Entity;
|
use App\Core\Entity;
|
||||||
@ -398,15 +399,17 @@ class Note extends Entity
|
|||||||
return false;
|
return false;
|
||||||
case VisibilityScope::GROUP:
|
case VisibilityScope::GROUP:
|
||||||
// Only for the group to see
|
// Only for the group to see
|
||||||
return !\is_null($actor) && DB::dql(
|
return !\is_null($actor) && (
|
||||||
|
!($actor->getRoles() & ActorLocalRoles::PRIVATE_GROUP) // Public Group
|
||||||
|
|| DB::dql( // It's a member of the private group
|
||||||
<<<'EOF'
|
<<<'EOF'
|
||||||
select m from group_member m
|
SELECT m FROM \Component\Group\Entity\GroupMember m
|
||||||
join group_inbox i with m.group_id = i.group_id
|
JOIN \Component\Notification\Entity\Notification att WITH m.group_id = att.target_id
|
||||||
join note n with i.activity_id = n.id
|
JOIN \App\Entity\Activity a WITH att.activity_id = a.id
|
||||||
where n.id = :note_id and m.actor_id = :actor_id
|
WHERE a.object_id = :note_id AND m.actor_id = :actor_id
|
||||||
EOF,
|
EOF,
|
||||||
['note_id' => $this->id, 'actor_id' => $actor->getId()],
|
['note_id' => $this->id, 'actor_id' => $actor->getId()],
|
||||||
) !== [];
|
) !== []);
|
||||||
case VisibilityScope::COLLECTION:
|
case VisibilityScope::COLLECTION:
|
||||||
case VisibilityScope::MESSAGE:
|
case VisibilityScope::MESSAGE:
|
||||||
// Only for the collection to see
|
// Only for the collection to see
|
||||||
@ -417,13 +420,11 @@ class Note extends Entity
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// @return array of ids of Actors
|
||||||
* @return array of ids of Actors
|
public array $_object_mentions_ids = [];
|
||||||
*/
|
|
||||||
private array $object_mentions_ids = [];
|
|
||||||
public function setObjectMentionsIds(array $mentions): self
|
public function setObjectMentionsIds(array $mentions): self
|
||||||
{
|
{
|
||||||
$this->object_mentions_ids = $mentions;
|
$this->_object_mentions_ids = $mentions;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +433,7 @@ class Note extends Entity
|
|||||||
*/
|
*/
|
||||||
public function getNotificationTargetIds(array $ids_already_known = [], ?int $sender_id = null, bool $include_additional = true): array
|
public function getNotificationTargetIds(array $ids_already_known = [], ?int $sender_id = null, bool $include_additional = true): array
|
||||||
{
|
{
|
||||||
$target_ids = $this->object_mentions_ids ?? [];
|
$target_ids = $this->_object_mentions_ids ?? [];
|
||||||
if ($target_ids === []) {
|
if ($target_ids === []) {
|
||||||
$content = $this->getContent();
|
$content = $this->getContent();
|
||||||
if (!\array_key_exists('object', $ids_already_known)) {
|
if (!\array_key_exists('object', $ids_already_known)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user