用户修改密码、删除项目成员 添加事务处理
This commit is contained in:
parent
7faddc30c5
commit
d304555044
|
@ -392,27 +392,33 @@ class MembersController < ApplicationController
|
||||||
#课程成员删除修改
|
#课程成员删除修改
|
||||||
if @project
|
if @project
|
||||||
if request.delete? && @member.deletable?
|
if request.delete? && @member.deletable?
|
||||||
@member.destroy
|
ActiveRecord::Base.transaction do
|
||||||
# end
|
begin
|
||||||
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
@member.destroy
|
||||||
if user_admin.size > 0
|
# end
|
||||||
user_admin.each do |user|
|
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
||||||
user.destroy
|
if user_admin.size > 0
|
||||||
|
user_admin.each do |user|
|
||||||
|
user.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
||||||
|
if user_grade.size > 0
|
||||||
|
user_grade.each do |grade|
|
||||||
|
grade.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
|
||||||
|
applied_projects = AppliedProject.where(:project_id => @project.id, :user_id => @member.user_id).first
|
||||||
|
unless applied_projects.nil?
|
||||||
|
applied_projects.delete
|
||||||
|
end
|
||||||
|
#移出项目发送消息
|
||||||
|
ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id)
|
||||||
|
rescue Exception => e
|
||||||
|
puts e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
|
||||||
if user_grade.size > 0
|
|
||||||
user_grade.each do |grade|
|
|
||||||
grade.destroy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
|
|
||||||
applied_projects = AppliedProject.where(:project_id => @project.id, :user_id => @member.user_id).first
|
|
||||||
unless applied_projects.nil?
|
|
||||||
applied_projects.delete
|
|
||||||
end
|
|
||||||
#移出项目发送消息
|
|
||||||
ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id)
|
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to_settings_in_projects }
|
format.html { redirect_to_settings_in_projects }
|
||||||
|
|
|
@ -159,8 +159,8 @@ class MyController < ApplicationController
|
||||||
g = Gitlab.client
|
g = Gitlab.client
|
||||||
begin
|
begin
|
||||||
g.edit_user(@user.gid, :email => params[:user][:mail])
|
g.edit_user(@user.gid, :email => params[:user][:mail])
|
||||||
rescue
|
rescue Exception => e
|
||||||
logger.error "sync user's email of gitlab failed!"
|
puts e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -232,25 +232,27 @@ class UsersService
|
||||||
|
|
||||||
#修改密码
|
#修改密码
|
||||||
def change_password params
|
def change_password params
|
||||||
@current_user = User.find(params[:current_user_id])
|
ActiveRecord::Base.transaction do
|
||||||
if @current_user.check_password?(params[:password])
|
@current_user = User.find(params[:current_user_id])
|
||||||
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
if @current_user.check_password?(params[:password])
|
||||||
@current_user.save
|
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||||
# 修改密码同步gitlab密码修改
|
@current_user.save
|
||||||
unless @current_user.gid.nil?
|
# 修改密码同步gitlab密码修改
|
||||||
begin
|
unless @current_user.gid.nil?
|
||||||
g = Gitlab.client
|
begin
|
||||||
g.edit_user(@current_user.gid, :password => params[:new_password])
|
g = Gitlab.client
|
||||||
rescue Exception => e
|
g.edit_user(@current_user.gid, :password => params[:new_password])
|
||||||
logger.error "change users password failed! ===> #{e}"
|
rescue Exception => e
|
||||||
|
logger.error "change users password failed! ===> #{e}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
#raise @current_user.errors.full_message
|
#raise @current_user.errors.full_message
|
||||||
#return @current_user
|
#return @current_user
|
||||||
else
|
else
|
||||||
raise l(:notice_account_wrong_password,:locale => 'zh')
|
raise l(:notice_account_wrong_password,:locale => 'zh')
|
||||||
|
end
|
||||||
|
@current_user
|
||||||
end
|
end
|
||||||
@current_user
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#搜索用户
|
#搜索用户
|
||||||
|
|
Loading…
Reference in New Issue