-
-
Notifications
You must be signed in to change notification settings - Fork 77
Correctly listen to group change events #1601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58c6fbf
AlbumMapper: new method to remove all files for a given user
cd43d81
Group sharing: remove photos by user if user is remved from group
7e711aa
AlbumMapper: add possibility to remove group from collabs
302bb3f
Add listener for GroupDeletedEvent to drop this group as collaborator
7da43d2
Use tab as indentation
7027273
Allow fetching albums without files
c2ac203
Group deletion listener: use new mapper method
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add listener for GroupDeletedEvent to drop this group as collaborator
Signed-off-by: Simon Spannagel <[email protected]>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
|
|
||
| namespace OCA\Photos\Listener; | ||
|
|
||
| use OCA\Photos\Album\AlbumMapper; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\Group\Events\GroupDeletedEvent; | ||
|
|
||
| class GroupDeletedListener implements IEventListener { | ||
| private AlbumMapper $albumMapper; | ||
|
|
||
| public function __construct(AlbumMapper $albumMapper) { | ||
| $this->albumMapper = $albumMapper; | ||
| } | ||
|
|
||
| public function handle(Event $event): void { | ||
| if (!($event instanceof GroupDeletedEvent)) { | ||
| return; | ||
| } | ||
|
|
||
| // Get all shared albums for this group: | ||
| $albums_group = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($event->getGroup()->getGID(), AlbumMapper::TYPE_GROUP); | ||
artonge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Get all users of this group: | ||
| $users = $event->getGroup()->getUsers(); | ||
|
|
||
| foreach ($users as $user) { | ||
artonge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $uid = $user->getUID(); | ||
|
|
||
| // Get all albums shared with this specific user: | ||
| $albums_user = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($user->getUID(), AlbumMapper::TYPE_USER); | ||
|
|
||
| // Get all group-shared albums that are not directly shared with the removed user in addition | ||
| $albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getAlbum()->getId() - $b->getAlbum()->getId())); | ||
|
|
||
|
|
||
| // Remove their photos from theses albums: | ||
| foreach ($albums as $album) { | ||
| $this->albumMapper->removeFilesForUser($album->getAlbum()->getId(), $user->getUID()); | ||
| } | ||
| } | ||
|
|
||
| foreach ($albums_group as $album) { | ||
| $this->albumMapper->deleteGroupFromAlbumCollaboratorsList($event->getGroup()->getGID(), $album->getAlbum()->getId()); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.