forked from Gitlink/forgeplus
Compare commits
112 Commits
standalone
...
dev_educod
| Author | SHA1 | Date |
|---|---|---|
|
|
fccaa476e4 | |
|
|
807e91a839 | |
|
|
13497ae6dc | |
|
|
9955619398 | |
|
|
ae2a2725f7 | |
|
|
6220d851ae | |
|
|
d2e18d9c0c | |
|
|
039ca21f30 | |
|
|
cbc74e4709 | |
|
|
fd4806012d | |
|
|
4825c910f0 | |
|
|
ace13abe92 | |
|
|
e8da6364d8 | |
|
|
a7e20dcae2 | |
|
|
06e24a8ea4 | |
|
|
070df3c9dd | |
|
|
7c0bc5d444 | |
|
|
6ebab1be66 | |
|
|
27f510e6c9 | |
|
|
d9a27b7728 | |
|
|
68f1d7f7f6 | |
|
|
7e3517d873 | |
|
|
877ef54b24 | |
|
|
133eed6afe | |
|
|
eba2df5a2d | |
|
|
85a37fdbcc | |
|
|
01341d4389 | |
|
|
a62b29a263 | |
|
|
3a475a4674 | |
|
|
0eccafcb69 | |
|
|
0dbed862a7 | |
|
|
dfc998a9cc | |
|
|
8be4bc823c | |
|
|
7af6d8d754 | |
|
|
5a8dc9d5e7 | |
|
|
ecdb79ee48 | |
|
|
50e0ad9804 | |
|
|
953d6790d0 | |
|
|
136d1c1abd | |
|
|
e085ef374b | |
|
|
a557139ad0 | |
|
|
6d0ac60d5a | |
|
|
dda1868a72 | |
|
|
93a1a08393 | |
|
|
4d4d8d1369 | |
|
|
ab42fb7476 | |
|
|
11ac2f9c9d | |
|
|
8a9c3df2e5 | |
|
|
e90f80255e | |
|
|
1b6c082480 | |
|
|
ce1152cd4f | |
|
|
c8a9094ad0 | |
|
|
569088d846 | |
|
|
6159cda155 | |
|
|
d738ea432b | |
|
|
4a30e8c83f | |
|
|
b3288937c9 | |
|
|
7520fa03c2 | |
|
|
f282d971e3 | |
|
|
56f01801ae | |
|
|
45e70367d5 | |
|
|
a0b376e70a | |
|
|
d62d757c42 | |
|
|
033c2607e2 | |
|
|
0d6abdf7d0 | |
|
|
22c68f4c70 | |
|
|
fcd86fb01b | |
|
|
faecb99136 | |
|
|
15a002f601 | |
|
|
206d7bc159 | |
|
|
5e0006a830 | |
|
|
3abf993463 | |
|
|
efbf6d627d | |
|
|
6836907146 | |
|
|
6c4058cde5 | |
|
|
5a2e17abe2 | |
|
|
9a8b89bcd8 | |
|
|
4856da1607 | |
|
|
883a5f7e38 | |
|
|
1658c1b923 | |
|
|
74f6a54d29 | |
|
|
adb315521e | |
|
|
01cad866b8 | |
|
|
3447b17cdf | |
|
|
0079255e98 | |
|
|
490bff5ded | |
|
|
008b8ac709 | |
|
|
d0532a8f70 | |
|
|
a8c4cde350 | |
|
|
5de5974102 | |
|
|
3d3e778078 | |
|
|
f5ea8dc4a2 | |
|
|
c4b942a5f2 | |
|
|
13391b189a | |
|
|
b116a72ce7 | |
|
|
f01aec94d6 | |
|
|
cc97f85a1e | |
|
|
133995080a | |
|
|
27304c35dc | |
|
|
d6bf85ef73 | |
|
|
be9c01bf1d | |
|
|
edeaaa5db7 | |
|
|
0e41b6cc9b | |
|
|
5f3946f187 | |
|
|
b7be00f3ec | |
|
|
9b21e29426 | |
|
|
f37fccfdb3 | |
|
|
810d2dbac6 | |
|
|
6af97d865f | |
|
|
efba4b2b4f | |
|
|
aaf1f43cc2 | |
|
|
823c99bd71 |
|
|
@ -6,6 +6,20 @@ class AccountsController < ApplicationController
|
||||||
render json: session
|
render json: session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 为了同步平台上未注册gitea的用户
|
||||||
|
def gitea_register
|
||||||
|
user = User.find_by(login: sync_gitea_params[:login])
|
||||||
|
Users::SyncGiteaForm.new(sync_gitea_params.merge(user: user)).validate!
|
||||||
|
return render_error("该用户已同步协作平台") if user.gitea_token.present? && user.gitea_uid.present?
|
||||||
|
|
||||||
|
result = create_gitea_user!(user, sync_gitea_params[:login], sync_gitea_params[:email], sync_gitea_params[:password])
|
||||||
|
|
||||||
|
result[:user] ? render_ok : render_error(result[:message])
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(-1, e.message)
|
||||||
|
end
|
||||||
|
|
||||||
# 其他平台同步注册的用户
|
# 其他平台同步注册的用户
|
||||||
def remote_register
|
def remote_register
|
||||||
username = params[:username]&.gsub(/\s+/, "")
|
username = params[:username]&.gsub(/\s+/, "")
|
||||||
|
|
@ -362,6 +376,10 @@ class AccountsController < ApplicationController
|
||||||
{ login: pre + code, email: email, phone: phone }
|
{ login: pre + code, email: email, phone: phone }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync_gitea_params
|
||||||
|
params.permit(:login, :email, :password)
|
||||||
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:login, :email, :phone)
|
params.require(:user).permit(:login, :email, :phone)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,15 @@ module LaboratoryHelper
|
||||||
# my_projects: "/users/#{current_user.try(:login)}/projects",
|
# my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||||
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
|
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
|
||||||
{
|
{
|
||||||
new_syllabuses: "https://www.trustie.net/syllabuses/new",
|
new_syllabuses: "https://forge.educoder.net/syllabuses/new",
|
||||||
new_course: "https://www.trustie.net/courses/new",
|
new_course: "https://forge.educoder.net/courses/new",
|
||||||
edit_account: "https://www.trustie.net/my/account",
|
edit_account: "https://forge.educoder.net/my/account",
|
||||||
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
my_courses: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_courselist",
|
||||||
my_projects: "/users/#{current_user.try(:login)}/projects",
|
my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||||
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
my_organ: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_organizations",
|
||||||
default_url: Rails.application.config_for(:configuration)['platform_url'],
|
default_url: "https://www.educoder.net/",
|
||||||
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
|
tiding_url: "https://www.educoder.net/users/#{current_user.try(:login)}/user_tidings",
|
||||||
register_url: "https://www.trustie.net/login?login=false"
|
register_url: "https://www.educoder.net/user/register"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ module RegisterHelper
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def autologin_register(username, email, password, platform= 'forge')
|
def autologin_register(username, email, password, platform= 'forge')
|
||||||
result = {message: nil, user: nil}
|
|
||||||
|
|
||||||
user = User.new(admin: false, login: username, mail: email, type: "User")
|
user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||||
user.password = password
|
user.password = password
|
||||||
user.platform = platform
|
user.platform = platform
|
||||||
|
|
@ -11,20 +9,32 @@ module RegisterHelper
|
||||||
|
|
||||||
return unless user.valid?
|
return unless user.valid?
|
||||||
|
|
||||||
|
create_gitea_user!(user, username, email, password)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_gitea_user!(forge_user, username, email, password=random_password)
|
||||||
|
result = {message: nil, user: nil}
|
||||||
|
|
||||||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||||
if interactor.success?
|
if interactor.success?
|
||||||
gitea_user = interactor.result
|
gitea_user = interactor.result
|
||||||
|
Rails.logger.info "##### [gitea] create_gitea_user result: #{gitea_user}"
|
||||||
result = Gitea::User::GenerateTokenService.call(username, password)
|
result = Gitea::User::GenerateTokenService.call(username, password)
|
||||||
user.gitea_token = result['sha1']
|
forge_user.gitea_token = result['sha1']
|
||||||
user.gitea_uid = gitea_user[:body]['id']
|
forge_user.gitea_uid = gitea_user[:body]['id']
|
||||||
if user.save!
|
forge_user.mail = email
|
||||||
UserExtension.create!(user_id: user.id)
|
if forge_user.save
|
||||||
result[:user] = {id: user.id, token: user.gitea_token}
|
UserExtension.create!(user_id: forge_user.id) if forge_user.user_extension.blank?
|
||||||
|
result[:user] = {id: forge_user.id, token: forge_user.gitea_token}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
Rails.logger.info "##### [gitea] create_gitea_user result: #{interactor.error}"
|
||||||
result[:message] = interactor.error
|
result[:message] = interactor.error
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def random_password
|
||||||
|
"#{Random.rand(11111111)}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,14 @@ class ForksController < ApplicationController
|
||||||
|
|
||||||
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]).call
|
||||||
|
|
||||||
|
# TODO: fix Educoder shixun
|
||||||
|
if @new_project.persisted?
|
||||||
|
ProjectScore.create(:project_id => @new_project.id, :score => 0) if @new_project.project_score.nil?
|
||||||
|
|
||||||
|
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @new_project.id)
|
||||||
|
@project.project_infos << project_info
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,14 @@ class MainController < ApplicationController
|
||||||
uid_logger("main start is #{cookies[:_educoder_session]}")
|
uid_logger("main start is #{cookies[:_educoder_session]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:path] && params[:path].start_with?('projects/')
|
||||||
|
project_id = params[:path].split("/")[1]
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
if project.present?
|
||||||
|
return redirect_to("/projects/#{project.owner.login}/#{project.identifier}", status: 301)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
||||||
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
||||||
render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html'
|
render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html'
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ class MembersController < ApplicationController
|
||||||
before_action :check_member_not_exists!, only: %i[remove change_role]
|
before_action :check_member_not_exists!, only: %i[remove change_role]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
if @user.gitea_token.blank?
|
||||||
|
result = Gitea::User::GetService.call(@user.login)
|
||||||
|
if result[:status] == :error
|
||||||
|
# gitea不存在用户@user,直接注册
|
||||||
|
user_result = create_gitea_user!(@user, @user.login, @user.mail)
|
||||||
|
return render_error(user_result[:message]) if user_result[:message]
|
||||||
|
end
|
||||||
|
end
|
||||||
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
||||||
SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,13 @@ 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
|
||||||
|
|
||||||
|
# TODO: fix Educoder shixun
|
||||||
|
if @project.persisted?
|
||||||
|
ProjectScore.create(:project_id => @project.id, :score => 0) if @project.project_score.nil?
|
||||||
|
|
||||||
|
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @project.id)
|
||||||
|
@project.project_infos << project_info
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ class RepositoriesController < ApplicationController
|
||||||
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
||||||
if local_requests.save
|
if local_requests.save
|
||||||
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
||||||
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
|
if gitea_request[:status] == :success && local_requests.update_attributes(gitea_number: gitea_request["body"]["number"])
|
||||||
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,310 +1,347 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include Ci::DbConnectable
|
include Ci::DbConnectable
|
||||||
|
|
||||||
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
|
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
|
||||||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
|
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
|
||||||
before_action :require_login, only: %i[me list sync_user_info]
|
before_action :require_login, only: %i[me list]
|
||||||
before_action :connect_to_ci_db, only: [:get_user_info]
|
before_action :connect_to_ci_db, only: [:get_user_info]
|
||||||
before_action :convert_image!, only: [:update]
|
before_action :convert_image!, only: [:update]
|
||||||
skip_before_action :check_sign, only: [:attachment_show]
|
skip_before_action :check_sign, only: [:attachment_show]
|
||||||
|
|
||||||
def connect_to_ci_db(options={})
|
def connect_to_ci_db(options={})
|
||||||
if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?)
|
if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
|
if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
|
||||||
connect_to_trustie_ci_database(options)
|
connect_to_trustie_ci_database(options)
|
||||||
else
|
else
|
||||||
connect_to_ci_database(options)
|
connect_to_ci_database(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def list
|
def list
|
||||||
scope = User.active.recent.like(params[:search]).includes(:user_extension)
|
scope = User.active.recent.like(params[:search]).includes(:user_extension)
|
||||||
@total_count = scope.size
|
@total_count = scope.size
|
||||||
@users = paginate(scope)
|
@users = paginate(scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
#待办事项,现在未做
|
#待办事项,现在未做
|
||||||
if User.current.admin? || User.current.login == @user.login
|
if User.current.admin? || User.current.login == @user.login
|
||||||
@waiting_applied_messages = @user.applied_messages.waiting
|
@waiting_applied_messages = @user.applied_messages.waiting
|
||||||
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common
|
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common
|
||||||
@common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common
|
@common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common
|
||||||
@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
|
@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
|
||||||
else
|
else
|
||||||
@waiting_applied_messages = AppliedMessage.none
|
@waiting_applied_messages = AppliedMessage.none
|
||||||
@common_applied_transfer_projects = AppliedTransferProject.none
|
@common_applied_transfer_projects = AppliedTransferProject.none
|
||||||
@common_applied_projects = AppliedProject.none
|
@common_applied_projects = AppliedProject.none
|
||||||
@undo_events = 0
|
@undo_events = 0
|
||||||
end
|
end
|
||||||
#用户的组织数量
|
#用户的组织数量
|
||||||
# @user_composes_count = @user.composes.size
|
# @user_composes_count = @user.composes.size
|
||||||
@user_composes_count = 0
|
@user_composes_count = 0
|
||||||
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
|
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
|
||||||
@user_org_count = user_organizations.size
|
@user_org_count = user_organizations.size
|
||||||
normal_projects = Project.members_projects(@user.id).to_sql
|
normal_projects = Project.members_projects(@user.id).to_sql
|
||||||
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql
|
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql
|
||||||
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
||||||
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible
|
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible
|
||||||
@projects_common_count = user_projects.common.size
|
@projects_common_count = user_projects.common.size
|
||||||
@projects_mirrior_count = user_projects.mirror.size
|
@projects_mirrior_count = user_projects.mirror.size
|
||||||
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch_users
|
def watch_users
|
||||||
watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc")
|
watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc")
|
||||||
if params[:search].present?
|
if params[:search].present?
|
||||||
search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id)
|
search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id)
|
||||||
watchers = watchers.where(watchable_id: search_user_ids)
|
watchers = watchers.where(watchable_id: search_user_ids)
|
||||||
end
|
end
|
||||||
@watchers_count = watchers.size
|
@watchers_count = watchers.size
|
||||||
@watchers = paginate(watchers)
|
@watchers = paginate(watchers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fan_users
|
def fan_users
|
||||||
watchers = @user.watchers.includes(:user).order("watchers.created_at desc")
|
watchers = @user.watchers.includes(:user).order("watchers.created_at desc")
|
||||||
watchers = watchers.joins(:user).merge(User.like(params[:search]))
|
watchers = watchers.joins(:user).merge(User.like(params[:search]))
|
||||||
@watchers_count = watchers.size
|
@watchers_count = watchers.size
|
||||||
@watchers = paginate(watchers)
|
@watchers = paginate(watchers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hovercard
|
def hovercard
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
||||||
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||||
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
||||||
@user.attributes = user_params.except(:image)
|
@user.attributes = user_params.except(:image)
|
||||||
unless @user.save
|
unless @user.save
|
||||||
render_error(@user.errors.full_messages.join(", "))
|
render_error(@user.errors.full_messages.join(", "))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def me
|
def me
|
||||||
@user = current_user
|
@user = current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
# 贴吧获取用户信接口
|
# 贴吧获取用户信接口
|
||||||
def get_user_info
|
def get_user_info
|
||||||
begin
|
begin
|
||||||
@user = current_user
|
@user = current_user
|
||||||
begin
|
begin
|
||||||
result = Notice::Read::CountService.call(current_user.id)
|
result = Notice::Read::CountService.call(current_user.id)
|
||||||
@message_unread_total = result.nil? ? 0 : result[2]["unread_notification"]
|
@message_unread_total = result.nil? ? 0 : result[2]["unread_notification"]
|
||||||
rescue
|
rescue
|
||||||
@message_unread_total = 0
|
@message_unread_total = 0
|
||||||
end
|
end
|
||||||
# TODO 等消息上线再打开注释
|
# TODO 等消息上线再打开注释
|
||||||
#@tidding_count = unviewed_tiddings(current_user) if current_user.present?
|
#@tidding_count = unviewed_tiddings(current_user) if current_user.present?
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
missing_template
|
missing_template
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_show
|
def attachment_show
|
||||||
file_name = params[:file_name]
|
file_name = params[:file_name]
|
||||||
path = params[:path] || file_storage_directory
|
path = params[:path] || file_storage_directory
|
||||||
send_file "#{path}/#{file_name}", :filename => "#{file_name}",
|
send_file "#{path}/#{file_name}", :filename => "#{file_name}",
|
||||||
:type => 'game',
|
:type => 'game',
|
||||||
:disposition => 'attachment' #inline can open in browser
|
:disposition => 'attachment' #inline can open in browser
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_show
|
def html_show
|
||||||
@contents = File.read("#{params[:path]}")
|
@contents = File.read("#{params[:path]}")
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {render :layout => false}
|
format.html {render :layout => false}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redo: 消息总数缓存
|
# Redo: 消息总数缓存
|
||||||
def get_navigation_info
|
def get_navigation_info
|
||||||
# @old_domain = edu_setting('old_edu_host')
|
# @old_domain = edu_setting('old_edu_host')
|
||||||
# @user = current_user
|
# @user = current_user
|
||||||
# # 新消息数
|
# # 新消息数
|
||||||
# @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0
|
# @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0
|
||||||
#
|
#
|
||||||
# @user_url = "/users/#{@user.login}"
|
# @user_url = "/users/#{@user.login}"
|
||||||
# @career = Career.where(status: true).order("created_at asc").pluck(:id, :name)
|
# @career = Career.where(status: true).order("created_at asc").pluck(:id, :name)
|
||||||
# @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil
|
# @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# 用户回复功能
|
# 用户回复功能
|
||||||
def reply_message
|
def reply_message
|
||||||
message = JournalsForMessage.new(reply_message_params)
|
message = JournalsForMessage.new(reply_message_params)
|
||||||
message.user_id = current_user.id
|
message.user_id = current_user.id
|
||||||
message.save!
|
message.save!
|
||||||
|
|
||||||
render_ok(id: message.id)
|
render_ok(id: message.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# 搜索用户具有管理员角色的项目
|
# 搜索用户具有管理员角色的项目
|
||||||
def search_user_projects
|
def search_user_projects
|
||||||
projects = Project.where.not(status: 9)
|
projects = Project.where.not(status: 9)
|
||||||
|
|
||||||
projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 })
|
projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 })
|
||||||
projects = projects.where(members: { user_id: current_user.id })
|
projects = projects.where(members: { user_id: current_user.id })
|
||||||
|
|
||||||
search = params[:search].to_s.strip
|
search = params[:search].to_s.strip
|
||||||
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
|
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
|
||||||
|
|
||||||
@projects = projects.select(:id, :name)
|
@projects = projects.select(:id, :name)
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO 个人主页信息,forge上弃用-hs, 0602
|
#TODO 个人主页信息,forge上弃用-hs, 0602
|
||||||
def homepage_info
|
def homepage_info
|
||||||
#待办事项,现在未做
|
#待办事项,现在未做
|
||||||
@undo_events = 10
|
@undo_events = 10
|
||||||
#用户的组织数量
|
#用户的组织数量
|
||||||
# @user_composes_count = @user.composes.size
|
# @user_composes_count = @user.composes.size
|
||||||
@user_composes_count = 10
|
@user_composes_count = 10
|
||||||
end
|
end
|
||||||
|
|
||||||
def brief_introduction
|
def brief_introduction
|
||||||
content = params[:content].to_s.strip
|
content = params[:content].to_s.strip
|
||||||
|
|
||||||
current_user.user_extension.update!(brief_introduction: content)
|
current_user.user_extension.update!(brief_introduction: content)
|
||||||
|
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def attendance
|
def attendance
|
||||||
attendance = Users::AttendanceService.call(current_user)
|
attendance = Users::AttendanceService.call(current_user)
|
||||||
render_ok(grade: current_user.grade, next_gold: attendance.next_gold)
|
render_ok(grade: current_user.grade, next_gold: attendance.next_gold)
|
||||||
rescue Users::AttendanceService::Error => ex
|
rescue Users::AttendanceService::Error => ex
|
||||||
render_error(ex.message)
|
render_error(ex.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# 其他平台登录后,必须将token同步到forge平台,实现sso登录功能
|
# 其他平台登录后,必须将token同步到forge平台,实现sso登录功能
|
||||||
def sync_token
|
def sync_token
|
||||||
return render_error('未找相关用户!') unless @user
|
return render_error('未找相关用户!') unless @user
|
||||||
|
|
||||||
token = Token.get_or_create_permanent_login_token(@user, 'autologin')
|
token = Token.get_or_create_permanent_login_token(@user, 'autologin')
|
||||||
token.update_column(:value, params[:token])
|
token.update_column(:value, params[:token])
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def trustie_related_projects
|
def trustie_related_projects
|
||||||
projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
|
projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
|
||||||
projects_json = []
|
projects_json = []
|
||||||
domain_url = EduSetting.get('host_name') + '/projects'
|
domain_url = EduSetting.get('host_name') + '/projects'
|
||||||
if projects.present?
|
if projects.present?
|
||||||
projects.each do |p|
|
projects.each do |p|
|
||||||
project_url = "/#{p.owner.login}/#{p.identifier}"
|
project_url = "/#{p.owner.login}/#{p.identifier}"
|
||||||
pj = {
|
pj = {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
name: p.name,
|
name: p.name,
|
||||||
is_public: p.is_public,
|
is_public: p.is_public,
|
||||||
updated_on: p.updated_on.strftime("%Y-%m-%d"),
|
updated_on: p.updated_on.strftime("%Y-%m-%d"),
|
||||||
status: p.status,
|
status: p.status,
|
||||||
is_member: p.member?(current_user.try(:id)),
|
is_member: p.member?(current_user.try(:id)),
|
||||||
owner: {
|
owner: {
|
||||||
name: p.owner.try(:show_real_name),
|
name: p.owner.try(:show_real_name),
|
||||||
login: p.owner.login
|
login: p.owner.login
|
||||||
},
|
},
|
||||||
members_count: p&.members.size,
|
members_count: p&.members.size,
|
||||||
issues_count: p.issues_count - p.pull_requests_count,
|
issues_count: p.issues_count - p.pull_requests_count,
|
||||||
commits_count: p&.project_score&.changeset_num.to_i,
|
commits_count: p&.project_score&.changeset_num.to_i,
|
||||||
http_url: domain_url + project_url,
|
http_url: domain_url + project_url,
|
||||||
http_collaborator_url: domain_url + project_url + "/setting/collaborator",
|
http_collaborator_url: domain_url + project_url + "/setting/collaborator",
|
||||||
http_issues_url: domain_url + project_url + "/issues",
|
http_issues_url: domain_url + project_url + "/issues",
|
||||||
http_commits_url: domain_url + project_url + "/commits",
|
http_commits_url: domain_url + project_url + "/commits",
|
||||||
project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {}
|
project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {}
|
||||||
}
|
}
|
||||||
projects_json.push(pj)
|
projects_json.push(pj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Rails.logger.info("==========projects_json========+########{projects_json}")
|
Rails.logger.info("==========projects_json========+########{projects_json}")
|
||||||
render json: { projects: projects_json.present? ? projects_json : {} }
|
render json: { projects: projects_json.present? ? projects_json : {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
def trustie_projects
|
def trustie_projects
|
||||||
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id
|
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id
|
||||||
projects = Project.visible
|
projects = Project.visible
|
||||||
|
|
||||||
projects = projects.joins(:members).where(members: { user_id: user_id })
|
projects = projects.joins(:members).where(members: { user_id: user_id })
|
||||||
|
|
||||||
search = params[:search].to_s.strip
|
search = params[:search].to_s.strip
|
||||||
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
|
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
|
||||||
|
|
||||||
projects = projects.select(:id, :name).limit(10).as_json
|
projects = projects.select(:id, :name).limit(10).as_json
|
||||||
render json: { projects: projects }
|
render json: { projects: projects }
|
||||||
end
|
end
|
||||||
|
|
||||||
def projects
|
def projects
|
||||||
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||||
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
|
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
|
||||||
@total_count = scope.size
|
@total_count = scope.size
|
||||||
@projects = paginate(scope)
|
@projects = paginate(scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO 其他平台登录时同步修改gitea平台对应用户的密码
|
# TODO 其他平台登录时同步修改gitea平台对应用户的密码
|
||||||
# 该方法主要用于:别的平台初次部署对接forge平台,同步用户后,gitea平台对应的用户密码与forge平台用户密码不一致是问题
|
# 该方法主要用于:别的平台初次部署对接forge平台,同步用户后,gitea平台对应的用户密码与forge平台用户密码不一致是问题
|
||||||
def sync_gitea_pwd
|
def sync_gitea_pwd
|
||||||
return render_error("未找到相关的用户") if @user.blank?
|
return render_error("未找到相关的用户") if @user.blank?
|
||||||
|
|
||||||
flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s})
|
flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s})
|
||||||
flag ? render_ok : render_error('同步失败!')
|
flag ? render_ok : render_error('同步失败!')
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# 同步trusite平台用户的salt信息,只需同步一次,同步完成后,该方法可以删除
|
# 同步trusite平台用户的salt信息,只需同步一次,同步完成后,该方法可以删除
|
||||||
def sync_salt
|
def sync_salt
|
||||||
user = User.find_by_login params[:login]
|
user = User.find_by_login params[:login]
|
||||||
return if user.blank?
|
return if user.blank?
|
||||||
user.update_column(:salt, params[:salt])
|
user.update_column(:salt, params[:salt])
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_user_info
|
# TODO: For Educoder
|
||||||
user = User.find_by_login params[:login]
|
def change_password
|
||||||
return render_forbidden unless user === current_user
|
user = User.find_by_login params[:login]
|
||||||
|
return render_error("用户 #{params[:login]} 不存在.") if user.nil?
|
||||||
sync_params = {
|
|
||||||
email: params[:email],
|
form_params= {
|
||||||
password: params[:password]
|
login: params[:login],
|
||||||
}
|
email: user&.mail,
|
||||||
|
password: params[:password],
|
||||||
Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate!
|
user: user
|
||||||
|
}
|
||||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
Gitea::User::ChangePasswordForm.new(form_params).validate!
|
||||||
if interactor.success?
|
|
||||||
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
|
sync_params = {
|
||||||
render_ok
|
email: user&.mail,
|
||||||
else
|
password: params[:password]
|
||||||
render_error(interactor.error)
|
}
|
||||||
end
|
|
||||||
end
|
if sync_params.present?
|
||||||
|
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||||
private
|
if interactor.success?
|
||||||
def load_user
|
user.update!(password: params[:password], is_sync_pwd: true)
|
||||||
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
render_ok
|
||||||
end
|
else
|
||||||
|
render_error(interactor.error)
|
||||||
def user_params
|
end
|
||||||
params.require(:user).permit(:nickname, :image,
|
end
|
||||||
user_extension_attributes: [
|
end
|
||||||
:gender, :location, :location_city,
|
|
||||||
:occupation, :technical_title,
|
# TODO: For Educoder
|
||||||
:school_id, :department_id, :province, :city,
|
def change_email
|
||||||
:custom_department, :identity, :student_id, :description,
|
user = User.find_by_login params[:login]
|
||||||
:show_email, :show_location, :show_department]
|
return render_error("用户 #{rq_params[:login]} 不存在.") if user.nil?
|
||||||
)
|
|
||||||
end
|
form_params= {
|
||||||
|
login: params[:login],
|
||||||
def reply_message_params
|
email: user&.mail,
|
||||||
normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? ||
|
user: user
|
||||||
params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil?
|
}
|
||||||
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id)
|
|
||||||
end
|
Gitea::User::ChangeEmailForm.new(form_params).validate!
|
||||||
|
|
||||||
def check_user_exist
|
sync_params = {
|
||||||
return if @user.present?
|
email: params[:email]
|
||||||
render_not_found
|
}
|
||||||
end
|
|
||||||
|
if sync_params.present?
|
||||||
end
|
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||||
|
if interactor.success?
|
||||||
|
user.update!(mail: params[:email])
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error(interactor.error)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def load_user
|
||||||
|
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_params
|
||||||
|
params.require(:user).permit(:nickname, :image,
|
||||||
|
user_extension_attributes: [
|
||||||
|
:gender, :location, :location_city,
|
||||||
|
:occupation, :technical_title,
|
||||||
|
:school_id, :department_id, :province, :city,
|
||||||
|
:custom_department, :identity, :student_id, :description,
|
||||||
|
:show_email, :show_location, :show_department]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reply_message_params
|
||||||
|
normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? ||
|
||||||
|
params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil?
|
||||||
|
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_user_exist
|
||||||
|
return if @user.present?
|
||||||
|
render_not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Gitea::User::ChangeEmailForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :user
|
||||||
|
attr_accessor :email, :login
|
||||||
|
|
||||||
|
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
|
||||||
|
validates :login, presence: true
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
class Gitea::User::ChangePasswordForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :user
|
||||||
|
attr_accessor :email, :login, :password
|
||||||
|
|
||||||
|
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
|
||||||
|
validates :login, presence: true
|
||||||
|
validates :password, presence: true
|
||||||
|
|
||||||
|
# validate :check_old_password
|
||||||
|
|
||||||
|
def check_old_password
|
||||||
|
return if user.check_password?(old_password.to_s)
|
||||||
|
|
||||||
|
errors.add(:old_password, :password_error)
|
||||||
|
end
|
||||||
|
|
||||||
|
# def check_user!
|
||||||
|
# user === current_user
|
||||||
|
# end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
class Users::SyncGiteaForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :login, :password, :email, :user
|
||||||
|
|
||||||
|
validates :login, :password, :email, presence: true
|
||||||
|
|
||||||
|
validate :check_user, :check_password
|
||||||
|
|
||||||
|
def check_user
|
||||||
|
user = User.find_by(login: login)
|
||||||
|
raise '用户不存在.' unless user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_password
|
||||||
|
raise '用户密码错误.' unless user.check_password?(password)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -23,13 +23,17 @@ module Gitea
|
||||||
def run
|
def run
|
||||||
Gitea::UserForm.new(params).validate!
|
Gitea::UserForm.new(params).validate!
|
||||||
response = Gitea::User::RegisterService.call(params.merge(token: token))
|
response = Gitea::User::RegisterService.call(params.merge(token: token))
|
||||||
render_result(response)
|
|
||||||
|
if response[:status] == :success
|
||||||
|
@result = response
|
||||||
|
else
|
||||||
|
fail!(response[:message])
|
||||||
|
end
|
||||||
rescue Exception => exception
|
rescue Exception => exception
|
||||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||||
fail!(exception.message)
|
fail!(exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :params
|
attr_reader :params
|
||||||
|
|
@ -38,10 +42,6 @@ module Gitea
|
||||||
@error = error
|
@error = error
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_result(response)
|
|
||||||
@result = response
|
|
||||||
end
|
|
||||||
|
|
||||||
def token
|
def token
|
||||||
{
|
{
|
||||||
username: Gitea.gitea_config[:access_key_id],
|
username: Gitea.gitea_config[:access_key_id],
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,6 @@ class Gitea::Pull < Gitea::Base
|
||||||
|
|
||||||
serialize :conflicted_files, Array
|
serialize :conflicted_files, Array
|
||||||
|
|
||||||
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_number, optional: true
|
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_id, optional: true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
# Table name: projects
|
# Table name: projects
|
||||||
|
|
@ -38,8 +37,6 @@
|
||||||
# rep_identifier :string(255)
|
# rep_identifier :string(255)
|
||||||
# project_category_id :integer
|
# project_category_id :integer
|
||||||
# project_language_id :integer
|
# project_language_id :integer
|
||||||
# license_id :integer
|
|
||||||
# ignore_id :integer
|
|
||||||
# praises_count :integer default("0")
|
# praises_count :integer default("0")
|
||||||
# watchers_count :integer default("0")
|
# watchers_count :integer default("0")
|
||||||
# issues_count :integer default("0")
|
# issues_count :integer default("0")
|
||||||
|
|
@ -53,9 +50,10 @@
|
||||||
# open_devops_count :integer default("0")
|
# open_devops_count :integer default("0")
|
||||||
# recommend :boolean default("0")
|
# recommend :boolean default("0")
|
||||||
# platform :integer default("0")
|
# platform :integer default("0")
|
||||||
|
# license_id :integer
|
||||||
|
# ignore_id :integer
|
||||||
# default_branch :string(255) default("master")
|
# default_branch :string(255) default("master")
|
||||||
# website :string(255)
|
# website :string(255)
|
||||||
# order_index :integer default("0")
|
|
||||||
# lesson_url :string(255)
|
# lesson_url :string(255)
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
|
|
@ -78,7 +76,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
include Matchable
|
include Matchable
|
||||||
include Publicable
|
include Publicable
|
||||||
|
|
@ -110,6 +107,7 @@ class Project < ApplicationRecord
|
||||||
has_one :project_educoder, dependent: :destroy
|
has_one :project_educoder, dependent: :destroy
|
||||||
|
|
||||||
has_one :project_score, dependent: :destroy
|
has_one :project_score, dependent: :destroy
|
||||||
|
has_many :project_infos, :dependent => :destroy
|
||||||
has_one :repository, dependent: :destroy
|
has_one :repository, dependent: :destroy
|
||||||
has_many :pull_requests, dependent: :destroy
|
has_many :pull_requests, dependent: :destroy
|
||||||
has_many :issue_tags, -> { order("issue_tags.created_at DESC") }, dependent: :destroy
|
has_many :issue_tags, -> { order("issue_tags.created_at DESC") }, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: project_infos
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# project_id :integer
|
||||||
|
# user_id :integer
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
|
||||||
|
class ProjectInfo < ActiveRecord::Base
|
||||||
|
|
||||||
|
belongs_to :project
|
||||||
|
belongs_to :user
|
||||||
|
validates_presence_of :project_id, :user_id
|
||||||
|
validates_uniqueness_of :project_id, :scope => :user_id
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
class ProjectUnit < ApplicationRecord
|
class ProjectUnit < ApplicationRecord
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
enum unit_type: {code: 1, issues: 2, pulls: 3, wiki:4, devops: 5, versions: 6, resources: 7}
|
enum unit_type: {code: 1, issues: 2, pulls: 3, devops: 4, versions: 5, resources: 6, gantt: 7, sonar: 8}
|
||||||
|
|
||||||
validates :unit_type, uniqueness: { scope: :project_id}
|
validates :unit_type, uniqueness: { scope: :project_id}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
# Table name: pull_requests
|
# Table name: pull_requests
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# pull_request_id :integer
|
# gitea_id :integer
|
||||||
# gpid :integer
|
# gitea_number :integer
|
||||||
# user_id :integer
|
# user_id :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
|
@ -37,7 +37,7 @@ class PullRequest < ApplicationRecord
|
||||||
has_many :pull_request_tags, foreign_key: :pull_request_id
|
has_many :pull_request_tags, foreign_key: :pull_request_id
|
||||||
has_many :project_trends, as: :trend, dependent: :destroy
|
has_many :project_trends, as: :trend, dependent: :destroy
|
||||||
has_many :attachments, as: :container, dependent: :destroy
|
has_many :attachments, as: :container, dependent: :destroy
|
||||||
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull'
|
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull'
|
||||||
|
|
||||||
scope :merged_and_closed, ->{where.not(status: 0)}
|
scope :merged_and_closed, ->{where.not(status: 0)}
|
||||||
scope :opening, -> {where(status: 0)}
|
scope :opening, -> {where(status: 0)}
|
||||||
|
|
|
||||||
|
|
@ -631,9 +631,16 @@ class User < Owner
|
||||||
|
|
||||||
# 工程认证的学校
|
# 工程认证的学校
|
||||||
def ec_school
|
def ec_school
|
||||||
school_id = self.ec_school_users.pluck(:school_id).first ||
|
school_id_hash = ActiveRecord::Base.connection.exec_query("SELECT `ec_school_users`.`school_id` FROM `ec_school_users` WHERE `ec_school_users`.`user_id` = #{self.id}").first ||
|
||||||
self.ec_major_schools.pluck(:school_id).first ||
|
ActiveRecord::Base.connection.exec_query("SELECT `ec_major_schools`.`school_id` FROM `ec_major_schools` INNER JOIN `ec_major_school_users` ON `ec_major_schools`.`id` = `ec_major_school_users`.`ec_major_school_id` WHERE`ec_major_school_users`.`user_id` = #{self.id}").first ||
|
||||||
(self.ec_course_users.first && self.ec_course_users.first.try(:ec_course).try(:ec_year).try(:ec_major_school).try(:school_id))
|
ActiveRecord::Base.connection.exec_query("SELECT `ec_major_schools`.`school_id` FROM `ec_major_schools` INNER JOIN `ec_years` ON `ec_years`.`ec_major_school_id` = `ec_major_schools`.`id` INNER JOIN `ec_courses` ON `ec_courses`.`ec_year_id` = `ec_years`.`id` INNER JOIN `ec_course_users` ON `ec_course_users`.`ec_course_id` = `ec_courses`.`id` WHERE `ec_course_users`.`user_id` = #{self.id}").first
|
||||||
|
if school_id_hash.nil?
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
school_id_hash["school_id"]
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# 登录,返回用户名与密码匹配的用户
|
# 登录,返回用户名与密码匹配的用户
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Version < ApplicationRecord
|
class Version < ApplicationRecord
|
||||||
belongs_to :project, counter_cache: true, touch: true
|
belongs_to :project, counter_cache: true, touch: true, optional: true
|
||||||
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
class Gitea::User::GetService < Gitea::ClientService
|
||||||
|
attr_reader :username
|
||||||
|
# params:
|
||||||
|
# username* string # required
|
||||||
|
def initialize(username)
|
||||||
|
@username = username
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
|
||||||
|
status, message, body = render_response(response)
|
||||||
|
json_format(status, message, body)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def url
|
||||||
|
"/users/#{username}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def params
|
||||||
|
{username: username}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def json_format(status, message, body)
|
||||||
|
case status
|
||||||
|
when 200 then success(body)
|
||||||
|
else
|
||||||
|
error(message, status)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,8 +10,7 @@ class Gitea::User::RegisterService < Gitea::ClientService
|
||||||
params = Hash.new.merge(data: user_params, token: @token)
|
params = Hash.new.merge(data: user_params, token: @token)
|
||||||
|
|
||||||
response = post(API_REST, params)
|
response = post(API_REST, params)
|
||||||
status, message, body = render_response(response)
|
response_payload(response)
|
||||||
json_format(status, message, body)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -27,11 +26,28 @@ class Gitea::User::RegisterService < Gitea::ClientService
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def json_format(status, message, body)
|
def response_payload(response)
|
||||||
|
status = response.status
|
||||||
|
body = response&.body
|
||||||
|
|
||||||
|
log_error(status, body)
|
||||||
|
status_payload(status, body)
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_payload(status, body)
|
||||||
case status
|
case status
|
||||||
when 201 then success(body)
|
when 201 then success(json_parse!(body))
|
||||||
else
|
when 403 then error("你没有权限操作!")
|
||||||
error(message, status)
|
when 400 then error("服务器开小差了")
|
||||||
|
when 422
|
||||||
|
body = json_parse!(body)
|
||||||
|
message = body['message']
|
||||||
|
if message.include?('email')
|
||||||
|
error("邮箱#{email}已被注册")
|
||||||
|
elsif message.include?('name')
|
||||||
|
error("用户名#{username}已被注册")
|
||||||
|
end
|
||||||
|
else error("系统错误!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,11 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if school && school.identifier.present? %>
|
<%# if school && school.identifier.present? %>
|
||||||
<% else %>
|
<%#= link_to school.identifier.to_s, statistics_college_path(school.identifier), target: '_blank' %>
|
||||||
|
<%# else %>
|
||||||
--
|
--
|
||||||
<% end %>
|
<%# end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="member-container">
|
<td class="member-container">
|
||||||
<div class="laboratory-user">
|
<div class="laboratory-user">
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
json.extract! @project, :id, :name,:identifier
|
json.extract! @project, :id, :name,:identifier
|
||||||
json.login @project&.owner.login
|
json.login @project&.owner&.login
|
||||||
|
|
@ -64,4 +64,10 @@ json.setting do
|
||||||
else
|
else
|
||||||
json.system_notification nil
|
json.system_notification nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if current_user.ec_school.blank?
|
||||||
|
json.engineer_url nil
|
||||||
|
else
|
||||||
|
json.engineer_url "#{EduSetting.get('engineer_education')}/ecs/department?school_id=#{current_user.ec_school}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,13 @@ 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.is_teacher @user.user_extension&.teacher?
|
json.is_teacher @user.user_extension&.teacher?
|
||||||
|
json.has_gitea_user @user.gitea_token.present? && @user.gitea_uid.present?
|
||||||
|
json.is_sync_pwd @user.is_sync_pwd
|
||||||
json.user_identity @user.identity
|
json.user_identity @user.identity
|
||||||
json.tidding_count 0
|
json.tidding_count 0
|
||||||
json.user_phone_binded @user.phone.present?
|
json.user_phone_binded @user.phone.present?
|
||||||
# json.phone @user.phone
|
# json.phone @user.phone
|
||||||
# json.email @user.mail
|
json.email @user.mail
|
||||||
json.profile_completed @user.profile_is_completed?
|
json.profile_completed @user.profile_is_completed?
|
||||||
json.professional_certification @user.professional_certification
|
json.professional_certification @user.professional_certification
|
||||||
json.devops_step @user.devops_step
|
json.devops_step @user.devops_step
|
||||||
|
|
@ -22,4 +24,4 @@ json.city @user.city
|
||||||
json.custom_department @user.custom_department
|
json.custom_department @user.custom_department
|
||||||
json.description @user.description
|
json.description @user.description
|
||||||
json.(@user, :show_email, :show_department, :show_location)
|
json.(@user, :show_email, :show_department, :show_location)
|
||||||
json.message_unread_total @message_unread_total
|
json.message_unread_total @message_unread_total
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
'zh-CN':
|
||||||
|
activemodel:
|
||||||
|
attributes:
|
||||||
|
gitea/user/change_password_form:
|
||||||
|
user: ''
|
||||||
|
email: 邮箱
|
||||||
|
login: 用户名
|
||||||
|
old_password: 旧密码
|
||||||
|
password: 新密码
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
gitea/user/change_password_form:
|
||||||
|
attributes:
|
||||||
|
old_password:
|
||||||
|
password_error: 错误
|
||||||
|
user:
|
||||||
|
not_exist: 不存在
|
||||||
|
|
@ -192,6 +192,7 @@ Rails.application.routes.draw do
|
||||||
get :logout
|
get :logout
|
||||||
get :get_verification_code
|
get :get_verification_code
|
||||||
get :valid_email_and_phone
|
get :valid_email_and_phone
|
||||||
|
post :gitea_register
|
||||||
post :remote_register
|
post :remote_register
|
||||||
post :remote_update
|
post :remote_update
|
||||||
post :remote_login
|
post :remote_login
|
||||||
|
|
@ -227,7 +228,8 @@ Rails.application.routes.draw do
|
||||||
post :sync_salt
|
post :sync_salt
|
||||||
get :trustie_projects
|
get :trustie_projects
|
||||||
get :trustie_related_projects
|
get :trustie_related_projects
|
||||||
post :sync_user_info
|
post :change_password
|
||||||
|
post :change_email
|
||||||
|
|
||||||
scope '/ci', module: :ci do
|
scope '/ci', module: :ci do
|
||||||
scope do
|
scope do
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddPlatformToUsers < ActiveRecord::Migration[5.2]
|
class AddPlatformToUsers < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :users, :platform, :string, default: 0
|
add_column :users, :platform, :string, default: 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddGiteaTokenToUsers < ActiveRecord::Migration[5.2]
|
class AddGiteaTokenToUsers < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :users, :gitea_token, :string
|
add_column :users, :gitea_token, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddProjectCategoryIdAndProjectLanguageIdToProjects < ActiveRecord::Migration[5.2]
|
class AddProjectCategoryIdAndProjectLanguageIdToProjects < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :projects, :project_category_id, :integer
|
add_column :projects, :project_category_id, :integer
|
||||||
# add_column :projects, :project_language_id, :integer
|
add_column :projects, :project_language_id, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class AddUserRefToRepository < ActiveRecord::Migration[5.2]
|
class AddUserRefToRepository < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :repositories, :user_id, :integer
|
add_column :repositories, :user_id, :integer
|
||||||
# add_index :repositories, :user_id
|
add_index :repositories, :user_id
|
||||||
|
|
||||||
Project.joins(:repository).find_each do |project|
|
Project.joins(:repository).find_each do |project|
|
||||||
project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?
|
project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddGiteaUidToUsers < ActiveRecord::Migration[5.2]
|
class AddGiteaUidToUsers < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :users, :gitea_uid, :integer
|
add_column :users, :gitea_uid, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddMirrorUrlToRepositories < ActiveRecord::Migration[5.2]
|
class AddMirrorUrlToRepositories < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :repositories, :mirror_url, :string
|
add_column :repositories, :mirror_url, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
class CreateIssueTags < ActiveRecord::Migration[5.2]
|
class CreateIssueTags < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# create_table :issue_tags do |t|
|
create_table :issue_tags do |t|
|
||||||
# t.string :title
|
t.string :title
|
||||||
# t.string :description
|
t.string :description
|
||||||
# t.string :color
|
t.string :color
|
||||||
# t.integer :user_id
|
t.integer :user_id
|
||||||
# t.integer :project_id
|
t.integer :project_id
|
||||||
# t.integer :issues_count,default: 0
|
t.integer :issues_count,default: 0
|
||||||
# t.timestamps
|
t.timestamps
|
||||||
# end
|
end
|
||||||
# add_index :issue_tags, [:user_id, :title,:project_id]
|
add_index :issue_tags, [:user_id, :title,:project_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddPraisesCountToProjects < ActiveRecord::Migration[5.2]
|
class AddPraisesCountToProjects < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :projects, :praises_count, :integer, :default => 0
|
add_column :projects, :praises_count, :integer, :default => 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
class AddIssuesTypeAndToken < ActiveRecord::Migration[5.2]
|
class AddIssuesTypeAndToken < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :issues, :issue_type, :string
|
add_column :issues, :issue_type, :string
|
||||||
# add_column :issues, :token, :string
|
add_column :issues, :token, :string
|
||||||
# add_column :issues, :issue_tag_ids, :string
|
add_column :issues, :issue_tag_ids, :string
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class RenameIssueTagTitle < ActiveRecord::Migration[5.2]
|
class RenameIssueTagTitle < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# rename_column :issue_tags, :title, :name
|
rename_column :issue_tags, :title, :name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
class CreateIssueTagsRelates < ActiveRecord::Migration[5.2]
|
class CreateIssueTagsRelates < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# create_table :issue_tags_relates do |t|
|
create_table :issue_tags_relates do |t|
|
||||||
# t.integer :issue_id
|
t.integer :issue_id
|
||||||
# t.integer :issue_tag_id
|
t.integer :issue_tag_id
|
||||||
# t.timestamps
|
t.timestamps
|
||||||
# end
|
end
|
||||||
# add_index :issue_tags_relates, [:issue_id, :issue_tag_id]
|
add_index :issue_tags_relates, [:issue_id, :issue_tag_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class RenameIssuesIssueTagIds < ActiveRecord::Migration[5.2]
|
class RenameIssuesIssueTagIds < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# rename_column :issues, :issue_tag_ids, :issue_tags_value
|
rename_column :issues, :issue_tag_ids, :issue_tags_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
class CreateIssueTimes < ActiveRecord::Migration[5.2]
|
class CreateIssueTimes < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# create_table :issue_times do |t|
|
create_table :issue_times do |t|
|
||||||
# t.integer :issue_id
|
t.integer :issue_id
|
||||||
# t.integer :user_id
|
t.integer :user_id
|
||||||
# t.datetime :start_time
|
t.datetime :start_time
|
||||||
# t.datetime :end_time
|
t.datetime :end_time
|
||||||
# t.string :cost_time
|
t.string :cost_time
|
||||||
# t.timestamps
|
t.timestamps
|
||||||
# end
|
end
|
||||||
# add_index :issue_times, [:issue_id, :user_id]
|
add_index :issue_times, [:issue_id, :user_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddIsLockToIssue < ActiveRecord::Migration[5.2]
|
class AddIsLockToIssue < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :issues, :is_lock, :boolean, default: false
|
add_column :issues, :is_lock, :boolean, default: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class AddWatchersCountToProjects < ActiveRecord::Migration[5.2]
|
class AddWatchersCountToProjects < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :projects, :watchers_count, :integer, :default => 0
|
add_column :projects, :watchers_count, :integer, :default => 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
class CreateVersionReleases < ActiveRecord::Migration[5.2]
|
class CreateVersionReleases < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# create_table :version_releases do |t|
|
create_table :version_releases do |t|
|
||||||
# t.integer :user_id
|
t.integer :user_id
|
||||||
# t.string :name
|
t.string :name
|
||||||
# t.text :body
|
t.text :body
|
||||||
# t.string :tag_name
|
t.string :tag_name
|
||||||
# t.string :target_commitish
|
t.string :target_commitish
|
||||||
# t.boolean :draft, default: false
|
t.boolean :draft, default: false
|
||||||
# t.boolean :prerelease, default: false
|
t.boolean :prerelease, default: false
|
||||||
# t.string :tarball_url
|
t.string :tarball_url
|
||||||
# t.string :zipball_url
|
t.string :zipball_url
|
||||||
# t.string :url
|
t.string :url
|
||||||
# t.string :version_gid
|
t.string :version_gid
|
||||||
# t.timestamps
|
t.timestamps
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddProjectIdToVersionRelease < ActiveRecord::Migration[5.2]
|
class AddProjectIdToVersionRelease < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :version_releases, :repository_id, :integer
|
add_column :version_releases, :repository_id, :integer
|
||||||
# add_index :version_releases, [:repository_id]
|
add_index :version_releases, [:repository_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddColumnToIssueTags < ActiveRecord::Migration[5.2]
|
class AddColumnToIssueTags < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :issue_tags, :gid, :integer
|
add_column :issue_tags, :gid, :integer
|
||||||
# add_column :issue_tags, :gitea_url, :string
|
add_column :issue_tags, :gitea_url, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
class AddColumnToPullRequests < ActiveRecord::Migration[5.2]
|
class AddColumnToPullRequests < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :pull_requests, :version_id, :integer
|
add_column :pull_requests, :version_id, :integer
|
||||||
# add_column :pull_requests, :body, :text
|
add_column :pull_requests, :body, :text
|
||||||
# add_column :pull_requests, :from_ref, :string
|
add_column :pull_requests, :from_ref, :string
|
||||||
# add_column :pull_requests, :to_ref, :string
|
add_column :pull_requests, :to_ref, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ class ChangePullRequestsColumns < ActiveRecord::Migration[5.2]
|
||||||
# add_column :pull_request_assigns, :user_login, :string
|
# add_column :pull_request_assigns, :user_login, :string
|
||||||
#
|
#
|
||||||
# add_index :pull_request_assigns, [:user_login]
|
# add_index :pull_request_assigns, [:user_login]
|
||||||
#
|
|
||||||
# rename_column :pull_requests, :version_id, :milestone
|
rename_column :pull_requests, :version_id, :milestone
|
||||||
# rename_column :pull_requests, :from_ref, :head
|
rename_column :pull_requests, :from_ref, :head
|
||||||
# rename_column :pull_requests, :to_ref, :base
|
rename_column :pull_requests, :to_ref, :base
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddColumnsToPullRequests < ActiveRecord::Migration[5.2]
|
class AddColumnsToPullRequests < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :pull_requests, :issue_id, :integer
|
add_column :pull_requests, :issue_id, :integer
|
||||||
# add_column :issues, :issue_classify, :string
|
add_column :issues, :issue_classify, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddIssuesRefNameAndBranchName < ActiveRecord::Migration[5.2]
|
class AddIssuesRefNameAndBranchName < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :issues, :ref_name, :string
|
add_column :issues, :ref_name, :string
|
||||||
# add_column :issues, :branch_name, :string
|
add_column :issues, :branch_name, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
class MigrateTidingStatus < ActiveRecord::Migration[5.2]
|
class MigrateTidingStatus < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
# Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
||||||
unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
# unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
||||||
tiding.update!(status: 1)
|
# tiding.update!(status: 1)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2]
|
class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :projects, :issues_count, :integer, :default => 0
|
add_column :projects, :issues_count, :integer, :default => 0
|
||||||
# add_column :projects, :pull_requests_count, :integer, :default => 0
|
add_column :projects, :pull_requests_count, :integer, :default => 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
class MigrateUserLocation < ActiveRecord::Migration[5.2]
|
class MigrateUserLocation < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
UserExtension.where("location like '%省'").each do |ue|
|
# UserExtension.where("location like '%省'").each do |ue|
|
||||||
ue.update_column("location", ue.location.chop)
|
# ue.update_column("location", ue.location.chop)
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
UserExtension.where("location_city like '%市'").each do |ue|
|
# UserExtension.where("location_city like '%市'").each do |ue|
|
||||||
ue.update_column("location_city", ue.location_city.chop)
|
# ue.update_column("location_city", ue.location_city.chop)
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class AddIssuesCountToVersions < ActiveRecord::Migration[5.2]
|
class AddIssuesCountToVersions < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
# add_column :versions, :issues_count, :integer, :default => 0
|
add_column :versions, :issues_count, :integer, :default => 0
|
||||||
# add_column :versions, :closed_issues_count, :integer, :default => 0
|
add_column :versions, :closed_issues_count, :integer, :default => 0
|
||||||
# add_column :versions, :percent, :float, default: 0.0
|
add_column :versions, :percent, :float, default: 0.0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,69 +1,69 @@
|
||||||
class ChangeQuillToMd < ActiveRecord::Migration[5.2]
|
class ChangeQuillToMd < ActiveRecord::Migration[5.2]
|
||||||
#迁移quill编辑器的内容为md
|
#迁移quill编辑器的内容为md
|
||||||
def change
|
def change
|
||||||
migrate_time = Time.current - 20.days
|
migrate_time = Time.current - 20.days
|
||||||
|
|
||||||
all_issues = Issue.where("updated_on > ?", migrate_time)
|
all_issues = Issue.where("updated_on > ?", migrate_time)
|
||||||
pros = PullRequest.where("updated_at > ?", migrate_time)
|
pros = PullRequest.where("updated_at > ?", migrate_time)
|
||||||
journals = Journal.where("created_on > ?", migrate_time)
|
journals = Journal.where("created_on > ?", migrate_time)
|
||||||
|
|
||||||
|
|
||||||
Issue.transaction do
|
# Issue.transaction do
|
||||||
if all_issues.size > 0
|
# if all_issues.size > 0
|
||||||
all_issues.each do |i|
|
# all_issues.each do |i|
|
||||||
description = i.description
|
# description = i.description
|
||||||
if description.present? && description.include?("insert")
|
# if description.present? && description.include?("insert")
|
||||||
new_content = change_content(description)
|
# new_content = change_content(description)
|
||||||
i.update_attribute(:description, new_content)
|
# i.update_attribute(:description, new_content)
|
||||||
end
|
# end
|
||||||
puts "__update_issue_content_____id:#{i.id}__"
|
# puts "__update_issue_content_____id:#{i.id}__"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
Journal.transaction do
|
# Journal.transaction do
|
||||||
if journals.size > 0
|
# if journals.size > 0
|
||||||
journals.each do |j|
|
# journals.each do |j|
|
||||||
description = j.notes
|
# description = j.notes
|
||||||
if description.present? && description.include?("insert")
|
# if description.present? && description.include?("insert")
|
||||||
new_content = change_content(description)
|
# new_content = change_content(description)
|
||||||
j.update_attribute(:notes, new_content)
|
# j.update_attribute(:notes, new_content)
|
||||||
end
|
# end
|
||||||
puts "__update_journal_content_____id:#{j.id}__"
|
# puts "__update_journal_content_____id:#{j.id}__"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
end
|
# end
|
||||||
|
|
||||||
PullRequest.transaction do
|
# PullRequest.transaction do
|
||||||
if pros.size > 0
|
# if pros.size > 0
|
||||||
pros.each do |p|
|
# pros.each do |p|
|
||||||
description = p.body
|
# description = p.body
|
||||||
if description.present? && description.include?("insert")
|
# if description.present? && description.include?("insert")
|
||||||
new_content = change_content(description)
|
# new_content = change_content(description)
|
||||||
p.update_attribute(:body, new_content)
|
# p.update_attribute(:body, new_content)
|
||||||
end
|
# end
|
||||||
puts "__update_pull_request_content_____id:#{p.id}__"
|
# puts "__update_pull_request_content_____id:#{p.id}__"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_content(content)
|
# def change_content(content)
|
||||||
puts "####________content_____######{content}"
|
# puts "####________content_____######{content}"
|
||||||
new_content = ""
|
# new_content = ""
|
||||||
return "" if content.blank?
|
# return "" if content.blank?
|
||||||
desc = JSON.parse(content)["ops"]
|
# desc = JSON.parse(content)["ops"]
|
||||||
if desc.length > 0
|
# if desc.length > 0
|
||||||
desc.each do |d|
|
# desc.each do |d|
|
||||||
image = d["insert"]["image"]
|
# image = d["insert"]["image"]
|
||||||
if image.present?
|
# if image.present?
|
||||||
new_content += "![#{image['alt']}](#{image['url']})"
|
# new_content += "![#{image['alt']}](#{image['url']})"
|
||||||
else
|
# else
|
||||||
new_content += d["insert"].gsub("\n", "")
|
# new_content += d["insert"].gsub("\n", "")
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
new_content
|
# new_content
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddColumnsToProjects < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :projects, :license_id, :integer
|
||||||
|
add_column :projects, :ignore_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -15,15 +15,27 @@ namespace :sync_data_to_gitea do
|
||||||
next unless regx.match user.mail
|
next unless regx.match user.mail
|
||||||
|
|
||||||
tmp_password = set_password
|
tmp_password = set_password
|
||||||
user_params = {
|
|
||||||
username: user.login,
|
|
||||||
email: user.mail,
|
|
||||||
password: tmp_password
|
|
||||||
}
|
|
||||||
|
|
||||||
gitea_user = Gitea::User::RegisterService.new(user_params).call
|
# TODO: Educoder sync
|
||||||
result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call
|
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: tmp_password})
|
||||||
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id'])
|
if interactor.success?
|
||||||
|
gitea_user = interactor.result
|
||||||
|
result = Gitea::User::GenerateTokenService.call(user.login, tmp_password)
|
||||||
|
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user[:body]['id'])
|
||||||
|
else
|
||||||
|
puts "#################【Gitea: 用户同步失败: #{interactor.error} #################"
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Trustie sync
|
||||||
|
# user_params = {
|
||||||
|
# username: user.login,
|
||||||
|
# email: user.mail,
|
||||||
|
# password: tmp_password
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# gitea_user = Gitea::User::RegisterService.new(user_params).call
|
||||||
|
# result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call
|
||||||
|
# user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id'])
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.error e
|
Rails.logger.error e
|
||||||
next
|
next
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue