Class: UcbRails::Admin::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/ucb_rails/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 15

def create
  uid = params.fetch(:uid)
  if user = UcbRails::User.find_by_uid(uid)
    flash[:warning] = "User already exists"
  else
    user = UcbRails::UserLdapService.create_user_from_uid(uid)
    flash[:notice] = 'Record created'#msg_created(user)
  end
  # render :js => %(window.location.href = '#{ucb_rails_admin_user_path}')
  render :js => %(window.location.href = '#{edit_ucb_rails_admin_user_path(user)}')
end

#destroyObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 35

def destroy
  if @user.destroy
    flash[:notice] = 'Record deleted' #msg_destroyed(@user)
  else
    flash[:error] = @user.errors[:base].first
  end

  redirect_to(ucb_rails_admin_users_path)
end

#editObject



12
13
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 12

def edit
end

#indexObject



5
6
7
8
9
10
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 5

def index
  respond_to do |format|
    format.html { @users = UcbRails::User.all }
    format.json { render json: UcbRails::UsersDatatable.new(view_context) }
  end
end

#ldap_searchObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 45

def ldap_search
  @lps_entries = UcbRails::LdapPerson::Finder.find_by_first_last(
    params.fetch(:first_name),
    params.fetch(:last_name), 
    :sort => :last_first_downcase
  )
  @lps_existing_uids = UcbRails::User.where(uid: @lps_entries.map(&:uid)).pluck(:uid)

  render 'ucb_rails/lps/search'
end

#typeahead_searchObject



56
57
58
59
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 56

def typeahead_search
  uta = UcbRails::UserTypeahead.new
  render json: uta.results(params.fetch(:query))
end

#updateObject



27
28
29
30
31
32
33
# File 'app/controllers/ucb_rails/admin/users_controller.rb', line 27

def update
  if @user.update_attributes(params.fetch(:ucb_rails_user), :without_protection => true)
    redirect_to(ucb_rails_admin_users_path, notice: 'Record updated')
  else
    render("edit")
  end
end