用户修改密码、删除项目成员 添加事务处理

This commit is contained in:
huang 2016-12-19 17:26:56 +08:00
parent 7faddc30c5
commit d304555044
3 changed files with 44 additions and 36 deletions

View File

@ -392,27 +392,33 @@ class MembersController < ApplicationController
#课程成员删除修改
if @project
if request.delete? && @member.deletable?
@member.destroy
# end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
ActiveRecord::Base.transaction do
begin
@member.destroy
# end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
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
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
respond_to do |format|
format.html { redirect_to_settings_in_projects }

View File

@ -159,8 +159,8 @@ class MyController < ApplicationController
g = Gitlab.client
begin
g.edit_user(@user.gid, :email => params[:user][:mail])
rescue
logger.error "sync user's email of gitlab failed!"
rescue Exception => e
puts e
end
end

View File

@ -232,25 +232,27 @@ class UsersService
#修改密码
def change_password params
@current_user = User.find(params[:current_user_id])
if @current_user.check_password?(params[:password])
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
# 修改密码同步gitlab密码修改
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
ActiveRecord::Base.transaction do
@current_user = User.find(params[:current_user_id])
if @current_user.check_password?(params[:password])
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
# 修改密码同步gitlab密码修改
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
end
end
end
#raise @current_user.errors.full_message
#return @current_user
else
raise l(:notice_account_wrong_password,:locale => 'zh')
else
raise l(:notice_account_wrong_password,:locale => 'zh')
end
@current_user
end
@current_user
end
#搜索用户