Repository navigation
Conversation
User IDs are used as array keys for the recipient lists and the notification settings. PHP stores numeric string keys like '55' as integers, and array_merge() renumbers integer keys from 0. With activity_use_cached_mountpoints enabled, file activities on instances with numeric user IDs were written for the users 0, 1, 2, ... instead of the real recipients. The email and notification settings of users who favorited the file were lost the same way. Use array_replace() for these keyed merges and cast the keys back to strings before comparing them with the current user, so the actor gets the "self" subject on rename and move. Fixes nextcloud#3071 Signed-off-by: motey <bleimehl@gmail.com>
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Fixes #3071
Problem
FilesHookskeys the recipient lists (uid => path) and the email/notification settings (uid => value) by user ID and combines them witharray_merge(). PHP stores numeric string keys like'55'as integers, andarray_merge()renumbers integer keys from 0. On instances with numeric user IDs (e.g.user_oidcwith a numericsub):activity_use_cached_mountpoints=true, file activities (created, changed, deleted, restored, renamed, moved) are written for the users0,1,2, ... instead of the real recipients. If a user with such an ID exists, they receive the activities of shares they have no access to.activity_use_cached_mountpoints=false.Change
array_replace()instead ofarray_merge()for the keyed merges ingetFileChangeActivitySettings(),addNotificationsForFileAction(),fileMove(),fileRenaming()andfileMoving(). For string keys the result is the same as before (later values win), integer keys are kept.fileRenaming()andgenerateDelete/Add/MoveActivities(), asaddNotificationsForFileAction()already does. Otherwise$user === $this->currentUser->getUID()is never true for numeric IDs and the actor getsrenamed_by/moved_byinstead ofrenamed_self/moved_self.The
array_merge()calls on plain lists ($allUsers,$usersToCheck,$rules) are not affected and stay as they are.Tests
Added to
tests/FilesHooksTest.php, all with numeric user IDs (56is the actor):testAddNotificationsForFileActionNumericUserIds: recipients from the access list, with and without cached mounts, plus a favorite. Checks the user IDs, subjects and email/notification settings passed toaddNotificationsForUser().testFileRenamingNumericUserIdsWithMountCachetestFileMoveNumericUserIdsWithMountCache: cross-folder move with deleted, added and moved users.All new tests fail on master (activities go to
0,1,2,3) and pass with this change. The full unit suite passes locally (470 tests, SQLite, server master), and php-cs-fixer and psalm report no issues.The same code is in stable33, stable34 and stable35, so a backport would help the affected instances.
🤖 AI (if applicable)