2929use Sabre \DAV \INode ;
3030use Sabre \DAV \PropFind ;
3131
32+ /**
33+ * @psalm-import-type Rule from RuleService
34+ */
3235class ApprovalService {
3336
3437 public function __construct (
@@ -162,7 +165,7 @@ public function getUserRules(string $userId, string $role = 'requesters', ?int $
162165 * Check if a user is authorized to approve or request by a given rule
163166 *
164167 * @param string $userId
165- * @param array $rule
168+ * @param Rule $rule
166169 * @param string $role
167170 * @return bool
168171 */
@@ -178,7 +181,7 @@ private function userIsAuthorizedByRule(string $userId, array $rule, string $rol
178181 }));
179182
180183 // if user is in rule's user list
181- if (in_array ($ userId , $ ruleUserIds )) {
184+ if (in_array ($ userId , $ ruleUserIds, true )) {
182185 return true ;
183186 } else {
184187 // if user is member of one rule's group list
@@ -295,15 +298,15 @@ public function getApprovalState(int $fileId, ?string $userId, bool $userHasAcce
295298 $ rules = $ this ->ruleService ->getRules ();
296299
297300 // Get all tags a file has to prevent needing to check for each tag in every rule
298- $ tags = $ this ->tagObjectMapper ->getTagIdsForObjects ([$ fileId ], 'files ' );
299- if (!array_key_exists ($ fileId , $ tags )) {
301+ $ tags = $ this ->tagObjectMapper ->getTagIdsForObjects ([( string ) $ fileId ], 'files ' );
302+ if (!array_key_exists (( string ) $ fileId , $ tags )) {
300303 return ['state ' => Application::STATE_NOTHING ];
301304 }
302- $ tags = $ tags [$ fileId ];
305+ $ tags = array_map ( static fn ( $ tag ): string => ( string ) $ tag , $ tags [( string ) $ fileId ]) ;
303306
304307 // first check if it's approvable
305308 foreach ($ rules as $ id => $ rule ) {
306- if (in_array ($ rule ['tagPending ' ], $ tags )
309+ if (in_array ($ rule ['tagPending ' ], $ tags, true )
307310 && $ this ->userIsAuthorizedByRule ($ userId , $ rule , 'approvers ' )) {
308311 return [
309312 'state ' => Application::STATE_APPROVABLE ,
@@ -314,7 +317,7 @@ public function getApprovalState(int $fileId, ?string $userId, bool $userHasAcce
314317
315318 // then check pending in priority
316319 foreach ($ rules as $ id => $ rule ) {
317- if (in_array ($ rule ['tagPending ' ], $ tags )) {
320+ if (in_array ($ rule ['tagPending ' ], $ tags, true )) {
318321 return [
319322 'state ' => Application::STATE_PENDING ,
320323 'rule ' => $ rule ,
@@ -323,7 +326,7 @@ public function getApprovalState(int $fileId, ?string $userId, bool $userHasAcce
323326 }
324327 // then rejected
325328 foreach ($ rules as $ id => $ rule ) {
326- if (in_array ($ rule ['tagRejected ' ], $ tags )) {
329+ if (in_array ($ rule ['tagRejected ' ], $ tags, true )) {
327330 return [
328331 'state ' => Application::STATE_REJECTED ,
329332 'rule ' => $ rule ,
@@ -332,7 +335,7 @@ public function getApprovalState(int $fileId, ?string $userId, bool $userHasAcce
332335 }
333336 // then approved
334337 foreach ($ rules as $ id => $ rule ) {
335- if (in_array ($ rule ['tagApproved ' ], $ tags )) {
338+ if (in_array ($ rule ['tagApproved ' ], $ tags, true )) {
336339 return [
337340 'state ' => Application::STATE_APPROVED ,
338341 'rule ' => $ rule ,
@@ -522,7 +525,7 @@ public function requestViaTagAssignment(int $fileId, int $ruleId, string $reques
522525 * Share file with everybody who can approve with given rule and have no access yet
523526 *
524527 * @param int $fileId
525- * @param array $rule
528+ * @param Rule $rule
526529 * @param string $userId
527530 * @return array list of created shares
528531 * @throws \OCP\Files\NotPermittedException
@@ -646,15 +649,15 @@ public function getRuleAuthorizedUserIds(array $rule, string $role = 'approvers'
646649 $ ruleUserIds = [];
647650 foreach ($ rule [$ role ] as $ approver ) {
648651 if ($ approver ['type ' ] === 'user ' ) {
649- if (!in_array ($ approver ['entityId ' ], $ ruleUserIds )) {
652+ if (!in_array ($ approver ['entityId ' ], $ ruleUserIds, true )) {
650653 $ ruleUserIds [] = $ approver ['entityId ' ];
651654 }
652655 } elseif ($ approver ['type ' ] === 'group ' ) {
653656 $ groupId = $ approver ['entityId ' ];
654657 if ($ this ->groupManager ->groupExists ($ groupId )) {
655658 $ users = $ this ->groupManager ->get ($ groupId )->getUsers ();
656659 foreach ($ users as $ user ) {
657- if ($ user instanceof IUser && !in_array ($ user ->getUID (), $ ruleUserIds )) {
660+ if ($ user instanceof IUser && !in_array ($ user ->getUID (), $ ruleUserIds, true )) {
658661 $ ruleUserIds [] = $ user ->getUID ();
659662 }
660663 }
@@ -670,7 +673,7 @@ public function getRuleAuthorizedUserIds(array $rule, string $role = 'approvers'
670673 continue ;
671674 }
672675 $ memberUserId = $ member ->getUserId ();
673- if (!in_array ($ memberUserId , $ ruleUserIds )) {
676+ if (!in_array ($ memberUserId , $ ruleUserIds, true )) {
674677 $ ruleUserIds [] = $ memberUserId ;
675678 }
676679 }
@@ -698,7 +701,7 @@ public function handleTagAssignmentEvent(int $fileId, array $tags): void {
698701 $ rules = $ this ->ruleService ->getRules ();
699702 foreach ($ rules as $ id => $ rule ) {
700703 // rule matches tags
701- if (in_array ($ rule ['tagPending ' ], $ tags )) {
704+ if (in_array ($ rule ['tagPending ' ], $ tags, true )) {
702705 $ ruleInvolded = $ rule ;
703706 break ;
704707 }
@@ -742,7 +745,7 @@ public function handleTagAssignmentEvent(int $fileId, array $tags): void {
742745 * Send it to all users who are authorized to approve it
743746 *
744747 * @param int $fileId
745- * @param array $rule
748+ * @param Rule $rule
746749 * @param string $requestUserId
747750 * @return void
748751 */
@@ -751,7 +754,7 @@ public function sendRequestNotification(int $fileId, array $rule, string $reques
751754 $ rulesUserIds = [];
752755 $ thisRuleUserIds = $ this ->getRuleAuthorizedUserIds ($ rule , 'approvers ' );
753756 foreach ($ thisRuleUserIds as $ userId ) {
754- if (!in_array ($ userId , $ rulesUserIds )) {
757+ if (!in_array ($ userId , $ rulesUserIds, true )) {
755758 $ rulesUserIds [] = $ userId ;
756759 }
757760 }
0 commit comments