3434use OCA \UserStatus \Exception \StatusMessageTooLongException ;
3535use OCP \AppFramework \Db \DoesNotExistException ;
3636use OCP \AppFramework \Utility \ITimeFactory ;
37+ use OCP \IConfig ;
3738use OCP \UserStatus \IUserStatus ;
3839
3940/**
@@ -55,6 +56,15 @@ class StatusService {
5556 /** @var EmojiService */
5657 private $ emojiService ;
5758
59+ /** @var bool */
60+ private $ shareeEnumeration ;
61+
62+ /** @var bool */
63+ private $ shareeEnumerationInGroupOnly ;
64+
65+ /** @var bool */
66+ private $ shareeEnumerationPhone ;
67+
5868 /**
5969 * List of priorities ordered by their priority
6070 */
@@ -87,17 +97,22 @@ class StatusService {
8797 *
8898 * @param UserStatusMapper $mapper
8999 * @param ITimeFactory $timeFactory
90- * @param PredefinedStatusService $defaultStatusService,
100+ * @param PredefinedStatusService $defaultStatusService
91101 * @param EmojiService $emojiService
102+ * @param IConfig $config
92103 */
93104 public function __construct (UserStatusMapper $ mapper ,
94105 ITimeFactory $ timeFactory ,
95106 PredefinedStatusService $ defaultStatusService ,
96- EmojiService $ emojiService ) {
107+ EmojiService $ emojiService ,
108+ IConfig $ config ) {
97109 $ this ->mapper = $ mapper ;
98110 $ this ->timeFactory = $ timeFactory ;
99111 $ this ->predefinedStatusService = $ defaultStatusService ;
100112 $ this ->emojiService = $ emojiService ;
113+ $ this ->shareeEnumeration = $ config ->getAppValue ('core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' ) === 'yes ' ;
114+ $ this ->shareeEnumerationInGroupOnly = $ this ->shareeEnumeration && $ config ->getAppValue ('core ' , 'shareapi_restrict_user_enumeration_to_group ' , 'no ' ) === 'yes ' ;
115+ $ this ->shareeEnumerationPhone = $ this ->shareeEnumeration && $ config ->getAppValue ('core ' , 'shareapi_restrict_user_enumeration_to_phone ' , 'no ' ) === 'yes ' ;
101116 }
102117
103118 /**
@@ -106,6 +121,13 @@ public function __construct(UserStatusMapper $mapper,
106121 * @return UserStatus[]
107122 */
108123 public function findAll (?int $ limit = null , ?int $ offset = null ): array {
124+ // Return empty array if user enumeration is disabled or limited to groups
125+ // TODO: find a solution that scales to get only users from common groups if user enumeration is limited to
126+ // groups. See discussion at https://github.com/nextcloud/server/pull/27879#discussion_r729715936
127+ if (!$ this ->shareeEnumeration || $ this ->shareeEnumerationInGroupOnly || $ this ->shareeEnumerationPhone ) {
128+ return [];
129+ }
130+
109131 return array_map (function ($ status ) {
110132 return $ this ->processStatus ($ status );
111133 }, $ this ->mapper ->findAll ($ limit , $ offset ));
@@ -117,6 +139,13 @@ public function findAll(?int $limit = null, ?int $offset = null): array {
117139 * @return array
118140 */
119141 public function findAllRecentStatusChanges (?int $ limit = null , ?int $ offset = null ): array {
142+ // Return empty array if user enumeration is disabled or limited to groups
143+ // TODO: find a solution that scales to get only users from common groups if user enumeration is limited to
144+ // groups. See discussion at https://github.com/nextcloud/server/pull/27879#discussion_r729715936
145+ if (!$ this ->shareeEnumeration || $ this ->shareeEnumerationInGroupOnly || $ this ->shareeEnumerationPhone ) {
146+ return [];
147+ }
148+
120149 return array_map (function ($ status ) {
121150 return $ this ->processStatus ($ status );
122151 }, $ this ->mapper ->findAllRecent ($ limit , $ offset ));
@@ -224,7 +253,7 @@ public function setPredefinedMessage(string $userId,
224253 /**
225254 * @param string $userId
226255 * @param string|null $statusIcon
227- * @param string|null $message
256+ * @param string $message
228257 * @param int|null $clearAt
229258 * @return UserStatus
230259 * @throws InvalidClearAtException
@@ -332,7 +361,7 @@ public function removeUserStatus(string $userId): bool {
332361 * up to date and provides translated default status if needed
333362 *
334363 * @param UserStatus $status
335- * @returns UserStatus
364+ * @return UserStatus
336365 */
337366 private function processStatus (UserStatus $ status ): UserStatus {
338367 $ clearAt = $ status ->getClearAt ();
0 commit comments