Module: UcbRailsUser::Concerns::UsersController
- Extended by:
- ActiveSupport::Concern
- Included in:
- UsersController
- Defined in:
- app/controllers/ucb_rails_user/concerns/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #impersonate_search ⇒ Object
- #index ⇒ Object
- #ldap_search ⇒ Object
- #new ⇒ Object
- #omni_typeahead_search ⇒ Object
- #search ⇒ Object
- #toggle_superuser ⇒ Object
- #typeahead_search ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 40 def create uid = params.fetch(:ldap_uid) user = nil if user = User.find_by_ldap_uid(uid) flash[:warning] = "User already exists" else begin user = UcbRailsUser::UserLdapService.create_user_from_uid(uid) flash[:notice] = "Record created" rescue Exception => e raise e flash[:danger] = "Unable to create new user - please try again" return redirect_to new_admin_user_path() end end redirect_to edit_admin_user_path(user) end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 66 def destroy if @user.destroy flash[:notice] = 'Record deleted' else flash[:error] = @user.errors[:base].first end redirect_to(admin_users_path) end |
#edit ⇒ Object
34 35 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 34 def edit end |
#impersonate_search ⇒ Object
29 30 31 32 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 29 def impersonate_search result = UcbRailsUser::UserSearch.find_users_by_name(params[:q]) render json: result.map { |u| { name: u.full_name, id: u.id } } end |
#index ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 10 def index @users = User.all respond_to do |format| format.html { @users = User.all } format.json { render json: UcbRails::UsersDatatable.new(view_context).as_json } end end |
#ldap_search ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 76 def ldap_search # FIXME: this was retrofitted to support typeahead ajax json queries if(query = params[:query]) @lps_entries = UcbRails::OmniUserTypeahead.new.ldap_results(query) @lps_entries.map!{|entry| attrs = entry.attributes.tap{|attrs| attrs["first_last_name"] = "#{attrs['first_name']} #{attrs['last_name']}" } attrs.as_json } render json: @lps_entries else @lps_entries = UcbRails::LdapPerson::Finder.find_by_first_last( params.fetch(:first_name), params.fetch(:last_name), :sort => :last_first_downcase ) @lps_existing_uids = User.where(ldap_uid: @lps_entries.map(&:uid)).pluck(:uid) render 'lps/search' end end |
#new ⇒ Object
37 38 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 37 def new end |
#omni_typeahead_search ⇒ Object
104 105 106 107 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 104 def omni_typeahead_search uta = UcbRails::OmniUserTypeahead.new render json: uta.results(params.fetch(:query)) end |
#search ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 18 def search @results = UcbRailsUser::LdapPerson::Finder.find_by_attributes( { givenname: params.fetch(:first_name), sn: params.fetch(:last_name), employeenumber: params.fetch(:employee_id) }, sort: :last_first_downcase ) end |
#toggle_superuser ⇒ Object
109 110 111 112 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 109 def toggle_superuser current_user.try(:superuser!, !superuser?) redirect_to root_path end |
#typeahead_search ⇒ Object
99 100 101 102 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 99 def typeahead_search uta = UcbRails::UserTypeahead.new render json: uta.results(params.fetch(:query)) end |
#update ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/controllers/ucb_rails_user/concerns/users_controller.rb', line 58 def update if @user.update_attributes(user_params) redirect_to(admin_users_path, notice: 'Record updated') else render("edit") end end |