Merge pull request 'FIX bug' (#148) from develop into dev_trustie_server
This commit is contained in:
commit
00ed177089
|
@ -761,10 +761,10 @@ class ApplicationController < ActionController::Base
|
||||||
if @project and current_user.can_read_project?(@project)
|
if @project and current_user.can_read_project?(@project)
|
||||||
logger.info "###########: has project and can read project"
|
logger.info "###########: has project and can read project"
|
||||||
@project
|
@project
|
||||||
elsif @project && current_user.is_a?(AnonymousUser)
|
# elsif @project && current_user.is_a?(AnonymousUser)
|
||||||
logger.info "###########:This is AnonymousUser"
|
# logger.info "###########:This is AnonymousUser"
|
||||||
@project = nil if !@project.is_public?
|
# @project = nil if !@project.is_public?
|
||||||
render_forbidden and return
|
# render_forbidden and return
|
||||||
else
|
else
|
||||||
logger.info "###########:project not found"
|
logger.info "###########:project not found"
|
||||||
@project = nil
|
@project = nil
|
||||||
|
|
|
@ -32,8 +32,17 @@ class AttachmentsController < ApplicationController
|
||||||
def get_file
|
def get_file
|
||||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
||||||
response = Faraday.get(url)
|
if url.starts_with?(base_url)
|
||||||
filename = params[:download_url].to_s.split("/").pop()
|
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')
|
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
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 = kaminari_paginate(scope)
|
||||||
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
@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
|
redirect_to file_path
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ module ProjectsHelper
|
||||||
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
||||||
end
|
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)
|
def render_http_url(project)
|
||||||
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
||||||
end
|
end
|
||||||
|
|
|
@ -124,8 +124,8 @@ class Project < ApplicationRecord
|
||||||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||||
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
||||||
|
|
||||||
after_save :check_project_members, :reset_cache_data
|
after_save :check_project_members
|
||||||
before_save :set_invite_code
|
before_save :set_invite_code, :reset_cache_data, :reset_unmember_followed
|
||||||
after_destroy :reset_cache_data
|
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 :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)}
|
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||||
|
@ -134,6 +134,18 @@ class Project < ApplicationRecord
|
||||||
delegate :content, to: :project_detail, allow_nil: true
|
delegate :content, to: :project_detail, allow_nil: true
|
||||||
delegate :name, to: :license, prefix: true, 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
|
def reset_cache_data
|
||||||
if changes[:user_id].present?
|
if changes[:user_id].present?
|
||||||
first_owner = Owner.find_by_id(changes[:user_id].first)
|
first_owner = Owner.find_by_id(changes[:user_id].first)
|
||||||
|
@ -143,6 +155,12 @@ class Project < ApplicationRecord
|
||||||
self.reset_user_cache_async_job(self.owner)
|
self.reset_user_cache_async_job(self.owner)
|
||||||
end
|
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
|
def set_invite_code
|
||||||
if self.invite_code.nil?
|
if self.invite_code.nil?
|
||||||
self.invite_code= self.generate_dcode('invite_code', 6)
|
self.invite_code= self.generate_dcode('invite_code', 6)
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
class Projects::ListQuery < ApplicationQuery
|
class Projects::ListQuery < ApplicationQuery
|
||||||
include CustomSortable
|
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
|
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
|
@params = params
|
||||||
|
@current_user_id = current_user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
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
|
scope = q
|
||||||
.with_project_type(params[:project_type])
|
.with_project_type(params[:project_type])
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Organizations::Teams::UpdateService < ApplicationService
|
||||||
private
|
private
|
||||||
def update_params
|
def update_params
|
||||||
if team.authorize == "owner"
|
if team.authorize == "owner"
|
||||||
update_params = params.slice(:description)
|
update_params = params.slice(:description, :nickname)
|
||||||
else
|
else
|
||||||
update_params = params.slice(:name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project)
|
update_params = params.slice(:name, :nickname, :description, :authorize, :includes_all_project, :can_create_org_project)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Projects::ApplyTransferService < ApplicationService
|
||||||
raise Error, '仓库标识不正确' if @project.identifier != params[:identifier]
|
raise Error, '仓库标识不正确' if @project.identifier != params[:identifier]
|
||||||
raise Error, '该仓库正在迁移' if @project.is_transfering
|
raise Error, '该仓库正在迁移' if @project.is_transfering
|
||||||
raise Error, '新拥有者不存在' unless @owner.present?
|
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, '新拥有者已经存在同名仓库!' if Project.where(user_id: @owner.id, identifier: params[:identifier]).present?
|
||||||
raise Error, '未拥有转移权限' unless is_permit_owner
|
raise Error, '未拥有转移权限' unless is_permit_owner
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,8 @@ if @project.forge?
|
||||||
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
||||||
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
||||||
else
|
else
|
||||||
entry['download_url']
|
# entry['download_url']
|
||||||
|
render_download_file_url(@owner, @repository, entry['path'].to_s, @ref)
|
||||||
end
|
end
|
||||||
json.download_url download_url
|
json.download_url download_url
|
||||||
|
|
||||||
|
|
|
@ -434,6 +434,7 @@ Rails.application.routes.draw do
|
||||||
get 'readme'
|
get 'readme'
|
||||||
get 'languages'
|
get 'languages'
|
||||||
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
||||||
|
get 'raw', to: 'repositories#raw', as: "raw"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue