Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop
This commit is contained in:
commit
d8dbea60eb
|
@ -5,7 +5,7 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
search = params[:search].to_s.strip
|
||||
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
projects = Project.where("name like ? OR identifier LIKE ?", "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
|
|
|
@ -67,7 +67,18 @@ class Organizations::TeamsController < Organizations::BaseController
|
|||
tip_exception("组织团队不允许被删除") if @team.owner?
|
||||
ActiveRecord::Base.transaction do
|
||||
Gitea::Organization::Team::DeleteService.call(@organization.gitea_token, @team.gtid)
|
||||
other_user_ids = @organization.team_users.where.not(team_id: @team.id).pluck(:user_id)
|
||||
team_user_ids = @team.team_users.pluck(:user_id)
|
||||
# 当前删除团队中成员在其他组织其他团队不存在的成员需清除组织
|
||||
remove_user_ids = team_user_ids - other_user_ids
|
||||
Rails.logger.info "remove_user_ids ===========> #{remove_user_ids}"
|
||||
@team.destroy!
|
||||
if remove_user_ids.present?
|
||||
User.where(id: remove_user_ids).each do |user|
|
||||
@organization.organization_users.find_by(user_id: user.id).destroy!
|
||||
Gitea::Organization::OrganizationUser::DeleteService.call(@organization.gitea_token, @organization.login, user.login)
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
|
|
|
@ -43,7 +43,8 @@ class ProjectsController < ApplicationController
|
|||
@total_count =
|
||||
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
|
||||
# 默认查询时count性能问题处理
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count
|
||||
not_category_count = Project.where(project_category_id: nil).count
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count
|
||||
elsif params[:search].present? || params[:topic_id].present?
|
||||
@projects.total_count
|
||||
else
|
||||
|
@ -59,7 +60,10 @@ class ProjectsController < ApplicationController
|
|||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
||||
UpdateProjectTopicJob.perform_later(@project.id) if @project.id.present?
|
||||
end
|
||||
rescue Exception => e
|
||||
rescue Gitea::Api::ServerError => ex
|
||||
uid_logger_error(ex.message)
|
||||
tip_exception(ex.http_code, ex.message)
|
||||
rescue ApplicationService::Error => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
|
|
@ -64,10 +64,9 @@ class RepositoriesController < ApplicationController
|
|||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||
else
|
||||
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
|
||||
return render_not_found if @entries.is_a?(Array) && @entries.blank?
|
||||
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
|
||||
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||
@repo_detail = $gitea_client.get_repos_by_owner_repo(@owner.login, @project.identifier)
|
||||
return render_not_found if @entries.blank? && !@repo_detail["empty"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class VersionReleasesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :load_repository
|
||||
before_action :set_user
|
||||
before_action :require_login, except: [:index, :show]
|
||||
|
@ -126,6 +127,16 @@ class VersionReleasesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def download
|
||||
tip_exception(404, '您访问的页面不存在或已被删除') if params["tag_name"].blank? || params["filename"].blank?
|
||||
version = @repository.version_releases.find_by(tag_name: params["tag_name"])
|
||||
attachment = version.attachments.find_by(filename: params["filename"])
|
||||
tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank?
|
||||
send_file(absolute_path(local_path(attachment)), filename: attachment.title, stream: false, type: attachment.content_type.presence || 'application/octet-stream')
|
||||
update_downloads(attachment)
|
||||
# redirect_to "/api/attachments/#{attachment.uuid}"
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_user
|
||||
|
|
|
@ -28,7 +28,7 @@ class Page < ApplicationRecord
|
|||
belongs_to :project
|
||||
|
||||
# language_frame 前端语言框架
|
||||
enum language_frame: { hugo: 0, jekyll: 1, hexo: 2}
|
||||
enum language_frame: { hugo: 0, jekyll: 1, hexo: 2, files: 3}
|
||||
|
||||
after_create do
|
||||
PageService.genernate_user(user_id)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#
|
||||
|
||||
class PageTheme < ApplicationRecord
|
||||
enum language_frame: { hugo: 0, jeklly: 1, hexo: 2}
|
||||
enum language_frame: { hugo: 0, jeklly: 1, hexo: 2, files:3}
|
||||
validates :name, presence: {message: "主题名不能为空"}, uniqueness: {message: "主题名已存在",scope: :language_frame},length: {maximum: 255}
|
||||
|
||||
def image
|
||||
|
|
|
@ -90,6 +90,8 @@ class Project < ApplicationRecord
|
|||
include ProjectOperable
|
||||
include Dcodes
|
||||
|
||||
default_scope {where.not(id: 0)}
|
||||
|
||||
# common:开源托管项目
|
||||
# mirror:普通镜像项目,没有定时同步功能
|
||||
# sync_mirror:同步镜像项目,有系统定时同步功能,且用户可手动同步操作
|
||||
|
|
|
@ -23,6 +23,7 @@ class ProjectUnit < ApplicationRecord
|
|||
|
||||
def self.init_types(project_id, project_type='common')
|
||||
unit_types = project_type == 'sync_mirror' ? ProjectUnit::unit_types.except("pulls") : ProjectUnit::unit_types
|
||||
unit_types = unit_types.except("dataset")
|
||||
unit_types.each do |_, v|
|
||||
self.create!(project_id: project_id, unit_type: v)
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ class PageService
|
|||
repo_link = project.repository.url
|
||||
repo = project.repository.identifier
|
||||
branch = branch
|
||||
script_path =page.build_script_path
|
||||
script_path = branch == "gh-pages" ? "files_build" : page.build_script_path
|
||||
if script_path.present?
|
||||
uri = URI.parse("http://gitlink.#{@deploy_domain}/gitlink_execute_script?key=#{@deploy_key}&script_path=#{script_path}&project_dir=#{project_dir}&repo=#{repo}&repo_link=#{repo_link}&branch=#{branch}&owner=#{owner}")
|
||||
response = Net::HTTP.get_response(uri)
|
||||
|
|
|
@ -26,9 +26,6 @@ class Projects::CreateService < ApplicationService
|
|||
end
|
||||
end
|
||||
@project
|
||||
rescue => e
|
||||
puts "create project service error: #{e.message}"
|
||||
raise Error, e.message
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -33,18 +33,17 @@ class Repositories::CreateService < ApplicationService
|
|||
end
|
||||
repository
|
||||
end
|
||||
rescue => e
|
||||
puts "create repository service error: #{e.message}"
|
||||
raise Error, e.message
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_gitea_repository
|
||||
if project.owner.is_a?(User)
|
||||
@gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||
# @gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||
@gitea_repository = $gitea_client.post_user_repos({query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
||||
elsif project.owner.is_a?(Organization)
|
||||
@gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
||||
# @gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
||||
@gitea_repository = $gitea_client.post_orgs_repos_by_org(project.owner.login, {query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<label>
|
||||
建站工具 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<% state_options = [['hugo', "hugo"], ['jeklly', "jeklly"],['hexo',"hexo"]] %>
|
||||
<% state_options = [['hugo', "hugo"], ['jeklly', "jeklly"],['hexo',"hexo"],['files',"files"]] %>
|
||||
<%= select_tag('page_theme[language_frame]', options_for_select(state_options), class: 'form-control') %>
|
||||
</div>
|
||||
<% end%>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<%= form_tag(admins_page_themes_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<div class="form-group mr-2">
|
||||
<label for="language_frame">建站工具:</label>
|
||||
<% state_options = [['全部',nil], ['hugo', 0], ['jeklly', 1],['hexo',2]] %>
|
||||
<% state_options = [['全部',nil], ['hugo', 0], ['jeklly', 1],['hexo',2],['files',3]] %>
|
||||
<%= select_tag(:language_frame, options_for_select(state_options), class: 'form-control') %>
|
||||
</div>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '项目名称检索') %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '项目名称/标识检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
|
|
|
@ -36,7 +36,8 @@ json.setting do
|
|||
|
||||
json.subject_banner_url default_setting.subject_banner_url&.[](1..-1)
|
||||
json.course_banner_url default_setting.course_banner_url&.[](1..-1)
|
||||
json.competition_banner_url default_setting.competition_banner_url&.[](1..-1)
|
||||
json.competition_banner_url EduSetting.get("competition_banner_url").to_s
|
||||
json.competition_banner_href EduSetting.get("competition_banner_href").to_s
|
||||
json.moop_cases_banner_url default_setting.moop_cases_banner_url&.[](1..-1)
|
||||
json.oj_banner_url default_setting.oj_banner_url&.[](1..-1)
|
||||
|
||||
|
|
|
@ -16,6 +16,12 @@ json.user_login user&.login
|
|||
json.image_url user.present? ? url_to_avatar(user) : ""
|
||||
json.attachments do
|
||||
json.array! version.try(:attachments) do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
# json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
json.id attachment.id
|
||||
json.title attachment.title
|
||||
json.filesize number_to_human_size attachment.filesize
|
||||
json.description attachment.description
|
||||
json.is_pdf attachment.is_pdf?
|
||||
json.url "/#{@owner.login}/#{@repository.identifier}/releases/download/#{version&.tag_name}/#{attachment.filename}"
|
||||
end
|
||||
end
|
|
@ -19,6 +19,7 @@ Rails.application.routes.draw do
|
|||
get 'attachments/entries/get_file', to: 'attachments#get_file'
|
||||
get 'attachments/download/:id', to: 'attachments#show'
|
||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||
get ':owner/:repo/releases/download/:tag_name/:filename', to: 'version_releases#download', constraints: { repo: /[^\/]+/, tag_name: /[^\/]+/, filename: /[^\/]+/ }
|
||||
get 'check_pr_url',to: "settings#check_url"
|
||||
|
||||
# get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||
|
|
Loading…
Reference in New Issue