merge pre
This commit is contained in:
commit
5135f60e50
|
@ -161,6 +161,9 @@ class AccountsController < ApplicationController
|
||||||
successful_authentication(user)
|
successful_authentication(user)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
elsif interactor.result[:message].to_s.include?("user already exists")
|
||||||
|
UserAction.create(:action_id => 2, :action_type => "register_error", :user_id => user.try(:id).to_i, :ip => "code: #{register_params[:code]}; login: #{register_params[:login]}; namespace: #{register_params[:namespace]}; password: #{password};")
|
||||||
|
normal_status(-1, "用户已注册,请勿连续操作。")
|
||||||
else
|
else
|
||||||
tip_exception(-1, interactor.result[:message])
|
tip_exception(-1, interactor.result[:message])
|
||||||
end
|
end
|
||||||
|
@ -182,7 +185,7 @@ class AccountsController < ApplicationController
|
||||||
# user.destroy
|
# user.destroy
|
||||||
end
|
end
|
||||||
Rails.logger.error("##:register error--#{user.try(:id)},message:#{e.message}")
|
Rails.logger.error("##:register error--#{user.try(:id)},message:#{e.message}")
|
||||||
UserAction.create(:action_id => user.try(:id).to_i, :action_type => "register_error", :user_id => user.try(:id).to_i, :ip => "code: #{register_params[:code]}; login: #{register_params[:login]}; namespace: #{register_params[:namespace]}; password: #{password};")
|
UserAction.create(:action_id => 1, :action_type => "register_error", :user_id => user.try(:id).to_i, :ip => "code: #{register_params[:code]}; login: #{register_params[:login]}; namespace: #{register_params[:namespace]}; password: #{password};")
|
||||||
logger_error(e)
|
logger_error(e)
|
||||||
tip_exception(-1, "注册失败")
|
tip_exception(-1, "注册失败")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1161,6 +1161,19 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
def find_atme_receivers
|
def find_atme_receivers
|
||||||
@atme_receivers = User.where(login: params[:receivers_login])
|
@atme_receivers = User.where(login: params[:receivers_login])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 接口限流,请求量大有性能问题
|
||||||
|
def request_limit
|
||||||
|
record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}")
|
||||||
|
if record_count.present?
|
||||||
|
record_count = record_count + 1
|
||||||
|
else
|
||||||
|
record_count = 1
|
||||||
|
end
|
||||||
|
tip_exception("请求太快,请稍后再试。") if record_count > 100
|
||||||
|
|
||||||
|
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 1.minute)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,14 +5,14 @@ class ForksController < ApplicationController
|
||||||
before_action :authenticate_project!, :authenticate_user!
|
before_action :authenticate_project!, :authenticate_user!
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
|
@new_project = Projects::ForkService.new(current_user, @project, params[:organization], params[:new_name], params[:new_identifier]).call
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def authenticate_project!
|
def authenticate_project!
|
||||||
if current_user&.id == @project.user_id
|
if current_user&.id == @project.user_id && (params[:new_identifier].blank? || params[:new_identifier] == @project.identifier)
|
||||||
render_result(-1, "自己不能fork自己的项目")
|
render_result(-1, "自己不能fork自己的项目")
|
||||||
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
elsif Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
|
||||||
render_result(0, "fork失败,你已拥有了这个项目")
|
render_result(0, "fork失败,你已拥有了这个项目")
|
||||||
end
|
end
|
||||||
# return if current_user != @project.owner
|
# return if current_user != @project.owner
|
||||||
|
|
|
@ -9,6 +9,7 @@ class ProjectsController < ApplicationController
|
||||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||||
|
before_action :request_limit, only: %i[index]
|
||||||
|
|
||||||
def menu_list
|
def menu_list
|
||||||
menu = []
|
menu = []
|
||||||
|
@ -45,8 +46,8 @@ class ProjectsController < ApplicationController
|
||||||
elsif params[:search].present? || params[:topic_id].present?
|
elsif params[:search].present? || params[:topic_id].present?
|
||||||
@projects.total_count
|
@projects.total_count
|
||||||
else
|
else
|
||||||
cate = ProjectCategory.find_by(id: category_id)
|
cate = ProjectCategory.find_by(id: category_id)
|
||||||
cate&.projects_count || 0
|
cate&.projects_count || 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ class ProjectsController < ApplicationController
|
||||||
Projects::CreateForm.new(project_params).validate!
|
Projects::CreateForm.new(project_params).validate!
|
||||||
@project = Projects::CreateService.new(current_user, project_params).call
|
@project = Projects::CreateService.new(current_user, project_params).call
|
||||||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
||||||
|
UpdateProjectTopicJob.perform_later(@project.id) if @project.id.present?
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -72,8 +74,8 @@ class ProjectsController < ApplicationController
|
||||||
if result[:status] == :success
|
if result[:status] == :success
|
||||||
Rails.logger.info "########## 加速镜像成功 ########## "
|
Rails.logger.info "########## 加速镜像成功 ########## "
|
||||||
Projects::MigrateService.call(current_user,
|
Projects::MigrateService.call(current_user,
|
||||||
mirror_params.merge(source_clone_url: source_clone_url,
|
mirror_params.merge(source_clone_url: source_clone_url,
|
||||||
clone_addr: accelerator_url(mirror_params[:repository_name])))
|
clone_addr: accelerator_url(mirror_params[:repository_name])))
|
||||||
else
|
else
|
||||||
Projects::MigrateService.call(current_user, mirror_params)
|
Projects::MigrateService.call(current_user, mirror_params)
|
||||||
end
|
end
|
||||||
|
@ -95,7 +97,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||||
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name])
|
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name])
|
||||||
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result) : result
|
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result) : result
|
||||||
end
|
end
|
||||||
|
|
||||||
def branches_slice
|
def branches_slice
|
||||||
|
@ -146,7 +148,7 @@ class ProjectsController < ApplicationController
|
||||||
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||||
else
|
else
|
||||||
validate_params = project_params.slice(:name, :description,
|
validate_params = project_params.slice(:name, :description,
|
||||||
:project_category_id, :project_language_id, :private, :identifier)
|
:project_category_id, :project_language_id, :private, :identifier)
|
||||||
|
|
||||||
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier, project_name: @project.name)).validate!
|
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier, project_name: @project.name)).validate!
|
||||||
|
|
||||||
|
@ -162,7 +164,7 @@ class ProjectsController < ApplicationController
|
||||||
name: @project.identifier
|
name: @project.identifier
|
||||||
}
|
}
|
||||||
gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params)
|
gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params)
|
||||||
@project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]})
|
@project.repository.update_attributes({ hidden: gitea_repo["private"], identifier: gitea_repo["name"] })
|
||||||
# 更新对应所属分类下的项目数量(私有)
|
# 更新对应所属分类下的项目数量(私有)
|
||||||
before_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][0] : @project.is_public
|
before_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][0] : @project.is_public
|
||||||
after_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][1] : @project.is_public
|
after_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][1] : @project.is_public
|
||||||
|
@ -273,7 +275,7 @@ class ProjectsController < ApplicationController
|
||||||
if @project_detail.save!
|
if @project_detail.save!
|
||||||
attachment_ids = Array(params[:attachment_ids])
|
attachment_ids = Array(params[:attachment_ids])
|
||||||
logger.info "=============> #{Array(params[:attachment_ids])}"
|
logger.info "=============> #{Array(params[:attachment_ids])}"
|
||||||
@attachments = Attachment.where(id: attachment_ids)
|
@attachments = Attachment.where(id: attachment_ids)
|
||||||
@attachments.update_all(
|
@attachments.update_all(
|
||||||
container_id: @project_detail.id,
|
container_id: @project_detail.id,
|
||||||
container_type: @project_detail.model_name.name,
|
container_type: @project_detail.model_name.name,
|
||||||
|
@ -286,6 +288,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def project_params
|
def project_params
|
||||||
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier,
|
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier,
|
||||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
||||||
|
@ -293,7 +296,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mirror_params
|
def mirror_params
|
||||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username,
|
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username, :auth_token,
|
||||||
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ class SettingsController < ApplicationController
|
||||||
private
|
private
|
||||||
def get_navbar
|
def get_navbar
|
||||||
@navbar = default_laboratory.navbar
|
@navbar = default_laboratory.navbar
|
||||||
if User.current.logged?
|
# if User.current.logged?
|
||||||
pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
|
# pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
|
||||||
@navbar << pernal_index
|
# @navbar << pernal_index
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_add_menu
|
def get_add_menu
|
||||||
|
|
|
@ -6,6 +6,7 @@ class Users::ProjectTrendsController < Users::BaseController
|
||||||
else
|
else
|
||||||
@project_trends = observed_user.project_trends
|
@project_trends = observed_user.project_trends
|
||||||
end
|
end
|
||||||
|
@project_trends = @project_trends.left_joins(:project).where("projects.is_public = TRUE")
|
||||||
@project_trends = kaminari_paginate(@project_trends.includes(:trend, :project).order(created_at: :desc))
|
@project_trends = kaminari_paginate(@project_trends.includes(:trend, :project).order(created_at: :desc))
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
class Projects::MigrateForm < BaseForm
|
class Projects::MigrateForm < BaseForm
|
||||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description,
|
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description, :auth_token,
|
||||||
:project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
:project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
||||||
|
|
||||||
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
||||||
|
|
|
@ -16,10 +16,12 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
||||||
project_id = repo&.project&.id
|
project_id = repo&.project&.id
|
||||||
puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############"
|
puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############"
|
||||||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present?
|
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present?
|
||||||
|
UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present?
|
||||||
puts "############ mirror status: #{repo.mirror.status} ############"
|
puts "############ mirror status: #{repo.mirror.status} ############"
|
||||||
else
|
else
|
||||||
repo&.mirror&.failed!
|
repo&.mirror&.failed!
|
||||||
end
|
end
|
||||||
BroadcastMirrorRepoMsgJob.perform_later(repo.id) unless repo&.mirror.waiting?
|
# UpdateProjectTopicJob 中语言要延迟1S才能获取
|
||||||
|
BroadcastMirrorRepoMsgJob.set(wait: 1.seconds).perform_later(repo.id) unless repo&.mirror.waiting?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
class UpdateProjectTopicJob < ApplicationJob
|
||||||
|
include ProjectsHelper
|
||||||
|
|
||||||
|
queue_as :message
|
||||||
|
|
||||||
|
def perform(project_id)
|
||||||
|
project = Project.find_by(id: project_id)
|
||||||
|
return if project.blank?
|
||||||
|
begin
|
||||||
|
languages = $gitea_client.get_repos_languages_by_owner_repo(project.owner.login, project.identifier)
|
||||||
|
puts "#{project.owner.login}/#{project.identifier} get_repos_languages:#{languages}"
|
||||||
|
topic_count = 0
|
||||||
|
if project.project_category_id.present?
|
||||||
|
project_topic = ProjectTopic.find_or_create_by!(name: project.project_category.name.downcase)
|
||||||
|
project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: project.id)
|
||||||
|
if project_topic.present? && project_topic_ralate.present?
|
||||||
|
topic_count +=1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
languages.each do |k, _|
|
||||||
|
next if topic_count >= 3
|
||||||
|
project_topic = ProjectTopic.find_or_create_by!(name: k.downcase)
|
||||||
|
project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: project.id)
|
||||||
|
if project_topic.present? && project_topic_ralate.present?
|
||||||
|
topic_count +=1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
puts "get_repos_languages: error:#{e.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -200,7 +200,7 @@ module ProjectOperable
|
||||||
if owner.is_a?(User)
|
if owner.is_a?(User)
|
||||||
managers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
managers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
||||||
elsif owner.is_a?(Organization)
|
elsif owner.is_a?(Organization)
|
||||||
managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_only_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,7 @@ module ProjectOperable
|
||||||
if owner.is_a?(User)
|
if owner.is_a?(User)
|
||||||
developers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
developers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
||||||
elsif owner.is_a?(Organization)
|
elsif owner.is_a?(Organization)
|
||||||
developers.exists?(user_id: user.id) || (owner.is_only_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
developers.exists?(user_id: user.id) || (owner.is_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -126,14 +126,24 @@ class Organization < Owner
|
||||||
|
|
||||||
def is_only_admin?(user_id)
|
def is_only_admin?(user_id)
|
||||||
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(admin)}).present?
|
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(admin)}).present?
|
||||||
|
roles = has_roles(user_id)
|
||||||
|
roles.size > 1 ? false : roles.include?("admin")
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_only_write?(user_id)
|
def is_only_write?(user_id)
|
||||||
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(write)}).present?
|
# team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(write)}).present?
|
||||||
|
roles = has_roles(user_id)
|
||||||
|
roles.size > 1 ? false : roles.include?("write")
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_only_read?(user_id)
|
def is_only_read?(user_id)
|
||||||
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(read)}).present?
|
# team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(read)}).present?
|
||||||
|
roles = has_roles(user_id)
|
||||||
|
roles.size > 1 ? false : roles.include?("read")
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_roles(user_id)
|
||||||
|
teams.joins(:team_users).where("team_users.user_id=?", user_id).pluck("teams.authorize").uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# 是不是所有者团队的最后一个成员
|
# 是不是所有者团队的最后一个成员
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Repository < ApplicationRecord
|
||||||
validates :identifier, presence: true
|
validates :identifier, presence: true
|
||||||
|
|
||||||
delegate :default_branch, to: :project, allow_nil: true
|
delegate :default_branch, to: :project, allow_nil: true
|
||||||
|
attr_accessor :auth_token
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
self.identifier.parameterize
|
self.identifier.parameterize
|
||||||
|
|
|
@ -39,15 +39,14 @@
|
||||||
# business :boolean default("0")
|
# business :boolean default("0")
|
||||||
# profile_completed :boolean default("0")
|
# profile_completed :boolean default("0")
|
||||||
# laboratory_id :integer
|
# laboratory_id :integer
|
||||||
# is_shixun_marker :boolean default("0")
|
# platform :string(255) default("0")
|
||||||
# admin_visitable :boolean default("0")
|
# gitea_token :string(255)
|
||||||
# collaborator :boolean default("0")
|
|
||||||
# gitea_uid :integer
|
# gitea_uid :integer
|
||||||
|
# is_shixun_marker :boolean default("0")
|
||||||
# is_sync_pwd :boolean default("1")
|
# is_sync_pwd :boolean default("1")
|
||||||
# watchers_count :integer default("0")
|
# watchers_count :integer default("0")
|
||||||
# devops_step :integer default("0")
|
# devops_step :integer default("0")
|
||||||
# gitea_token :string(255)
|
# sign_cla :boolean default("0")
|
||||||
# platform :string(255)
|
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -56,8 +55,7 @@
|
||||||
# index_users_on_homepage_teacher (homepage_teacher)
|
# index_users_on_homepage_teacher (homepage_teacher)
|
||||||
# index_users_on_laboratory_id (laboratory_id)
|
# index_users_on_laboratory_id (laboratory_id)
|
||||||
# index_users_on_login (login) UNIQUE
|
# index_users_on_login (login) UNIQUE
|
||||||
# index_users_on_mail (mail) UNIQUE
|
# index_users_on_mail (mail)
|
||||||
# index_users_on_phone (phone) UNIQUE
|
|
||||||
# index_users_on_type (type)
|
# index_users_on_type (type)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -463,6 +461,23 @@ class User < Owner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def register_gitea
|
||||||
|
psd = "12345678"
|
||||||
|
interactor = Gitea::RegisterInteractor.call({username: self.login, email: self.mail, password: psd})
|
||||||
|
if interactor.success?
|
||||||
|
gitea_user = interactor.result
|
||||||
|
result = Gitea::User::GenerateTokenService.call(self.login, psd)
|
||||||
|
self.gitea_token = result['sha1']
|
||||||
|
self.gitea_uid = gitea_user[:body]['id']
|
||||||
|
self.password = psd
|
||||||
|
self.password_confirmation = psd
|
||||||
|
if self.save!
|
||||||
|
UserExtension.create!(user_id: self.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def activate!
|
def activate!
|
||||||
update_attribute(:status, STATUS_ACTIVE)
|
update_attribute(:status, STATUS_ACTIVE)
|
||||||
prohibit_gitea_user_login!(false)
|
prohibit_gitea_user_login!(false)
|
||||||
|
@ -838,7 +853,8 @@ class User < Owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile_is_completed?
|
def profile_is_completed?
|
||||||
self.nickname.present? && self.mail.present?
|
#self.nickname.present? && self.mail.present?
|
||||||
|
self.mail.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def trace_token
|
def trace_token
|
||||||
|
@ -861,7 +877,7 @@ class User < Owner
|
||||||
|
|
||||||
# 重写gitea_token,当用户为bot类型时,替换成管理员token
|
# 重写gitea_token,当用户为bot类型时,替换成管理员token
|
||||||
def gitea_token
|
def gitea_token
|
||||||
if self.platform == "bot"
|
if self.respond_to?('platform') && self.platform == "bot"
|
||||||
GiteaService.gitea_config[:admin_token]
|
GiteaService.gitea_config[:admin_token]
|
||||||
else
|
else
|
||||||
self['gitea_token']
|
self['gitea_token']
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Gitea::Repository::ForkService < Gitea::ClientService
|
class Gitea::Repository::ForkService < Gitea::ClientService
|
||||||
attr_reader :old_owner, :target_owner, :repo_name, :organization
|
attr_reader :old_owner, :target_owner, :repo_name, :organization, :new_identifier
|
||||||
|
|
||||||
# old_owner: 被clone的项目(源项目)拥有者
|
# old_owner: 被clone的项目(源项目)拥有者
|
||||||
# target_owner: clone后的醒目(新项目)的拥有者
|
# target_owner: clone后的醒目(新项目)的拥有者
|
||||||
|
@ -7,10 +7,12 @@ class Gitea::Repository::ForkService < Gitea::ClientService
|
||||||
# {
|
# {
|
||||||
# "organization": "string" #组织名称
|
# "organization": "string" #组织名称
|
||||||
# }
|
# }
|
||||||
def initialize(old_owner, target_owner, repo_name, organization=nil)
|
def initialize(old_owner, target_owner, repo_name, organization=nil, new_identifier=nil)
|
||||||
@old_owner = old_owner
|
@old_owner = old_owner
|
||||||
@target_owner = target_owner
|
@target_owner = target_owner
|
||||||
@repo_name = repo_name
|
@repo_name = repo_name
|
||||||
|
@organization = organization
|
||||||
|
@new_identifier = new_identifier
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -24,6 +26,7 @@ class Gitea::Repository::ForkService < Gitea::ClientService
|
||||||
def request_params
|
def request_params
|
||||||
hash = Hash.new.merge(token: target_owner.gitea_token)
|
hash = Hash.new.merge(token: target_owner.gitea_token)
|
||||||
hash = hash.merge(data: {organization: organization}) if organization
|
hash = hash.merge(data: {organization: organization}) if organization
|
||||||
|
hash = hash.merge(data: {name: new_identifier}) if new_identifier
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ class Gitea::Repository::MigrateService < Gitea::ClientService
|
||||||
response = post(url, request_params)
|
response = post(url, request_params)
|
||||||
|
|
||||||
render_response(response)
|
render_response(response)
|
||||||
|
rescue => e
|
||||||
|
puts "MigrateService error: #{e.message}"
|
||||||
|
[500, e.message, ""]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
class Projects::ForkService < ApplicationService
|
class Projects::ForkService < ApplicationService
|
||||||
attr_reader :target_owner, :project, :organization
|
attr_reader :target_owner, :project, :organization, :new_name, :new_identifier
|
||||||
|
|
||||||
def initialize(target_owner, project, organization=nil)
|
def initialize(target_owner, project, organization=nil, new_name=nil, new_identifier=nil)
|
||||||
@target_owner = target_owner
|
@target_owner = target_owner
|
||||||
@project = project
|
@project = project
|
||||||
@organization = organization
|
@organization = organization
|
||||||
|
@new_name = new_name
|
||||||
|
@new_identifier = new_identifier
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -15,11 +17,13 @@ class Projects::ForkService < ApplicationService
|
||||||
:rep_identifier, :project_category_id, :project_language_id,
|
:rep_identifier, :project_category_id, :project_language_id,
|
||||||
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
||||||
|
|
||||||
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization).call
|
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call
|
||||||
|
|
||||||
clone_project.owner = @target_owner
|
clone_project.owner = @target_owner
|
||||||
clone_project.forked_from_project_id = @project.id
|
clone_project.forked_from_project_id = @project.id
|
||||||
clone_project.gpid = result['id']
|
clone_project.gpid = result['id']
|
||||||
|
clone_project.name = @new_name if @new_name.present?
|
||||||
|
clone_project.identifier = @new_identifier if @new_identifier.present?
|
||||||
clone_project.save!
|
clone_project.save!
|
||||||
|
|
||||||
new_repository = clone_project.repository
|
new_repository = clone_project.repository
|
||||||
|
|
|
@ -9,7 +9,6 @@ class Projects::MigrateService < ApplicationService
|
||||||
|
|
||||||
def call
|
def call
|
||||||
raise Error, "user_id不正确." unless authroize_user_id_success
|
raise Error, "user_id不正确." unless authroize_user_id_success
|
||||||
|
|
||||||
@project = Project.new(project_params)
|
@project = Project.new(project_params)
|
||||||
if @project.save!
|
if @project.save!
|
||||||
ProjectUnit.init_types(@project.id, project.project_type)
|
ProjectUnit.init_types(@project.id, project.project_type)
|
||||||
|
@ -55,6 +54,7 @@ class Projects::MigrateService < ApplicationService
|
||||||
user_id: params[:user_id],
|
user_id: params[:user_id],
|
||||||
login: params[:auth_username],
|
login: params[:auth_username],
|
||||||
password: params[:auth_password],
|
password: params[:auth_password],
|
||||||
|
auth_token: params[:auth_token],
|
||||||
is_mirror: params[:is_mirror],
|
is_mirror: params[:is_mirror],
|
||||||
source_clone_url: params[:source_clone_url]
|
source_clone_url: params[:source_clone_url]
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ class Repositories::MigrateService < ApplicationService
|
||||||
private: params[:hidden],
|
private: params[:hidden],
|
||||||
mirror: wrapper_mirror || false,
|
mirror: wrapper_mirror || false,
|
||||||
auth_username: params[:login],
|
auth_username: params[:login],
|
||||||
auth_password: Base64.decode64(params[:password] || "")
|
auth_password: Base64.decode64(params[:password] || ""),
|
||||||
|
auth_token: params[:auth_token]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ json.issue_versions @project_versions
|
||||||
json.issue_priories @project_priories
|
json.issue_priories @project_priories
|
||||||
json.project_author @project.owner.try(:show_real_name)
|
json.project_author @project.owner.try(:show_real_name)
|
||||||
json.project_name @project.try(:name)
|
json.project_name @project.try(:name)
|
||||||
|
json.disable_pr_vew @project.pr_view_admin? && !@project.manager?(current_user)
|
||||||
json.members do
|
json.members do
|
||||||
json.array! @project_members.to_a.each do |user|
|
json.array! @project_members.to_a.each do |user|
|
||||||
json.id user.id
|
json.id user.id
|
||||||
|
|
|
@ -10,6 +10,7 @@ json.project_name @project.name
|
||||||
json.project_author @project.owner.try(:login)
|
json.project_author @project.owner.try(:login)
|
||||||
json.project_author_name @project.owner.try(:show_real_name)
|
json.project_author_name @project.owner.try(:show_real_name)
|
||||||
json.has_created_pull_requests @project.pull_requests.size > 0
|
json.has_created_pull_requests @project.pull_requests.size > 0
|
||||||
|
json.disable_pr_vew @project.pr_view_admin? && !@project.manager?(current_user)
|
||||||
|
|
||||||
json.issues do
|
json.issues do
|
||||||
json.array! @issues.to_a do |issue|
|
json.array! @issues.to_a do |issue|
|
||||||
|
|
|
@ -16,5 +16,5 @@ $gitea_hat_client = Gitea::Api::Hat::Client.new({
|
||||||
hat_base_url: gitea_config[:hat_base_url],
|
hat_base_url: gitea_config[:hat_base_url],
|
||||||
username: gitea_config[:access_key_id],
|
username: gitea_config[:access_key_id],
|
||||||
password: gitea_config[:access_key_secret],
|
password: gitea_config[:access_key_secret],
|
||||||
log_filepath: "log/gitea-client.log"
|
log_filepath: "log/gitea-hat-client.log"
|
||||||
})
|
})
|
|
@ -15,7 +15,7 @@ namespace :batch_forked_project do
|
||||||
user = User.find_by(login: username)
|
user = User.find_by(login: username)
|
||||||
next if user.blank?
|
next if user.blank?
|
||||||
next if Project.exists?(user_id: user.id, identifier: project.identifier)
|
next if Project.exists?(user_id: user.id, identifier: project.identifier)
|
||||||
new_project = Projects::ForkService.new(user, project, nil).call
|
new_project = Projects::ForkService.new(user, project, nil, nil, nil).call
|
||||||
random_num = rand(5..20)
|
random_num = rand(5..20)
|
||||||
members = user_logins.sample(random_num)
|
members = user_logins.sample(random_num)
|
||||||
members.each do |m|
|
members.each do |m|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
namespace :init_project_topic do
|
namespace :init_project_topic do
|
||||||
desc "Init Project Topic for Project"
|
desc "Init Project Topic for Project"
|
||||||
task project: :environment do
|
task project: :environment do
|
||||||
Project.order(created_at: :desc).find_each do |p|
|
Project.where(platform: 'forge').order(created_at: :desc).find_each do |p|
|
||||||
next unless p.owner.present?
|
next unless p.owner.present?
|
||||||
next if p.project_topics.size >= 3
|
next if p.project_topics.size >= 3
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in New Issue