forked from Trustie/forgeplus
Merge pull request '一些bug修复' (#147) from yystopf/forgeplus:hh_fix_bug into develop
This commit is contained in:
commit
e594c72c43
|
@ -762,10 +762,10 @@ class ApplicationController < ActionController::Base
|
|||
if @project and current_user.can_read_project?(@project)
|
||||
logger.info "###########: has project and can read project"
|
||||
@project
|
||||
elsif @project && current_user.is_a?(AnonymousUser)
|
||||
logger.info "###########:This is AnonymousUser"
|
||||
@project = nil if !@project.is_public?
|
||||
render_forbidden and return
|
||||
# elsif @project && current_user.is_a?(AnonymousUser)
|
||||
# logger.info "###########:This is AnonymousUser"
|
||||
# @project = nil if !@project.is_public?
|
||||
# render_forbidden and return
|
||||
else
|
||||
logger.info "###########:project not found"
|
||||
@project = nil
|
||||
|
|
|
@ -32,8 +32,17 @@ class AttachmentsController < ApplicationController
|
|||
def get_file
|
||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
||||
response = Faraday.get(url)
|
||||
filename = params[:download_url].to_s.split("/").pop()
|
||||
if url.starts_with?(base_url)
|
||||
domain = Gitea.gitea_config[:domain]
|
||||
api_url = Gitea.gitea_config[:base_url]
|
||||
url = url.split(base_url)[1].gsub("api", "repos").gsub('?filepath=', '/').gsub('&', '?')
|
||||
request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join
|
||||
response = Faraday.get(request_url)
|
||||
filename = url.to_s.split("/").pop()
|
||||
else
|
||||
response = Faraday.get(url)
|
||||
filename = params[:download_url].to_s.split("/").pop()
|
||||
end
|
||||
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||
end
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def index
|
||||
scope = Projects::ListQuery.call(params)
|
||||
scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params)
|
||||
|
||||
# @projects = kaminari_paginate(scope)
|
||||
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
|
|
|
@ -205,6 +205,17 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
redirect_to file_path
|
||||
end
|
||||
|
||||
def raw
|
||||
domain = Gitea.gitea_config[:domain]
|
||||
api_url = Gitea.gitea_config[:base_url]
|
||||
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{params[:filepath]}?ref=#{params[:ref]}"
|
||||
file_path = [domain, api_url, url].join
|
||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") if @repository.hidden?
|
||||
|
||||
redirect_to file_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@ module ProjectsHelper
|
|||
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
||||
end
|
||||
|
||||
def render_download_file_url(owner, repository, filepath, ref)
|
||||
[base_url, "/api/#{owner&.login}/#{repository.identifier}/raw?filepath=#{filepath}&ref=#{ref}"].join
|
||||
end
|
||||
|
||||
def render_http_url(project)
|
||||
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
||||
end
|
||||
|
|
|
@ -127,8 +127,8 @@ class Project < ApplicationRecord
|
|||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
||||
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
before_save :set_invite_code
|
||||
after_save :check_project_members
|
||||
before_save :set_invite_code, :reset_cache_data, :reset_unmember_followed
|
||||
after_destroy :reset_cache_data
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
|
@ -137,6 +137,18 @@ class Project < ApplicationRecord
|
|||
delegate :content, to: :project_detail, allow_nil: true
|
||||
delegate :name, to: :license, prefix: true, allow_nil: true
|
||||
|
||||
def self.all_visible(user_id=nil)
|
||||
user_projects_sql = Project.joins(:owner).where(users: {type: 'User'}).to_sql
|
||||
org_public_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'common'})).to_sql
|
||||
if user_id.present?
|
||||
org_limit_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'limited'})).to_sql
|
||||
org_privacy_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension, :organization_users).where(organization_extensions: {visibility: 'privacy'}, organization_users: {user_id: user_id})).to_sql
|
||||
return Project.from("( #{ user_projects_sql } UNION #{ org_public_projects_sql } UNION #{ org_limit_projects_sql } UNION #{org_privacy_projects_sql} ) AS projects").visible
|
||||
else
|
||||
return Project.from("( #{ user_projects_sql } UNION #{ org_public_projects_sql } ) AS projects").visible
|
||||
end
|
||||
end
|
||||
|
||||
def reset_cache_data
|
||||
if changes[:user_id].present?
|
||||
first_owner = Owner.find_by_id(changes[:user_id].first)
|
||||
|
@ -146,6 +158,12 @@ class Project < ApplicationRecord
|
|||
self.reset_user_cache_async_job(self.owner)
|
||||
end
|
||||
|
||||
def reset_unmember_followed
|
||||
if changes[:is_public].present? && changes[:is_public] == [true, false]
|
||||
self.watchers.where.not(user_id: self.all_collaborators).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
def set_invite_code
|
||||
if self.invite_code.nil?
|
||||
self.invite_code= self.generate_dcode('invite_code', 6)
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
class Projects::ListQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
attr_reader :params, :current_user_id
|
||||
|
||||
sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
def initialize(params, current_user_id=nil)
|
||||
@params = params
|
||||
@current_user_id = current_user_id
|
||||
end
|
||||
|
||||
def call
|
||||
q = Project.visible.by_name_or_identifier(params[:search])
|
||||
q = Project.all_visible(current_user_id).by_name_or_identifier(params[:search])
|
||||
|
||||
scope = q
|
||||
.with_project_type(params[:project_type])
|
||||
|
|
|
@ -25,7 +25,7 @@ class Organizations::Teams::UpdateService < ApplicationService
|
|||
private
|
||||
def update_params
|
||||
if team.authorize == "owner"
|
||||
update_params = params.slice(:description)
|
||||
update_params = params.slice(:description, :nickname)
|
||||
else
|
||||
update_params = params.slice(:name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project)
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ class Projects::ApplyTransferService < ApplicationService
|
|||
raise Error, '仓库标识不正确' if @project.identifier != params[:identifier]
|
||||
raise Error, '该仓库正在迁移' if @project.is_transfering
|
||||
raise Error, '新拥有者不存在' unless @owner.present?
|
||||
raise Error, '新拥有者资料不完善' unless @owner.profile_completed
|
||||
raise Error, '新拥有者资料不完善' if @owner.is_a?(User) && !@owner.profile_completed
|
||||
raise Error, '新拥有者已经存在同名仓库!' if Project.where(user_id: @owner.id, identifier: params[:identifier]).present?
|
||||
raise Error, '未拥有转移权限' unless is_permit_owner
|
||||
end
|
||||
|
|
|
@ -17,7 +17,8 @@ if @project.forge?
|
|||
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
||||
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
||||
else
|
||||
entry['download_url']
|
||||
# entry['download_url']
|
||||
render_download_file_url(@owner, @repository, entry['path'].to_s, @ref)
|
||||
end
|
||||
json.download_url download_url
|
||||
|
||||
|
|
|
@ -434,6 +434,7 @@ Rails.application.routes.draw do
|
|||
get 'readme'
|
||||
get 'languages'
|
||||
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
||||
get 'raw', to: 'repositories#raw', as: "raw"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue