Skip to content

Commit

Permalink
chore: drop unused visibility checking in notif syncer
Browse files Browse the repository at this point in the history
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
  • Loading branch information
SychO9 committed Apr 27, 2023
1 parent 7684a10 commit ce6cb58
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 64 deletions.
18 changes: 0 additions & 18 deletions framework/core/src/Notification/NotificationSyncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ public function sync(Blueprint\BlueprintInterface $blueprint, array $users)
continue;
}

// To add access checking on notification subjects, we first attempt
// to load visible subjects to this user.
if (! $this->userCanSeeSubject($user, $blueprint->getSubject())) {
continue;
}

$existing = $toDelete->first(function ($notification) use ($user) {
return $notification->user_id === $user->id;
});
Expand Down Expand Up @@ -168,18 +162,6 @@ protected function setDeleted(array $ids, $isDeleted)
Notification::whereIn('id', $ids)->update(['is_deleted' => $isDeleted]);
}

/**
* Check access to determine if the recipient is allowed to receive the notification.
*/
protected function userCanSeeSubject(User $user, ?AbstractModel $subject): bool
{
if ($subject && method_exists($subject, 'registerVisibilityScoper')) {
return (bool) $subject->newQuery()->whereVisibleTo($user)->find($subject->id);
}

return true;
}

/**
* Adds a notification driver to the list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,6 @@ protected function setUp(): void
]);
}

/**
* @dataProvider visibleSubjectsProvider
* @param class-string<AbstractModel> $subjectClass
* @test
*/
public function can_receive_notification_for_visible_subjects(string $subjectClass, int $subjectId, string $serializer)
{
$this->expect_notification_count_from_sending_notification_type_with_subject(
2,
$subjectClass,
$subjectId,
$serializer
);
}

/**
* @dataProvider invisibleSubjectsProvider
* @test
*/
public function cannot_receive_notification_for_restricted_subjects(string $subjectClass, int $subjectId, string $serializer)
{
$this->expect_notification_count_from_sending_notification_type_with_subject(
0,
$subjectClass,
$subjectId,
$serializer
);
}

/**
* @param class-string<AbstractModel> $subjectClass
*/
Expand Down Expand Up @@ -112,23 +83,6 @@ protected function expect_notification_count_from_sending_notification_type_with
->count()
);
}

public function visibleSubjectsProvider()
{
return [
[Post::class, 1, BasicPostSerializer::class],
[Discussion::class, 1, BasicDiscussionSerializer::class],
];
}

public function invisibleSubjectsProvider()
{
return [
[Post::class, 2, BasicPostSerializer::class],
[Discussion::class, 2, BasicDiscussionSerializer::class],
[Post::class, 3, BasicPostSerializer::class],
];
}
}

class CustomNotificationType implements BlueprintInterface
Expand Down

0 comments on commit ce6cb58

Please # to comment.