forked from Gitlink/forgeplus
新增: 合并请求创建审查接口
This commit is contained in:
parent
5db43bf768
commit
5463c22518
|
@ -31,18 +31,18 @@ class Api::V1::BaseController < ApplicationController
|
|||
# 具有对仓库的管理权限
|
||||
def require_manager_above
|
||||
@project = load_project
|
||||
return render_forbidden unless current_user.admin? && @project.manager?(current_user)
|
||||
return render_forbidden if !current_user.admin? && !@project.manager?(current_user)
|
||||
end
|
||||
|
||||
# 具有对仓库的操作权限
|
||||
def require_operate_above
|
||||
@project = load_project
|
||||
return render_forbidden unless current_user.admin? && @project.operator?(current_user)
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
|
||||
end
|
||||
|
||||
# 具有对仓库的访问权限
|
||||
def require_public_and_member_above
|
||||
@project = load_project
|
||||
return render_forbidden unless @project.is_public || (current_user.admin? && @project.member?(current_user))
|
||||
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
|
||||
end
|
||||
end
|
|
@ -4,4 +4,20 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba
|
|||
@reviews = @pull_request.reviews
|
||||
@reviews = kaminari_paginate(@reviews)
|
||||
end
|
||||
|
||||
before_action :require_reviewer, only: [:create]
|
||||
|
||||
def create
|
||||
@journal, @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user)
|
||||
end
|
||||
|
||||
private
|
||||
def require_reviewer
|
||||
puts @pull_request.reviewers.exists?(current_user.id)
|
||||
return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id)
|
||||
end
|
||||
|
||||
def review_params
|
||||
params.require(:review).permit(:content, :commit_id, :status)
|
||||
end
|
||||
end
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
class Review < ApplicationRecord
|
||||
|
||||
belongs_to :issue
|
||||
belongs_to :pull_request
|
||||
belongs_to :reviewer, class_name: 'User', foreign_key: :reviewer_id
|
||||
has_one :journal, dependent: :destroy
|
||||
|
||||
|
|
|
@ -24,17 +24,17 @@ class Api::V1::Projects::Pulls::Reviews::CreateService < ApplicationService
|
|||
end
|
||||
|
||||
return @journal, @review
|
||||
rescue
|
||||
raise Error, '服务器错误,请联系系统管理员!'
|
||||
# rescue
|
||||
# raise Error, '服务器错误,请联系系统管理员!'
|
||||
end
|
||||
|
||||
private
|
||||
def create_review
|
||||
@review = issue.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id)
|
||||
@review = pull_request.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id)
|
||||
end
|
||||
|
||||
def create_journal
|
||||
@journal = issue.journals.create!(notes: content, user_id: @current_user.id, review_id: @review.id)
|
||||
@journal = pull_request.journals.create!(notes: content, user_id: @current_user.id, review_id: @review.id)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
json.reviewer do
|
||||
json.partial! "api/v1/users/simple_user", user: @review.reviewer
|
||||
end
|
||||
json.pull_request do
|
||||
json.partial! "api/v1/projects/pulls/simple_detail", pull: @review.pull_request
|
||||
end
|
||||
json.(@review, :id, :commit_id, :content, :status)
|
||||
json.created_at format_time(@review.created_at)
|
|
@ -25,6 +25,7 @@ defaults format: :json do
|
|||
get :diff
|
||||
end
|
||||
end
|
||||
resources :reviews, only: [:index, :create]
|
||||
end
|
||||
|
||||
resources :versions
|
||||
|
|
Loading…
Reference in New Issue