修改commits报错

This commit is contained in:
sylor_huang@126.com 2020-06-02 15:48:31 +08:00
commit d1089a4a4b
3 changed files with 12 additions and 13 deletions

View File

@ -9,4 +9,9 @@ module OperateProjectAbilityAble
render_forbidden('你没有权限操作.') render_forbidden('你没有权限操作.')
end end
def authorizate_user_can_edit_repo!
return if @repo.project.manager?(current_user) || current_user.admin?
render_forbidden('你没有权限操作.')
end
end end

View File

@ -2,11 +2,10 @@ class RepositoriesController < ApplicationController
include ApplicationHelper include ApplicationHelper
include OperateProjectAbilityAble include OperateProjectAbilityAble
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror] before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
before_action :find_project, except: [:tags, :commit] before_action :find_project, except: [:tags, :commit, :sync_mirror]
before_action :authorizate!, except: [:sync_mirror, :tags, :commit] before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
before_action :find_repository, only: %i[sync_mirror tags] before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
before_action :authorizate_user_can_edit_project!, only: %i[sync_mirror] before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
before_action :find_repository_by_id, only: %i[commit]
def show def show
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size @branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
@ -45,8 +44,8 @@ class RepositoriesController < ApplicationController
end end
def commits def commits
@create_user = @project.owner @project_owner = @project.owner
@hash_commit = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, @hash_commit = Gitea::Repository::Commits::ListService.new(@project_owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
end end
@ -113,7 +112,7 @@ class RepositoriesController < ApplicationController
def sync_mirror def sync_mirror
@repo&.mirror.set_status!(Mirror.statuses[:waiting]) @repo&.mirror.set_status!(Mirror.statuses[:waiting])
SyncMirroredRepositoryJob(@repo, current_user) SyncMirroredRepositoryJob.perform_later(@repo, current_user)
render_ok render_ok
end end
@ -124,10 +123,6 @@ class RepositoriesController < ApplicationController
render_not_found("未找到相关的仓库") unless @project render_not_found("未找到相关的仓库") unless @project
end end
def find_repository
@repo = Repository.find params[:id]
end
def authorizate! def authorizate!
if @project.repository.hidden? && !@project.member?(current_user) if @project.repository.hidden? && !@project.member?(current_user)
render_forbidden render_forbidden

View File

@ -9,8 +9,7 @@ else
json.message commit['commit']['message'] json.message commit['commit']['message']
json.timestamp render_unix_time(commit['commit']['author']['date']) json.timestamp render_unix_time(commit['commit']['author']['date'])
json.time_from_now time_from_now(commit['commit']['author']['date']) json.time_from_now time_from_now(commit['commit']['author']['date'])
json.partial! 'author', locals: {user: @create_user} json.partial! 'author', user: @project_owner
end end
end end
end end