FIX 版本库更新、创建、删除文件的权限问题
This commit is contained in:
parent
3becb4eabc
commit
72ba784e70
|
@ -66,7 +66,7 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def create_file
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user, content_params)
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @project.owner.login, content_params)
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
create_new_pr(params)
|
||||
|
@ -76,7 +76,7 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def update_file
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user, params.merge(identifier: @project.identifier))
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
create_new_pr(params)
|
||||
|
@ -87,7 +87,7 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def delete_file
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user, params.merge(identifier: @project.identifier))
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
render_result(1, "文件删除成功")
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
module Gitea
|
||||
class CreateFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@owner = owner
|
||||
@params = params
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,7 @@ module Gitea
|
|||
|
||||
def run
|
||||
Contents::CreateForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::CreateService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::CreateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||
|
@ -33,7 +33,7 @@ module Gitea
|
|||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
@error = error
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
module Gitea
|
||||
class DeleteFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@params = params
|
||||
end
|
||||
|
||||
|
@ -23,7 +24,7 @@ module Gitea
|
|||
|
||||
def run
|
||||
Contents::DeleteForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::DeleteService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
|
@ -31,7 +32,7 @@ module Gitea
|
|||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
module Gitea
|
||||
class UpdateFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@owner = owner
|
||||
@token = token
|
||||
@params = params
|
||||
end
|
||||
|
||||
|
@ -23,7 +24,7 @@ module Gitea
|
|||
|
||||
def run
|
||||
Contents::UpdateForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::UpdateService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
|
@ -31,7 +32,7 @@ module Gitea
|
|||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
|
@ -20,11 +20,12 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
|||
# "new_branch": "string"
|
||||
# }
|
||||
#
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
@body = bodys
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -33,11 +34,11 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
|||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
|
@ -19,8 +19,9 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
|||
# "new_branch": "string",
|
||||
# "sha": "string", #require
|
||||
# }
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
|
@ -32,11 +33,11 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
|||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
|
@ -20,8 +20,9 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
|||
# "new_branch": "string"
|
||||
# }
|
||||
#
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
|
@ -33,11 +34,11 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
|||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue