fix: issue change operate permission and repository detail remove garbage

This commit is contained in:
yystopf 2021-10-09 09:50:35 +08:00
parent f957b6f95e
commit 46ab55d50f
5 changed files with 22 additions and 61 deletions

View File

@ -15,7 +15,7 @@ class IssuesController < ApplicationController
include TagChosenHelper include TagChosenHelper
def index def index
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user)) @user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user) || @project.is_public?)
issues = @project.issues.issue_issue.issue_index_includes issues = @project.issues.issue_issue.issue_index_includes
issues = issues.where(is_private: false) unless @user_admin_or_member issues = issues.where(is_private: false) unless @user_admin_or_member
@ -453,7 +453,7 @@ class IssuesController < ApplicationController
end end
def operate_issue_permission def operate_issue_permission
return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.member?(current_user) return render_forbidden("您没有权限进行此操作.") unless current_user.present? && current_user.logged? && (current_user.admin? || @project.member?(current_user) || @project.is_public?)
end end
def export_issues(issues) def export_issues(issues)

View File

@ -55,16 +55,6 @@ class RepositoriesController < ApplicationController
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call @entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : [] @entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
# TODO
# 临时处理readme文件问题
result = Gitea::Repository::Readme::GetService.call(@owner.login, @project.identifier, @ref, @owner&.gitea_token)
@readme =
if result[:status] == :success
result[:body]
else
{}
end
end end
end end

View File

@ -8,29 +8,25 @@ class Repositories::DetailService < ApplicationService
end end
def call def call
if @repo.project.educoder? return {
return { repo: repo_suitable,
repo: {}, release: release_suitable,
release: [], branch: branch_suitable,
branch: [], tag: tag_suitable,
branch_type: [], contributor: contributor_suitable,
tag: [], language: language_suitable
contributor: [], }
language: {}, rescue
readme: {} return {
} repo: {},
else release: [],
return { branch: [],
repo: repo_suitable, branch_type: [],
release: release_suitable, tag: [],
branch: branch_suitable, contributor: [],
branch_slice: branch_slice_suitable, language: {},
tag: tag_suitable, readme: {}
contributor: contributor_suitable, }
language: language_suitable,
readme: readme_suitable
}
end
end end
private private
@ -48,11 +44,6 @@ class Repositories::DetailService < ApplicationService
branches.is_a?(Hash) && branches.key?(:status) ? [] : branches branches.is_a?(Hash) && branches.key?(:status) ? [] : branches
end end
def branch_slice_suitable
branches = Gitea::Repository::Branches::ListSliceService.call(@owner, @repo.identifier)
branches.is_a?(Hash) && branches.key?(:status) ? [] : branches
end
def tag_suitable def tag_suitable
tags = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @repo.identifier) tags = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @repo.identifier)
tags.is_a?(Hash) && tags[:status] == -1 ? [] : tags tags.is_a?(Hash) && tags[:status] == -1 ? [] : tags
@ -67,9 +58,4 @@ class Repositories::DetailService < ApplicationService
result = Gitea::Repository::Languages::ListService.call(@owner.login, @repo.identifier, @user&.gitea_token) result = Gitea::Repository::Languages::ListService.call(@owner.login, @repo.identifier, @user&.gitea_token)
result[:status] === :success ? hash_transform_precentagable(result[:body]) : nil result[:status] === :success ? hash_transform_precentagable(result[:body]) : nil
end end
def readme_suitable
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repo.identifier, @repo.default_branch, @owner.gitea_token)
result[:status] === :success ? result[:body] : nil
end
end end

View File

@ -1,11 +1,6 @@
json.content @project.content json.content @project.content
json.website @project.website json.website @project.website
json.lesson_url @project.lesson_url json.lesson_url @project.lesson_url
if @result[:readme].blank?
json.readme nil
else
json.readme @result[:readme].merge(content: readme_render_decode64_content(@result[:readme]["content"], nil))
end
json.identifier render_identifier(@project) json.identifier render_identifier(@project)
json.invite_code @project.invite_code json.invite_code @project.invite_code
json.name @project.name json.name @project.name
@ -72,15 +67,6 @@ json.branches do
end end
json.total_count @result[:branch].size json.total_count @result[:branch].size
end end
json.branches_slice do
json.list @result[:branch_slice].each do |branch_slice|
json.branch_type branch_slice["branch_name"]
json.list branch_slice["branches"].each do |branch|
json.name branch["name"]
end
end
json.total_count @result[:branch_slice].size
end
json.tags do json.tags do
json.list @result[:tag].each do |tag| json.list @result[:tag].each do |tag|
json.name tag["name"] json.name tag["name"]
@ -104,6 +90,6 @@ json.contributors do
end end
json.total_count total_count json.total_count total_count
end end
json.languages @result[:language] json.languages @result[:language].blank? ? nil : @result[:language]
json.partial! 'author', locals: { user: @project.owner } json.partial! 'author', locals: { user: @project.owner }

View File

@ -61,5 +61,4 @@ if @project.forge?
end end
end end
json.readme @readme.merge(content: readme_render_decode64_content(@readme["content"], nil))
end end