Class: Admin::UsersController
- Inherits:
 - 
      ApplicationController
      
        
- Object
 - ApplicationController
 - Admin::UsersController
 
 
- Defined in:
 - app/controllers/admin/users_controller.rb
 
Overview
rubocop:todo Metrics/ClassLength
Instance Method Summary collapse
- #edit ⇒ Object
 - #filter ⇒ Object
 - 
  
    
      #grant_user_role  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
 - #index ⇒ Object
 - 
  
    
      #remove_user_role  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
 - #show ⇒ Object
 - #switch ⇒ Object
 - 
  
    
      #update  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
 
Instance Method Details
#edit ⇒ Object
      17 18 19 20 21 22 23 24 25 26 27 28 29  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 17 def edit @user = User.find(params[:id]) @page_name = "#{action_name}: #{@user.name}" @all_roles = Role.keys @users_roles = @user.study_and_project_roles.order(name: :asc) @studies = Study.order(:id) @projects = Project.order(:id) respond_to do |format| format.js format.html end end  | 
  
#filter ⇒ Object
      103 104 105 106 107 108 109 110 111 112 113  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 103 def filter if params[:q] @users = User.order(:login).where( 'first_name LIKE :query OR last_name LIKE :query OR login LIKE :query', query: "%#{params[:q].downcase}%" ) end render partial: 'users', locals: { users: @users } end  | 
  
#grant_user_role ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
      51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 51 def grant_user_role # rubocop:todo Metrics/AbcSize, Metrics/MethodLength if request.xhr? if params[:role] = if params[:role][:authorizable_type] == 'Project' Project.find(params[:role][:authorizable_id]) else Study.find(params[:role][:authorizable_id]) end @user.grant_role(params[:role][:authorizable_name].to_s, ) @users_roles = @user.study_and_project_roles.order(name: :asc) flash[:notice] = 'Role added' render partial: 'roles', status: 200 else @users_roles = @user.study_and_project_roles.order(name: :asc) flash[:error] = 'A problem occurred while adding the role' render partial: 'roles', status: 500 end else @users_roles = @user.study_and_project_roles.sort_by(&:name) flash[:error] = 'A problem occurred while adding the role' render partial: 'roles', status: 401 end end  | 
  
#index ⇒ Object
      9 10 11  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 9 def index @users = User.order(:login) end  | 
  
#remove_user_role ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
      77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 77 def remove_user_role # rubocop:todo Metrics/AbcSize, Metrics/MethodLength if request.xhr? if params[:role] = if params[:role][:authorizable_type] == 'project' Project.find(params[:role][:authorizable_id]) else Study.find(params[:role][:authorizable_id]) end @user.remove_role(params[:role][:authorizable_name].to_s, ) @users_roles = @user.study_and_project_roles.order(name: :asc) flash[:error] = 'Role was removed' render partial: 'roles', status: 200 else @users_roles = @user.study_and_project_roles.order(name: :asc) flash[:error] = 'A problem occurred while removing the role' render partial: 'roles', status: 500 end else @users_roles = @user.study_and_project_roles.order(name: :asc) flash[:error] = 'A problem occurred while removing the role' render partial: 'roles', status: 401 end end  | 
  
#show ⇒ Object
      13 14 15  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 13 def show @page_name = @user.name end  | 
  
#switch ⇒ Object
      31 32 33 34  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 31 def switch session[:user] = params[:id] redirect_to studies_url end  | 
  
#update ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
      36 37 38 39 40 41 42 43 44 45 46 47 48 49  | 
    
      # File 'app/controllers/admin/users_controller.rb', line 36 def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength @user = User.find(params[:id]) Role.general_roles.each do |role| params[:role] && params[:role][role.name] ? @user.grant_role(role.name) : @user.remove_role(role.name) end @user.update(params[:user]) if @user.id == params[:id].to_i if @user.save flash[:notice] = 'Profile updated' else flash[:error] = 'Problem updating profile' end redirect_to profile_path(@user) end  |