poc: allow code review only for admin
This commit is contained in:
parent
c3f269798f
commit
e984966a9d
1 changed files with 33 additions and 7 deletions
|
|
@ -1315,18 +1315,44 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
|
|||
ai_user = User.get_ai_user()
|
||||
ai_user_id = ai_user.user_id
|
||||
|
||||
ids_to_add, ids_to_remove = self._update_reviewers(
|
||||
members_ = controls["review_members"]
|
||||
for i, member_data in enumerate(members_):
|
||||
user_id = safe_int(member_data.get("user_id", -1))
|
||||
|
||||
if ai_user_id == user_id:
|
||||
admin_permissions = (
|
||||
"repository.admin",
|
||||
"hg.admin",
|
||||
)
|
||||
is_admin = h.HasRepoPermissionAny(*admin_permissions)(
|
||||
user=self._rhodecode_user, repo_name=pull_request.target_repo.repo_name
|
||||
)
|
||||
|
||||
if is_admin:
|
||||
log.debug("Initiating code review for pull request id: %s", pull_request.pull_request_id)
|
||||
run_task(tasks.start_ai_code_review, pull_request.pull_request_id)
|
||||
msg = _("AI code review has started. The review will be ready in about 1–3 minutes.")
|
||||
h.flash(msg, category="success")
|
||||
else:
|
||||
log.debug("AI code review canceled, only admin can initiate AI code review.")
|
||||
msg = _(
|
||||
"AI code review is not available. This feature is in BETA and can only be initiated by an admin."
|
||||
)
|
||||
h.flash(
|
||||
msg,
|
||||
category="warning",
|
||||
)
|
||||
del members_[i]
|
||||
|
||||
break
|
||||
|
||||
self._update_reviewers(
|
||||
c,
|
||||
pull_request,
|
||||
controls["review_members"],
|
||||
members_,
|
||||
pull_request.reviewer_data,
|
||||
PullRequestReviewers.ROLE_REVIEWER,
|
||||
)
|
||||
if ai_user_id in ids_to_add:
|
||||
log.debug("Initiating code review for pull request id: %s", pull_request.pull_request_id)
|
||||
run_task(tasks.start_ai_code_review, pull_request.pull_request_id)
|
||||
msg = _("AI code review has started. The review will be ready in about 1–3 minutes.")
|
||||
h.flash(msg, category="success")
|
||||
|
||||
elif "observer_members" in controls:
|
||||
self._update_reviewers(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue