forked from Trustie/forgeplus
merge from develop
This commit is contained in:
commit
eac812a7bf
|
|
@ -15,6 +15,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController
|
|||
|
||||
def blame
|
||||
@result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
end
|
||||
|
|
@ -16,9 +16,9 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
|
||||
# 60s内不能重复发送
|
||||
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
||||
tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
||||
tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
begin
|
||||
UserMailer.update_email(mail, verification_code).deliver_now
|
||||
|
||||
|
|
@ -29,6 +29,8 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
tip_exception(-2,"邮件发送失败,请稍后重试")
|
||||
end
|
||||
ver_params = {code_type: code_type, code: verification_code, email: mail}
|
||||
last_code = VerificationCode.where(code_type: code_type, email: mail).last
|
||||
last_code.update_attributes!({created_at: Time.current - 10.minute}) if last_code.present?
|
||||
data = VerificationCode.new(ver_params)
|
||||
if data.save!
|
||||
render_ok
|
||||
|
|
@ -39,17 +41,17 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
|
||||
def check_password
|
||||
password = params[:password]
|
||||
return render_error("8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
|
||||
return render_error("密码错误") unless @observe_user.check_password?(password)
|
||||
return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
|
||||
return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_email
|
||||
mail = strip(params[:email])
|
||||
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
|
||||
exist_owner = Owner.find_by(mail: mail)
|
||||
return render_error('邮箱已被使用') if exist_owner
|
||||
return tip_exception(-2, '邮箱已被使用') if exist_owner
|
||||
render_ok
|
||||
end
|
||||
|
||||
|
|
@ -58,12 +60,13 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
mail = strip(params[:email])
|
||||
code_type = params[:code_type]
|
||||
|
||||
return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
|
||||
verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last
|
||||
return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||
|
||||
return render_error("验证码不正确") if verifi_code&.code != code
|
||||
return render_error("验证码已失效") if !verifi_code&.effective?
|
||||
return tip_exception(-6, "验证码不正确") if verifi_code&.code != code
|
||||
return tip_exception(-6, "验证码已失效") if !verifi_code&.effective?
|
||||
render_ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,30 +17,69 @@ module ProjectOperable
|
|||
owner.build_permit_team_projects!(id)
|
||||
# 避免自己创建的项目,却无法拥有访问权,因为该用户所在团队暂未获得项目访问权
|
||||
return if creator.nil? || owner.is_owner?(creator.id)
|
||||
add_member!(creator.id, "Manager")
|
||||
add_member!(creator.id, "Manager") if creator.is_a?(User)
|
||||
end
|
||||
|
||||
def add_member!(user_id, role_name='Developer', is_apply_signature=false)
|
||||
if self.owner.is_a?(Organization)
|
||||
case role_name
|
||||
when 'Manager'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.admin.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Developer'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.write.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Reporter'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.read.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
end
|
||||
end
|
||||
member = members.create!(user_id: user_id, team_user_id: team_user&.id, is_apply_signature: is_apply_signature)
|
||||
|
|
@ -71,26 +110,70 @@ module ProjectOperable
|
|||
|
||||
def change_member_role!(user_id, role)
|
||||
member = self.member(user_id)
|
||||
# 所有者为组织,并且该用户属于组织成员
|
||||
if self.owner.is_a?(Organization) && member.team_user.present?
|
||||
case role&.name
|
||||
when 'Manager'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.admin.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
team_user = member.team_user.update(team_id: team&.id)
|
||||
when 'Developer'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.write.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
$gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
team_user = member.team_user.update(team_id: team&.id)
|
||||
when 'Reporter'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.read.take
|
||||
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
||||
TeamProject.build(self.user_id, team.id, self.id)
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
team_user = member.team_user.update(team_id: team&.id)
|
||||
end
|
||||
end
|
||||
member.member_roles.last.update_attributes!(role: role)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ class Api::V1::Users::UpdateEmailService < ApplicationService
|
|||
def call
|
||||
raise Error, errors.full_messages.join(",") unless valid?
|
||||
raise Error, "密码不正确." unless @user.check_password?(@password)
|
||||
raise Error, "验证码不正确." if @verify_code&.code != @code
|
||||
raise Error, "验证码已失效." if !@verify_code&.effective?
|
||||
exist_owner = Owner.find_by(mail: @mail)
|
||||
raise Error, "邮箱已被使用." if exist_owner
|
||||
is_debug = @code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||
raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug
|
||||
raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug
|
||||
|
||||
# begin
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
change_user_email
|
||||
excute_data_to_gitea
|
||||
|
|
@ -32,15 +35,15 @@ class Api::V1::Users::UpdateEmailService < ApplicationService
|
|||
|
||||
return gitea_data
|
||||
|
||||
# rescue
|
||||
# raise Error, "服务器错误,请联系系统管理员!"
|
||||
# end
|
||||
rescue
|
||||
raise Error, "服务器错误,请联系系统管理员!"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
{
|
||||
access_token: token
|
||||
access_token: @user.gitea_token
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ class Projects::TransferService < ApplicationService
|
|||
|
||||
private
|
||||
def update_owner
|
||||
# 转移项目需要移除原来的权限
|
||||
project.members.update_all(team_user_id: nil)
|
||||
project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) }
|
||||
project.set_owner_permission(new_owner)
|
||||
project.update!(user_id: new_owner.id)
|
||||
project.set_owner_permission(new_owner)
|
||||
end
|
||||
|
||||
def update_repo_url
|
||||
|
|
@ -49,7 +51,8 @@ class Projects::TransferService < ApplicationService
|
|||
|
||||
def gitea_update_owner
|
||||
begin
|
||||
@gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login)
|
||||
@gitea_repo = $gitea_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json})
|
||||
# @gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login)
|
||||
rescue Exception => e
|
||||
Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@
|
|||
<td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td class="action-container">
|
||||
<% if project.is_public %>
|
||||
<%= javascript_void_link '精选', class: 'action pinned-action', data: { id: project.id }, style: project.is_pinned ? 'display: none;' : '' %>
|
||||
<%= javascript_void_link '取消精选', class: 'action unpinned-action', data: { id: project.id }, style: project.is_pinned ? '' : 'display: none;' %>
|
||||
<%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %>
|
||||
<%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %>
|
||||
<%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action edit-recommend-action", style: project.recommend ? '' : 'display: none;' %>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@ namespace :sync_data_to_gitea do
|
|||
end
|
||||
team.team_users.each do |teamuser|
|
||||
userlogin = teamuser&.user&.login
|
||||
ou = org.organization_users.find_by(user_id: teamuser.user_id)
|
||||
OrganizationUser.build(org.id, teamuser.user_id) unless ou.present?
|
||||
next if ($gitea_client.get_teams_members_by_id_username(team.gtid, userlogin) rescue nil)
|
||||
tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil
|
||||
tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil
|
||||
raise ActiveRecord::Rollback if tu_result.nil?
|
||||
end
|
||||
team.team_projects.each do |teamp|
|
||||
|
|
@ -26,7 +28,7 @@ namespace :sync_data_to_gitea do
|
|||
end
|
||||
end
|
||||
org.organization_users.each do |user|
|
||||
next if ($gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue nil)
|
||||
$gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue next
|
||||
user.destroy!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue