Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
db02c1ec6b
|
@ -204,4 +204,14 @@ input.form-control {
|
||||||
color: #23272B;
|
color: #23272B;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.table th, .table td {
|
||||||
|
padding: 0.75rem 0.1rem;
|
||||||
|
vertical-align: top;
|
||||||
|
border-top: 1px solid #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .thead-light th{
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
class Admins::ProjectIgnoresController < Admins::BaseController
|
class Admins::ProjectIgnoresController < Admins::BaseController
|
||||||
before_action :set_ignore, only: [:edit,:update, :destroy,:show]
|
before_action :set_ignore, only: [:edit,:update, :destroy,:show]
|
||||||
before_action :validate_params, only: [:create, :update]
|
# before_action :validate_params, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = Ignore.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
sort_by = Ignore.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
|
@ -31,12 +31,12 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
||||||
# }
|
# }
|
||||||
@project_ignore = Ignore.new(ignore_params)
|
@project_ignore = Ignore.new(ignore_params)
|
||||||
|
|
||||||
if @project_ignore.save!
|
if @project_ignore.save
|
||||||
redirect_to admins_project_ignores_path
|
redirect_to admins_project_ignores_path
|
||||||
flash[:success] = "创建成功"
|
flash[:success] = "创建成功"
|
||||||
else
|
else
|
||||||
render :new
|
redirect_to admins_project_ignores_path
|
||||||
flash[:danger] = "创建失败"
|
flash[:danger] = @project_ignore.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
||||||
redirect_to admins_project_ignores_path
|
redirect_to admins_project_ignores_path
|
||||||
flash[:success] = "更新成功"
|
flash[:success] = "更新成功"
|
||||||
else
|
else
|
||||||
render :edit
|
redirect_to admins_project_ignores_path
|
||||||
flash[:danger] = "更新失败"
|
flash[:danger] = @project_ignore.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,23 +98,23 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
||||||
params.require(:ignore).permit(:name,:content)
|
params.require(:ignore).permit(:name,:content)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_params
|
# def validate_params
|
||||||
name = params[:ignore][:name]
|
# name = params[:ignore][:name]
|
||||||
if name.blank?
|
# if name.blank?
|
||||||
flash[:danger] = "名称不允许为空"
|
# flash[:danger] = "名称不允许为空"
|
||||||
redirect_to admins_project_ignores_path
|
# redirect_to admins_project_ignores_path
|
||||||
elsif check_ignore_present?(name) && @project_ignore.blank?
|
# elsif check_ignore_present?(name) && @project_ignore.blank?
|
||||||
flash[:danger] = "创建失败:名称已存在"
|
# flash[:danger] = "创建失败:名称已存在"
|
||||||
redirect_to admins_project_ignores_path
|
# redirect_to admins_project_ignores_path
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
def check_ignore_present?(name)
|
# def check_ignore_present?(name)
|
||||||
return true if name.blank?
|
# return true if name.blank?
|
||||||
name_downcase = name.downcase
|
# name_downcase = name.downcase
|
||||||
name_upcase = name.upcase
|
# name_upcase = name.upcase
|
||||||
name_first_big = name.capitalize
|
# name_first_big = name.capitalize
|
||||||
Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big)
|
# Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big)
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,17 +27,18 @@ class Admins::ProjectLanguagesController < Admins::BaseController
|
||||||
flash[:success] = '创建成功'
|
flash[:success] = '创建成功'
|
||||||
else
|
else
|
||||||
redirect_to admins_project_languages_path
|
redirect_to admins_project_languages_path
|
||||||
flash[:danger] = '创建失败'
|
flash[:danger] = @project_language.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @project_language.update_attribute(:name, @name)
|
@project_language.attributes = {name: @name}
|
||||||
|
if @project_language.save
|
||||||
redirect_to admins_project_languages_path
|
redirect_to admins_project_languages_path
|
||||||
flash[:success] = '更新成功'
|
flash[:success] = '更新成功'
|
||||||
else
|
else
|
||||||
redirect_to admins_project_languages_path
|
redirect_to admins_project_languages_path
|
||||||
flash[:success] = '更新失败'
|
flash[:danger] = @project_language.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Admins::ProjectLicensesController < Admins::BaseController
|
class Admins::ProjectLicensesController < Admins::BaseController
|
||||||
before_action :set_license, only: [:edit,:update, :destroy,:show]
|
before_action :set_license, only: [:edit,:update, :destroy,:show]
|
||||||
before_action :validate_params, only: [:create, :update]
|
# before_action :validate_params, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
|
@ -30,13 +30,12 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
||||||
# position: max_position
|
# position: max_position
|
||||||
# }
|
# }
|
||||||
@project_license = License.new(license_params)
|
@project_license = License.new(license_params)
|
||||||
|
if @project_license.save
|
||||||
if @project_license.save!
|
|
||||||
redirect_to admins_project_licenses_path
|
redirect_to admins_project_licenses_path
|
||||||
flash[:success] = "创建成功"
|
flash[:success] = "创建成功"
|
||||||
else
|
else
|
||||||
render :new
|
redirect_to admins_project_licenses_path
|
||||||
flash[:danger] = "创建失败"
|
flash[:danger] = @project_license.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,12 +53,13 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
||||||
# permissions: permissions.to_s,
|
# permissions: permissions.to_s,
|
||||||
# limitations: limitations.to_s
|
# limitations: limitations.to_s
|
||||||
# }
|
# }
|
||||||
if @project_license.update_attributes(license_params)
|
@project_license.attributes = license_params
|
||||||
|
if @project_license.save
|
||||||
redirect_to admins_project_licenses_path
|
redirect_to admins_project_licenses_path
|
||||||
flash[:success] = "更新成功"
|
flash[:success] = "更新成功"
|
||||||
else
|
else
|
||||||
render :edit
|
render admins_project_licenses_path
|
||||||
flash[:danger] = "更新失败"
|
flash[:danger] = @project_license.errors.full_messages.join(",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,23 +98,23 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
||||||
params.require(:license).permit(:name,:content)
|
params.require(:license).permit(:name,:content)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_params
|
# def validate_params
|
||||||
name = params[:license][:name]
|
# name = params[:license][:name]
|
||||||
if name.blank?
|
# if name.blank?
|
||||||
flash[:danger] = "名称不允许为空"
|
# flash[:danger] = "名称不允许为空"
|
||||||
redirect_to admins_project_licenses_path
|
# redirect_to admins_project_licenses_path
|
||||||
elsif check_license_present?(name) && @project_license.blank?
|
# elsif check_license_present?(name) && @project_license.blank?
|
||||||
flash[:danger] = "创建失败:名称已存在"
|
# flash[:danger] = "创建失败:名称已存在"
|
||||||
redirect_to admins_project_licenses_path
|
# redirect_to admins_project_licenses_path
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
def check_license_present?(name)
|
# def check_license_present?(name)
|
||||||
return true if name.blank?
|
# return true if name.blank?
|
||||||
name_downcase = name.downcase
|
# name_downcase = name.downcase
|
||||||
name_upcase = name.upcase
|
# name_upcase = name.upcase
|
||||||
name_first_big = name.capitalize
|
# name_first_big = name.capitalize
|
||||||
License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big)
|
# License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big)
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController
|
||||||
|
|
||||||
def blame
|
def blame
|
||||||
@result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token)
|
@result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token)
|
||||||
puts @result_object
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -16,9 +16,9 @@ class Api::V1::UsersController < Api::V1::BaseController
|
||||||
|
|
||||||
# 60s内不能重复发送
|
# 60s内不能重复发送
|
||||||
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
||||||
tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||||
send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
||||||
tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||||
begin
|
begin
|
||||||
UserMailer.update_email(mail, verification_code).deliver_now
|
UserMailer.update_email(mail, verification_code).deliver_now
|
||||||
|
|
||||||
|
@ -39,17 +39,17 @@ class Api::V1::UsersController < Api::V1::BaseController
|
||||||
|
|
||||||
def check_password
|
def check_password
|
||||||
password = params[:password]
|
password = params[:password]
|
||||||
return render_error("8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
|
return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
|
||||||
return render_error("密码错误") unless @observe_user.check_password?(password)
|
return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_email
|
def check_email
|
||||||
mail = strip(params[:email])
|
mail = strip(params[:email])
|
||||||
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||||
|
|
||||||
exist_owner = Owner.find_by(mail: mail)
|
exist_owner = Owner.find_by(mail: mail)
|
||||||
return render_error('邮箱已被使用') if exist_owner
|
return tip_exception(-2, '邮箱已被使用') if exist_owner
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,12 +58,13 @@ class Api::V1::UsersController < Api::V1::BaseController
|
||||||
mail = strip(params[:email])
|
mail = strip(params[:email])
|
||||||
code_type = params[:code_type]
|
code_type = params[:code_type]
|
||||||
|
|
||||||
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||||
|
|
||||||
verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last
|
verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last
|
||||||
|
return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||||
|
|
||||||
return render_error("验证码不正确") if verifi_code&.code != code
|
return tip_exception(-6, "验证码不正确") if verifi_code&.code != code
|
||||||
return render_error("验证码已失效") if !verifi_code&.effective?
|
return tip_exception(-6, "验证码已失效") if !verifi_code&.effective?
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,25 @@ class ApplicationController < ActionController::Base
|
||||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def require_login_or_token
|
||||||
|
if params[:token].present?
|
||||||
|
user = User.try_to_autologin(params[:token])
|
||||||
|
User.current = user
|
||||||
|
end
|
||||||
|
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_login_cloud_ide_saas
|
||||||
|
if params[:sign].present? && params[:email].present?
|
||||||
|
sign = Digest::MD5.hexdigest("#{OPENKEY}#{params[:email]}")
|
||||||
|
if params[:sign].to_s == sign
|
||||||
|
user = User.find_by(mail: params[:email])
|
||||||
|
User.current = user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||||
|
end
|
||||||
|
|
||||||
def require_profile_completed
|
def require_profile_completed
|
||||||
tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed?
|
tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed?
|
||||||
end
|
end
|
||||||
|
@ -704,9 +723,15 @@ class ApplicationController < ActionController::Base
|
||||||
# @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"
|
if @project.present?
|
||||||
@project = nil
|
logger.info "###########: has project and but can't read project"
|
||||||
render_not_found and return
|
@project = nil
|
||||||
|
render_forbidden and return
|
||||||
|
else
|
||||||
|
logger.info "###########:project not found"
|
||||||
|
@project = nil
|
||||||
|
render_not_found and return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@project
|
@project
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,261 +1,261 @@
|
||||||
#coding=utf-8
|
#coding=utf-8
|
||||||
#
|
#
|
||||||
# 文件上传
|
# 文件上传
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file]
|
before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file]
|
||||||
before_action :find_file, only: %i[show destroy]
|
before_action :find_file, only: %i[show destroy]
|
||||||
before_action :attachment_candown, only: [:show]
|
before_action :attachment_candown, only: [:show]
|
||||||
skip_before_action :check_sign, only: [:show, :create]
|
skip_before_action :check_sign, only: [:show, :create]
|
||||||
|
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
def show
|
def show
|
||||||
# 1. 优先跳到cdn
|
# 1. 优先跳到cdn
|
||||||
# 2. 如果没有cdn,send_file
|
# 2. 如果没有cdn,send_file
|
||||||
if @file.cloud_url.present?
|
if @file.cloud_url.present?
|
||||||
update_downloads(@file)
|
update_downloads(@file)
|
||||||
redirect_to @file.cloud_url and return
|
redirect_to @file.cloud_url and return
|
||||||
end
|
end
|
||||||
|
|
||||||
type_attachment = params[:disposition] || "attachment"
|
type_attachment = params[:disposition] || "attachment"
|
||||||
if type_attachment == "inline"
|
if type_attachment == "inline"
|
||||||
send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf'
|
send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf'
|
||||||
elsif type_attachment == "MP4"
|
elsif type_attachment == "MP4"
|
||||||
send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true
|
send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true
|
||||||
else
|
else
|
||||||
send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream')
|
send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream')
|
||||||
end
|
end
|
||||||
update_downloads(@file)
|
update_downloads(@file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def get_file
|
def get_file
|
||||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s)
|
url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s)
|
||||||
if url.starts_with?(base_url)
|
if url.starts_with?(base_url)
|
||||||
domain = GiteaService.gitea_config[:domain]
|
domain = GiteaService.gitea_config[:domain]
|
||||||
api_url = GiteaService.gitea_config[:base_url]
|
api_url = GiteaService.gitea_config[:base_url]
|
||||||
url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?')
|
url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?')
|
||||||
request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join
|
request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join
|
||||||
response = Faraday.get(request_url)
|
response = Faraday.get(request_url)
|
||||||
filename = url.to_s.split("/").pop()
|
filename = url.to_s.split("/").pop()
|
||||||
else
|
else
|
||||||
response = Faraday.get(url)
|
response = Faraday.get(url)
|
||||||
filename = params[:download_url].to_s.split("/").pop()
|
filename = params[:download_url].to_s.split("/").pop()
|
||||||
end
|
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
|
||||||
|
|
||||||
def create
|
def create
|
||||||
# 1. 本地存储
|
# 1. 本地存储
|
||||||
# 2. 上传到云
|
# 2. 上传到云
|
||||||
begin
|
begin
|
||||||
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
||||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||||
raise "未上传文件" unless upload_file
|
raise "未上传文件" unless upload_file
|
||||||
|
|
||||||
folder = file_storage_directory
|
folder = file_storage_directory
|
||||||
raise "存储目录未定义" unless folder.present?
|
raise "存储目录未定义" unless folder.present?
|
||||||
|
|
||||||
month_folder = current_month_folder
|
month_folder = current_month_folder
|
||||||
save_path = File.join(folder, month_folder)
|
save_path = File.join(folder, month_folder)
|
||||||
|
|
||||||
ext = file_ext(upload_file.original_filename)
|
ext = file_ext(upload_file.original_filename)
|
||||||
|
|
||||||
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
||||||
|
|
||||||
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
||||||
|
|
||||||
# remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
|
# remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
|
||||||
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
|
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
|
||||||
|
|
||||||
logger.info "local_path: #{local_path}"
|
logger.info "local_path: #{local_path}"
|
||||||
logger.info "remote_path: #{remote_path}"
|
logger.info "remote_path: #{remote_path}"
|
||||||
|
|
||||||
|
|
||||||
disk_filename = local_path[save_path.size + 1, local_path.size]
|
disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||||
#存数据库
|
#存数据库
|
||||||
#
|
#
|
||||||
@attachment = Attachment.where(disk_filename: disk_filename,
|
@attachment = Attachment.where(disk_filename: disk_filename,
|
||||||
author_id: current_user.id,
|
author_id: current_user.id,
|
||||||
cloud_url: remote_path).first
|
cloud_url: remote_path).first
|
||||||
if @attachment.blank?
|
if @attachment.blank?
|
||||||
@attachment = Attachment.new
|
@attachment = Attachment.new
|
||||||
@attachment.filename = upload_file.original_filename
|
@attachment.filename = upload_file.original_filename
|
||||||
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||||
@attachment.filesize = upload_file.tempfile.size
|
@attachment.filesize = upload_file.tempfile.size
|
||||||
@attachment.content_type = content_type
|
@attachment.content_type = content_type
|
||||||
@attachment.digest = digest
|
@attachment.digest = digest
|
||||||
@attachment.author_id = current_user.id
|
@attachment.author_id = current_user.id
|
||||||
@attachment.disk_directory = month_folder
|
@attachment.disk_directory = month_folder
|
||||||
@attachment.cloud_url = remote_path
|
@attachment.cloud_url = remote_path
|
||||||
@attachment.save!
|
@attachment.save!
|
||||||
else
|
else
|
||||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
render_json
|
render_json
|
||||||
rescue => e
|
rescue => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
begin
|
begin
|
||||||
@file_path = absolute_path(local_path(@file))
|
@file_path = absolute_path(local_path(@file))
|
||||||
#return normal_status(403, "") unless @file.author == current_user
|
#return normal_status(403, "") unless @file.author == current_user
|
||||||
@file.destroy!
|
@file.destroy!
|
||||||
|
|
||||||
delete_file(@file_path)
|
delete_file(@file_path)
|
||||||
normal_status("删除成功")
|
normal_status("删除成功")
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 附件为视频时,点击播放
|
# 附件为视频时,点击播放
|
||||||
def preview_attachment
|
def preview_attachment
|
||||||
attachment = Attachment.find_by(id: params[:id])
|
attachment = Attachment.find_by(id: params[:id])
|
||||||
dir_path = "#{Rails.root}/public/preview"
|
dir_path = "#{Rails.root}/public/preview"
|
||||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||||
if params[:status] == "preview"
|
if params[:status] == "preview"
|
||||||
if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/")
|
if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/")
|
||||||
render json: {status: 1, url: "/preview/#{attachment.disk_filename}"}
|
render json: {status: 1, url: "/preview/#{attachment.disk_filename}"}
|
||||||
else
|
else
|
||||||
normal_status(-1, "出现错误,请稍后重试")
|
normal_status(-1, "出现错误,请稍后重试")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
||||||
normal_status(1, "操作成功")
|
normal_status(1, "操作成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "出现错误,请稍后重试")
|
normal_status(-1, "出现错误,请稍后重试")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_file
|
def find_file
|
||||||
@file =
|
@file =
|
||||||
if params[:type] == 'history'
|
if params[:type] == 'history'
|
||||||
AttachmentHistory.find params[:id]
|
AttachmentHistory.find params[:id]
|
||||||
else
|
else
|
||||||
Attachment.find params[:id]
|
Attachment.find params[:id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_file(file_path)
|
def delete_file(file_path)
|
||||||
File.delete(file_path) if File.exist?(file_path)
|
File.delete(file_path) if File.exist?(file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_month_folder
|
def current_month_folder
|
||||||
date = Time.now
|
date = Time.now
|
||||||
"#{date.year}/#{date.month.to_s.rjust(2, '0')}"
|
"#{date.year}/#{date.month.to_s.rjust(2, '0')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_ext(file_name)
|
def file_ext(file_name)
|
||||||
ext = ''
|
ext = ''
|
||||||
exts = file_name.split(".")
|
exts = file_name.split(".")
|
||||||
if exts.size > 1
|
if exts.size > 1
|
||||||
ext = ".#{exts.last}"
|
ext = ".#{exts.last}"
|
||||||
end
|
end
|
||||||
ext
|
ext
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_save_to_local(save_path, temp_file, ext)
|
def file_save_to_local(save_path, temp_file, ext)
|
||||||
unless Dir.exists?(save_path)
|
unless Dir.exists?(save_path)
|
||||||
FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
|
FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
|
||||||
end
|
end
|
||||||
|
|
||||||
digest = md5_file(temp_file)
|
digest = md5_file(temp_file)
|
||||||
digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
|
digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
|
||||||
local_file_path = File.join(save_path, digest) + ext
|
local_file_path = File.join(save_path, digest) + ext
|
||||||
save_temp_file(temp_file, local_file_path)
|
save_temp_file(temp_file, local_file_path)
|
||||||
|
|
||||||
[local_file_path, digest]
|
[local_file_path, digest]
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_temp_file(temp_file, save_file_path)
|
def save_temp_file(temp_file, save_file_path)
|
||||||
File.open(save_file_path, 'wb') do |f|
|
File.open(save_file_path, 'wb') do |f|
|
||||||
temp_file.rewind
|
temp_file.rewind
|
||||||
while (buffer = temp_file.read(8192))
|
while (buffer = temp_file.read(8192))
|
||||||
f.write(buffer)
|
f.write(buffer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def md5_file(temp_file)
|
def md5_file(temp_file)
|
||||||
md5 = Digest::MD5.new
|
md5 = Digest::MD5.new
|
||||||
temp_file.rewind
|
temp_file.rewind
|
||||||
while (buffer = temp_file.read(8192))
|
while (buffer = temp_file.read(8192))
|
||||||
md5.update(buffer)
|
md5.update(buffer)
|
||||||
end
|
end
|
||||||
md5.hexdigest
|
md5.hexdigest
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_save_to_ucloud(path, file, content_type)
|
def file_save_to_ucloud(path, file, content_type)
|
||||||
ufile = Gitlink::Ufile.new(
|
ufile = Gitlink::Ufile.new(
|
||||||
ucloud_public_key: edu_setting('public_key'),
|
ucloud_public_key: edu_setting('public_key'),
|
||||||
ucloud_private_key: edu_setting('private_key'),
|
ucloud_private_key: edu_setting('private_key'),
|
||||||
ucloud_public_read: true,
|
ucloud_public_read: true,
|
||||||
ucloud_public_bucket: edu_setting('public_bucket'),
|
ucloud_public_bucket: edu_setting('public_bucket'),
|
||||||
ucloud_public_bucket_host: edu_setting('public_bucket_host'),
|
ucloud_public_bucket_host: edu_setting('public_bucket_host'),
|
||||||
ucloud_public_cdn_host: edu_setting('public_cdn_host'),
|
ucloud_public_cdn_host: edu_setting('public_cdn_host'),
|
||||||
)
|
)
|
||||||
File.open(file) do |f|
|
File.open(file) do |f|
|
||||||
ufile.put(path, f, 'Content-Type' => content_type)
|
ufile.put(path, f, 'Content-Type' => content_type)
|
||||||
end
|
end
|
||||||
edu_setting('public_cdn_host') + "/" + path
|
edu_setting('public_cdn_host') + "/" + path
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_candown
|
def attachment_candown
|
||||||
unless current_user.admin? || current_user.business?
|
unless current_user.admin? || current_user.business?
|
||||||
candown = true
|
candown = true
|
||||||
unless params[:type] == 'history'
|
unless params[:type] == 'history'
|
||||||
if @file.container && current_user.logged?
|
if @file.container && current_user.logged?
|
||||||
if @file.container.is_a?(Issue)
|
if @file.container.is_a?(Issue)
|
||||||
course = @file.container.project
|
course = @file.container.project
|
||||||
candown = course.member?(current_user) || course.is_public
|
candown = course.member?(current_user) || course.is_public
|
||||||
elsif @file.container.is_a?(Journal)
|
elsif @file.container.is_a?(Journal)
|
||||||
course = @file.container.issue.project
|
course = @file.container.issue.project
|
||||||
candown = course.member?(current_user)
|
candown = course.member?(current_user) || course.is_public
|
||||||
else
|
else
|
||||||
course = nil
|
course = nil
|
||||||
end
|
end
|
||||||
tip_exception(403, "您没有权限进入") if course.present? && !candown
|
tip_exception(403, "您没有权限进入") if course.present? && !candown
|
||||||
tip_exception(403, "您没有权限进入") if @file.container.is_a?(ApplyUserAuthentication)
|
tip_exception(403, "您没有权限进入") if @file.container.is_a?(ApplyUserAuthentication)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_file_with_range(path, options = {})
|
def send_file_with_range(path, options = {})
|
||||||
logger.info("########request.headers: #{request.headers}")
|
logger.info("########request.headers: #{request.headers}")
|
||||||
logger.info("########request.headers: #{File.exist?(path)}")
|
logger.info("########request.headers: #{File.exist?(path)}")
|
||||||
|
|
||||||
if File.exist?(path)
|
if File.exist?(path)
|
||||||
size = File.size(path)
|
size = File.size(path)
|
||||||
logger.info("########request.headers: #{request.headers}")
|
logger.info("########request.headers: #{request.headers}")
|
||||||
if !request.headers["Range"]
|
if !request.headers["Range"]
|
||||||
status_code = 200 # 200 OK
|
status_code = 200 # 200 OK
|
||||||
offset = 0
|
offset = 0
|
||||||
length = File.size(path)
|
length = File.size(path)
|
||||||
else
|
else
|
||||||
status_code = 206 # 206 Partial Content
|
status_code = 206 # 206 Partial Content
|
||||||
bytes = Rack::Utils.byte_ranges(request.headers, size)[0]
|
bytes = Rack::Utils.byte_ranges(request.headers, size)[0]
|
||||||
offset = bytes.begin
|
offset = bytes.begin
|
||||||
length = bytes.end - bytes.begin
|
length = bytes.end - bytes.begin
|
||||||
end
|
end
|
||||||
response.header["Accept-Ranges"] = "bytes"
|
response.header["Accept-Ranges"] = "bytes"
|
||||||
response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes
|
response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes
|
||||||
response.header["status"] = status_code
|
response.header["status"] = status_code
|
||||||
|
|
||||||
send_data IO.binread(path, length, offset), options
|
send_data IO.binread(path, length, offset), options
|
||||||
else
|
else
|
||||||
raise ActionController::MissingFile, "Cannot read file #{path}."
|
raise ActionController::MissingFile, "Cannot read file #{path}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,13 +65,13 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def check_member_exists!
|
def check_member_exists!
|
||||||
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
|
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
|
||||||
return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?)
|
return render_error("#{@user&.nickname}已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_member_not_exists!
|
def check_member_not_exists!
|
||||||
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
|
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
|
||||||
return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists?
|
return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists?
|
||||||
return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists?
|
return render_error("#{@user&.nickname}还不是项目成员") unless member_exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_user_profile_completed
|
def check_user_profile_completed
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class PublicKeysController < ApplicationController
|
class PublicKeysController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login_cloud_ide_saas
|
||||||
before_action :find_public_key, only: [:destroy]
|
before_action :find_public_key, only: [:destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -61,4 +61,6 @@ class PublicKeysController < ApplicationController
|
||||||
def find_public_key
|
def find_public_key
|
||||||
@public_key = current_user.public_keys.find_by_id(params[:id])
|
@public_key = current_user.public_keys.find_by_id(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -273,7 +273,7 @@ class PullRequestsController < ApplicationController
|
||||||
|
|
||||||
def get_relatived
|
def get_relatived
|
||||||
@project_tags = @project.issue_tags&.select(:id,:name, :color).as_json
|
@project_tags = @project.issue_tags&.select(:id,:name, :color).as_json
|
||||||
@project_versions = @project.versions&.select(:id,:name, :status).as_json
|
@project_versions = @project.versions.opening&.select(:id,:name, :status).as_json
|
||||||
@project_members = @project.all_developers
|
@project_members = @project.all_developers
|
||||||
@project_priories = IssuePriority&.select(:id,:name, :position).as_json
|
@project_priories = IssuePriority&.select(:id,:name, :position).as_json
|
||||||
end
|
end
|
||||||
|
|
|
@ -147,9 +147,19 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
if params[:only_name].present?
|
||||||
|
result = Gitea::Repository::Tags::ListNameService.call(@owner, @project.identifier, params[:name])
|
||||||
|
|
||||||
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
|
else
|
||||||
|
name_result = Gitea::Repository::Tags::ListNameService.call(@owner, @project.identifier, params[:name])
|
||||||
|
|
||||||
|
@tag_names = result.is_a?(Hash) && result.key?(:status) ? [] : name_result
|
||||||
|
|
||||||
|
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
||||||
|
|
||||||
|
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributors
|
def contributors
|
||||||
|
|
|
@ -123,7 +123,7 @@ module TagChosenHelper
|
||||||
cache_key = "project-#{project.id}/all_milestones/size-#{project.versions.size}/#{project.versions.maximum('updated_on')}"
|
cache_key = "project-#{project.id}/all_milestones/size-#{project.versions.size}/#{project.versions.maximum('updated_on')}"
|
||||||
|
|
||||||
Rails.cache.fetch(cache_key) do
|
Rails.cache.fetch(cache_key) do
|
||||||
project.versions.select(:id, :name, :status).collect do |event|
|
project.versions.opening.select(:id, :name, :status).collect do |event|
|
||||||
{
|
{
|
||||||
id: event.id,
|
id: event.id,
|
||||||
name: event.name,
|
name: event.name,
|
||||||
|
|
|
@ -17,30 +17,69 @@ module ProjectOperable
|
||||||
owner.build_permit_team_projects!(id)
|
owner.build_permit_team_projects!(id)
|
||||||
# 避免自己创建的项目,却无法拥有访问权,因为该用户所在团队暂未获得项目访问权
|
# 避免自己创建的项目,却无法拥有访问权,因为该用户所在团队暂未获得项目访问权
|
||||||
return if creator.nil? || owner.is_owner?(creator.id)
|
return if creator.nil? || owner.is_owner?(creator.id)
|
||||||
add_member!(creator.id, "Manager")
|
add_member!(creator.id, "Manager") if creator.is_a?(User)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_member!(user_id, role_name='Developer')
|
def add_member!(user_id, role_name='Developer')
|
||||||
if self.owner.is_a?(Organization)
|
if self.owner.is_a?(Organization)
|
||||||
case role_name
|
case role_name
|
||||||
when 'Manager'
|
when 'Manager'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.admin.take
|
team = self.owner.teams.admin.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 新增对应的团队成员
|
||||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
|
||||||
|
# 确保组织成员中有该用户
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
when 'Developer'
|
when 'Developer'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.write.take
|
team = self.owner.teams.write.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 新增对应的团队成员
|
||||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
|
||||||
|
# 确保组织成员中有该用户
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
when 'Reporter'
|
when 'Reporter'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.read.take
|
team = self.owner.teams.read.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 新增对应的团队成员
|
||||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
|
||||||
|
# 确保组织成员中有该用户
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
member = members.create!(user_id: user_id, team_user_id: team_user&.id)
|
member = members.create!(user_id: user_id, team_user_id: team_user&.id)
|
||||||
|
@ -71,26 +110,70 @@ module ProjectOperable
|
||||||
|
|
||||||
def change_member_role!(user_id, role)
|
def change_member_role!(user_id, role)
|
||||||
member = self.member(user_id)
|
member = self.member(user_id)
|
||||||
|
# 所有者为组织,并且该用户属于组织成员
|
||||||
if self.owner.is_a?(Organization) && member.team_user.present?
|
if self.owner.is_a?(Organization) && member.team_user.present?
|
||||||
case role&.name
|
case role&.name
|
||||||
when 'Manager'
|
when 'Manager'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.admin.take
|
team = self.owner.teams.admin.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||||
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 更改对应的团队成员
|
||||||
|
team_user = member.team_user
|
||||||
|
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
team_user.update_attributes!({team_id: team.id})
|
||||||
|
|
||||||
|
# 确保组织成员中有该用户
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
team_user = member.team_user.update(team_id: team&.id)
|
|
||||||
when 'Developer'
|
when 'Developer'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.write.take
|
team = self.owner.teams.write.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||||
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
$gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 更改对应的团队成员
|
||||||
|
team_user = member.team_user
|
||||||
|
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
team_user.update_attributes!({team_id: team.id})
|
||||||
|
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
team_user = member.team_user.update(team_id: team&.id)
|
|
||||||
when 'Reporter'
|
when 'Reporter'
|
||||||
|
# 构建相应的团队
|
||||||
team = self.owner.teams.read.take
|
team = self.owner.teams.read.take
|
||||||
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
if team.nil?
|
||||||
TeamProject.build(self.user_id, team.id, self.id)
|
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||||
|
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
# 设置项目在团队中的访问权限
|
||||||
|
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||||
|
|
||||||
|
# 更改对应的团队成员
|
||||||
|
team_user = member.team_user
|
||||||
|
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||||
|
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||||
|
team_user.update_attributes!({team_id: team.id})
|
||||||
|
|
||||||
|
# 确保组织成员中有该用户
|
||||||
OrganizationUser.build(self.user_id, user_id)
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
team_user = member.team_user.update(team_id: team&.id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
member.member_roles.last.update_attributes!(role: role)
|
member.member_roles.last.update_attributes!(role: role)
|
||||||
|
|
|
@ -11,4 +11,7 @@
|
||||||
|
|
||||||
class Ignore < ApplicationRecord
|
class Ignore < ApplicationRecord
|
||||||
include Projectable
|
include Projectable
|
||||||
|
|
||||||
|
validates :name, :content, presence: true
|
||||||
|
validates :name, uniqueness: { case_sensitive: false }
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,4 +11,8 @@
|
||||||
|
|
||||||
class License < ApplicationRecord
|
class License < ApplicationRecord
|
||||||
include Projectable
|
include Projectable
|
||||||
|
|
||||||
|
validates :name, :content, presence: true
|
||||||
|
validates :name, uniqueness: { case_sensitive: false }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class MessageTemplate < ApplicationRecord
|
class MessageTemplate < ApplicationRecord
|
||||||
self.inheritance_column = nil
|
# self.inheritance_column = nil
|
||||||
PLATFORM = 'GitLink'
|
PLATFORM = 'GitLink'
|
||||||
|
|
||||||
def self.build_init_data
|
def self.build_init_data
|
||||||
|
|
|
@ -12,4 +12,6 @@
|
||||||
|
|
||||||
class ProjectLanguage < ApplicationRecord
|
class ProjectLanguage < ApplicationRecord
|
||||||
include Projectable
|
include Projectable
|
||||||
|
|
||||||
|
validates :name, uniqueness: { message: "已存在" }
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,4 +70,15 @@ class Team < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def to_gitea_hash
|
||||||
|
{
|
||||||
|
can_create_org_repo: self.can_create_org_project,
|
||||||
|
description: self.description || "",
|
||||||
|
includes_all_repositories: self.includes_all_project,
|
||||||
|
name: self.name,
|
||||||
|
permission: self.authorize,
|
||||||
|
units: self.team_units.pluck(:unit_type).map{|i| "repo.#{i}"}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,8 @@ class Projects::ListMyQuery < ApplicationQuery
|
||||||
projects = projects.where(user_id: user.id)
|
projects = projects.where(user_id: user.id)
|
||||||
elsif params[:category].to_s == "watched" #我关注的
|
elsif params[:category].to_s == "watched" #我关注的
|
||||||
projects = projects.where.not(user_id: user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: user.id})
|
projects = projects.where.not(user_id: user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: user.id})
|
||||||
|
elsif params[:category].to_s == 'only_watched'
|
||||||
|
projects = projects.joins(:watchers).where(watchers: {watchable_type: "Project", user_id: user.id})
|
||||||
elsif params[:category].to_s == "forked" #我fork的
|
elsif params[:category].to_s == "forked" #我fork的
|
||||||
fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
|
fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
|
||||||
projects = projects.where(id: fork_ids)
|
projects = projects.where(id: fork_ids)
|
||||||
|
|
|
@ -53,6 +53,8 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
||||||
projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct
|
projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct
|
||||||
when 'watched'
|
when 'watched'
|
||||||
projects = projects.where.not(user_id: observe_user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id})
|
projects = projects.where.not(user_id: observe_user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id})
|
||||||
|
when 'only_watched'
|
||||||
|
projects = projects.where.joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id})
|
||||||
when 'forked'
|
when 'forked'
|
||||||
fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
|
fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
|
||||||
projects = projects.where(id: fork_ids)
|
projects = projects.where(id: fork_ids)
|
||||||
|
|
|
@ -20,10 +20,13 @@ class Api::V1::Users::UpdateEmailService < ApplicationService
|
||||||
def call
|
def call
|
||||||
raise Error, errors.full_messages.join(",") unless valid?
|
raise Error, errors.full_messages.join(",") unless valid?
|
||||||
raise Error, "密码不正确." unless @user.check_password?(@password)
|
raise Error, "密码不正确." unless @user.check_password?(@password)
|
||||||
raise Error, "验证码不正确." if @verify_code&.code != @code
|
exist_owner = Owner.find_by(mail: @mail)
|
||||||
raise Error, "验证码已失效." if !@verify_code&.effective?
|
raise Error, "邮箱已被使用." if exist_owner
|
||||||
|
is_debug = @code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||||
|
raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug
|
||||||
|
raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug
|
||||||
|
|
||||||
# begin
|
begin
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
change_user_email
|
change_user_email
|
||||||
excute_data_to_gitea
|
excute_data_to_gitea
|
||||||
|
@ -32,15 +35,15 @@ class Api::V1::Users::UpdateEmailService < ApplicationService
|
||||||
|
|
||||||
return gitea_data
|
return gitea_data
|
||||||
|
|
||||||
# rescue
|
rescue
|
||||||
# raise Error, "服务器错误,请联系系统管理员!"
|
raise Error, "服务器错误,请联系系统管理员!"
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def request_params
|
def request_params
|
||||||
{
|
{
|
||||||
access_token: token
|
access_token: @user.gitea_token
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
class Gitea::Repository::Tags::ListNameService < Gitea::ClientService
|
||||||
|
attr_reader :user, :repo, :name
|
||||||
|
|
||||||
|
def initialize(user, repo, name=nil)
|
||||||
|
@user = user
|
||||||
|
@repo = repo
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
render_200_response(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
Hash.new.merge(token: user.gitea_token, name: name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{user.login}/#{repo}/tag_name_set".freeze
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,9 +24,11 @@ class Projects::TransferService < ApplicationService
|
||||||
|
|
||||||
private
|
private
|
||||||
def update_owner
|
def update_owner
|
||||||
|
# 转移项目需要移除原来的权限
|
||||||
|
project.members.update_all(team_user_id: nil)
|
||||||
project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) }
|
project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) }
|
||||||
project.set_owner_permission(new_owner)
|
|
||||||
project.update!(user_id: new_owner.id)
|
project.update!(user_id: new_owner.id)
|
||||||
|
project.set_owner_permission(new_owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_repo_url
|
def update_repo_url
|
||||||
|
@ -49,7 +51,8 @@ class Projects::TransferService < ApplicationService
|
||||||
|
|
||||||
def gitea_update_owner
|
def gitea_update_owner
|
||||||
begin
|
begin
|
||||||
@gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login)
|
@gitea_repo = $gitea_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})
|
||||||
|
# @gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}")
|
Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,9 @@ class PullRequests::MergeService < ApplicationService
|
||||||
result = Gitea::PullRequest::MergeService.call(@current_user.gitea_token, @owner.login,
|
result = Gitea::PullRequest::MergeService.call(@current_user.gitea_token, @owner.login,
|
||||||
@repo.identifier, @pull.gitea_number, gitea_merge_pull_params)
|
@repo.identifier, @pull.gitea_number, gitea_merge_pull_params)
|
||||||
@status, @message = result
|
@status, @message = result
|
||||||
|
if @status.to_i == 409
|
||||||
|
@message = "代码冲突,请重新提交合并请求"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitea_merge_pull_params
|
def gitea_merge_pull_params
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
</label>
|
</label>
|
||||||
<%= p.number_field :pinned_index,class: "form-control input-lg",placeholder: "精选等级",required: true%>
|
<%= p.number_field :pinned_index,class: "form-control input-lg",placeholder: "精选等级",required: true%>
|
||||||
</div>
|
</div>
|
||||||
|
<%if false%>
|
||||||
<div class="logo-item">
|
<div class="logo-item">
|
||||||
<% logo_img = @project_category.logo_url %>
|
<% logo_img = @project_category.logo_url %>
|
||||||
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
|
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
<div>尺寸:高度38px以内,宽等比例缩放</div>
|
<div>尺寸:高度38px以内,宽等比例缩放</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入忽略文件的全称" %>
|
<%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入忽略文件的全称", required: true%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "忽略文件的简要介绍,不得超过500字" %>
|
<%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "忽略文件的简要介绍,不得超过500字", required: true %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入开源许可证的全称" %>
|
<%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入开源许可证的全称", required: true %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "许可证的简要介绍,不得超过500字" %>
|
<%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "许可证的简要介绍,不得超过500字", required: true %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<th width="5%">成员</th>
|
<th width="5%">成员</th>
|
||||||
<th width="12%">管理员</th>
|
<th width="12%">管理员</th>
|
||||||
<th width="15%"><%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %></th>
|
<th width="15%"><%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %></th>
|
||||||
<th width="25%">操作</th>
|
<th width="15%">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<thead class="thead-light">
|
<thead class="thead-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th width="4%">序号</th>
|
<th width="4%">序号</th>
|
||||||
<th width="8%" class="text-left">真实姓名</th>
|
<th width="8%" class="text-left">昵称</th>
|
||||||
<th width="13%">邮件地址</th>
|
<th width="13%">邮件地址</th>
|
||||||
<th width="10%">手机号码</th>
|
<th width="10%">手机号码</th>
|
||||||
<th width="7%">角色</th>
|
<th width="7%">角色</th>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
json.array! @tags do |tag|
|
json.total_count @tag_names.present? ? @tag_names.count : @tags.count
|
||||||
if tag.present?
|
json.tags @tags do |tag|
|
||||||
|
if tag.present? && tag.is_a?(Hash)
|
||||||
json.name tag['name']
|
json.name tag['name']
|
||||||
json.id tag['id']
|
json.id tag['id']
|
||||||
json.zipball_url render_zip_url(@owner, @repository, tag['name'])
|
json.zipball_url render_zip_url(@owner, @repository, tag['name'])
|
||||||
|
@ -22,6 +23,8 @@ json.array! @tags do |tag|
|
||||||
json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name']
|
json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
json.name tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,4 @@ json.login @user.login
|
||||||
json.user_id @user.id
|
json.user_id @user.id
|
||||||
json.image_url url_to_avatar(@user)
|
json.image_url url_to_avatar(@user)
|
||||||
json.admin @user.admin
|
json.admin @user.admin
|
||||||
|
json.email @user.mail
|
||||||
|
|
|
@ -361,7 +361,7 @@ Doorkeeper.configure do
|
||||||
# https://datatracker.ietf.org/doc/html/rfc6819#section-4.4.3
|
# https://datatracker.ietf.org/doc/html/rfc6819#section-4.4.3
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
grant_flows %w[authorization_code client_credentials password]
|
grant_flows %w[authorization_code client_credentials password refresh_token]
|
||||||
|
|
||||||
# Allows to customize OAuth grant flows that +each+ application support.
|
# Allows to customize OAuth grant flows that +each+ application support.
|
||||||
# You can configure a custom block (or use a class respond to `#call`) that must
|
# You can configure a custom block (or use a class respond to `#call`) that must
|
||||||
|
|
|
@ -223,6 +223,14 @@ zh-CN:
|
||||||
platform: '直播平台'
|
platform: '直播平台'
|
||||||
live_time: '开播时间'
|
live_time: '开播时间'
|
||||||
duration: '直播时长'
|
duration: '直播时长'
|
||||||
|
project_language:
|
||||||
|
name: '项目语言'
|
||||||
|
license:
|
||||||
|
name: '许可证名称'
|
||||||
|
content: '许可证内容'
|
||||||
|
ignore:
|
||||||
|
name: 'git忽略文件名称'
|
||||||
|
content: 'git忽略文件内容'
|
||||||
close_pr: 合并请求
|
close_pr: 合并请求
|
||||||
roles:
|
roles:
|
||||||
Developer: 开发者
|
Developer: 开发者
|
||||||
|
|
|
@ -4,6 +4,37 @@ desc "初始化数据同步到gitea平台"
|
||||||
# 再同步项目及项目成员
|
# 再同步项目及项目成员
|
||||||
|
|
||||||
namespace :sync_data_to_gitea do
|
namespace :sync_data_to_gitea do
|
||||||
|
desc "同步组织数据"
|
||||||
|
# 同步组织成员,并仅保留最高权限
|
||||||
|
task organizations: :environment do
|
||||||
|
Organization.includes(:organization_users, teams: [:team_users, :team_projects]).find_each do |org|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
org.teams.each do |team|
|
||||||
|
if team.gtid.blank?
|
||||||
|
gteam = $gitea_client.post_orgs_teams_by_org(org.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||||
|
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||||
|
end
|
||||||
|
team.team_users.each do |teamuser|
|
||||||
|
userlogin = teamuser&.user&.login
|
||||||
|
ou = org.organization_users.find_by(user_id: teamuser.user_id)
|
||||||
|
OrganizationUser.build(org.id, teamuser.user_id) unless ou.present?
|
||||||
|
next if ($gitea_client.get_teams_members_by_id_username(team.gtid, userlogin) rescue nil)
|
||||||
|
tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil
|
||||||
|
raise ActiveRecord::Rollback if tu_result.nil?
|
||||||
|
end
|
||||||
|
team.team_projects.each do |teamp|
|
||||||
|
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, org.login, teamp&.project.identifier) rescue nil
|
||||||
|
raise ActiveRecord::Rollback if tp_result.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
org.organization_users.each do |user|
|
||||||
|
$gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue next
|
||||||
|
user.destroy!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "同步用户"
|
desc "同步用户"
|
||||||
task users: :environment do
|
task users: :environment do
|
||||||
users = User.where.not(mail: [nil, ""], type: 'Anonymous').or(User.where.not(login: [nil, ""])).distinct
|
users = User.where.not(mail: [nil, ""], type: 'Anonymous').or(User.where.not(login: [nil, ""])).distinct
|
||||||
|
|
Loading…
Reference in New Issue