##// END OF EJS Templates
pull-requests: fixed a bug in removal of multiple reviewers
marcink -
r3575:a4085180 stable
parent child Browse files
Show More
@@ -1020,6 +1020,9 b' class PullRequestModel(BaseModel):'
1020 1020 log.debug("Adding %s reviewers", ids_to_add)
1021 1021 log.debug("Removing %s reviewers", ids_to_remove)
1022 1022 changed = False
1023 added_audit_reviewers = []
1024 removed_audit_reviewers = []
1025
1023 1026 for uid in ids_to_add:
1024 1027 changed = True
1025 1028 _usr = self._get_user(uid)
@@ -1030,29 +1033,37 b' class PullRequestModel(BaseModel):'
1030 1033 # NOTE(marcink): mandatory shouldn't be changed now
1031 1034 # reviewer.mandatory = reviewers[uid]['reasons']
1032 1035 Session().add(reviewer)
1033 self._log_audit_action(
1034 'repo.pull_request.reviewer.add', {'data': reviewer.get_dict()},
1035 user, pull_request)
1036 added_audit_reviewers.append(reviewer.get_dict())
1036 1037
1037 1038 for uid in ids_to_remove:
1038 1039 changed = True
1040 # NOTE(marcink): we fetch "ALL" reviewers using .all(). This is an edge case
1041 # that prevents and fixes cases that we added the same reviewer twice.
1042 # this CAN happen due to the lack of DB checks
1039 1043 reviewers = PullRequestReviewers.query()\
1040 1044 .filter(PullRequestReviewers.user_id == uid,
1041 1045 PullRequestReviewers.pull_request == pull_request)\
1042 1046 .all()
1043 # use .all() in case we accidentally added the same person twice
1044 # this CAN happen due to the lack of DB checks
1047
1045 1048 for obj in reviewers:
1046 old_data = obj.get_dict()
1049 added_audit_reviewers.append(obj.get_dict())
1047 1050 Session().delete(obj)
1048 self._log_audit_action(
1049 'repo.pull_request.reviewer.delete',
1050 {'old_data': old_data}, user, pull_request)
1051 1051
1052 1052 if changed:
1053 Session().expire_all()
1053 1054 pull_request.updated_on = datetime.datetime.now()
1054 1055 Session().add(pull_request)
1055 1056
1057 # finally store audit logs
1058 for user_data in added_audit_reviewers:
1059 self._log_audit_action(
1060 'repo.pull_request.reviewer.add', {'data': user_data},
1061 user, pull_request)
1062 for user_data in removed_audit_reviewers:
1063 self._log_audit_action(
1064 'repo.pull_request.reviewer.delete', {'old_data': user_data},
1065 user, pull_request)
1066
1056 1067 self.notify_reviewers(pull_request, ids_to_add)
1057 1068 return ids_to_add, ids_to_remove
1058 1069
General Comments 0
You need to be logged in to leave comments. Login now