Browse Source

新增: fork仓库协作者可以提交文件至仓库

pull/313/head
yystopf 3 years ago
parent
commit
096b0b954d
2 changed files with 10 additions and 3 deletions
  1. +7
    -0
      app/controllers/api/v1/base_controller.rb
  2. +3
    -3
      app/controllers/api/v1/projects/contents_controller.rb

+ 7
- 0
app/controllers/api/v1/base_controller.rb View File

@@ -40,6 +40,13 @@ class Api::V1::BaseController < ApplicationController
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
end

# 具有仓库的操作权限或者fork仓库的操作权限
def require_operate_above_or_fork_project
@project = load_project
puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
end

# 具有对仓库的访问权限
def require_public_and_member_above
@project = load_project


+ 3
- 3
app/controllers/api/v1/projects/contents_controller.rb View File

@@ -1,13 +1,13 @@
class Api::V1::Projects::ContentsController < Api::V1::BaseController
before_action :require_operate_above, only: [:batch]
before_action :require_operate_above_or_fork_project, only: [:batch]

def batch
@batch_content_params = batch_content_params
# 处理下author和committer信息,如果没传则默认为当前用户信息
@batch_content_params.merge!(author_email: current_user.mail, author_name: current_user.login) if batch_content_params[:author_email].blank? && batch_content_params[:author_name].blank?
@batch_content_params.merge!(committer_email: current_user.mail, committer_name: current_user.login) if batch_content_params[:committer_email].blank? && batch_content_params[:committer_name].blank?
@result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, current_user&.gitea_token)
puts @result_object
@result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, @project.owner.gitea_token)
end

private


Loading…
Cancel
Save