@@ -192,7 +192,7 @@ func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, opts
192192 }
193193 protectBranch .MergeWhitelistUserIDs = whitelist
194194
195- whitelist , err = updateUserWhitelist (repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
195+ whitelist , err = updateApprovalWhitelist (repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
196196 if err != nil {
197197 return err
198198 }
@@ -298,6 +298,27 @@ func (repo *Repository) IsProtectedBranchForMerging(pr *PullRequest, branchName
298298 return false , nil
299299}
300300
301+ // updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with
302+ // the users from newWhitelist which have explicit read or write access to the repo.
303+ func updateApprovalWhitelist (repo * Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
304+ hasUsersChanged := ! util .IsSliceInt64Eq (currentWhitelist , newWhitelist )
305+ if ! hasUsersChanged {
306+ return currentWhitelist , nil
307+ }
308+
309+ whitelist = make ([]int64 , 0 , len (newWhitelist ))
310+ for _ , userID := range newWhitelist {
311+ if reader , err := repo .IsReader (userID ); err != nil {
312+ return nil , err
313+ } else if ! reader {
314+ continue
315+ }
316+ whitelist = append (whitelist , userID )
317+ }
318+
319+ return
320+ }
321+
301322// updateUserWhitelist checks whether the user whitelist changed and returns a whitelist with
302323// the users from newWhitelist which have write access to the repo.
303324func updateUserWhitelist (repo * Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
0 commit comments