modify users controller code

dev_course
p31729568 6 years ago
parent eb7655d051
commit 32e2872bbd

@ -9,10 +9,6 @@ class UsersController < ApplicationController
@user = User.find params[:id]
@user.update!(user_params)
render_ok
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
# 贴吧获取用户信接口
@ -69,21 +65,24 @@ class UsersController < ApplicationController
# 用户回复功能
def reply_message
@message = JournalsForMessage.new(reply_message_params)
@message.user_id = current_user.id
@message.save!
#normal_status("回复成功")
message = JournalsForMessage.new(reply_message_params)
message.user_id = current_user.id
message.save!
render_ok(id: message.id)
end
# 搜索用户具有管理员角色的项目
def search_user_projects
condition = '%%'
condition = "%#{params[:search].strip}%".gsub(" ","") if !params[:search].blank?
projects = Project.where.not(status: 9)
projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 })
projects = projects.where(members: { user_id: current_user.id })
search = params[:search].to_s.strip
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id
AND m.id=mr.member_id AND mr.role_id = 3 AND m.user_id=#{current_user.id} AND p.status != 9 and
p.name like '#{condition}'")
@projects = Project.where(id: project_ids.pluck(:id))
@projects = projects.select(:id, :name)
end
# 个人主页信息

Loading…
Cancel
Save