Class: Authengine::UserRolesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/authengine/user_roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/authengine/user_roles_controller.rb', line 8

def create
  @user = User.find(params[:user_id])
  # session_user_roles are created by the process of downgrading the role
  # associated with the current session for the purpose of limiting access
  # when configuring a session for just one purpose (e.g.) checkout
  if params[:session_user_role]
    @user.session_user_roles.create(params[:session_user_role].delete_if{|k,v| k == "type" })
    role_name = Role.find(params[:session_user_role][:role_id]).name
    flash[:info] = "Current session now has #{role_name} role"
    redirect_to home_path
  else
    @user.user_roles.create(params[:user_role])
    redirect_to authengine_user_user_roles_path(@user)
  end
end

#destroyObject



24
25
26
27
28
# File 'app/controllers/authengine/user_roles_controller.rb', line 24

def destroy
  user_role = UserRole.find_by_role_id_and_user_id(params[:id],params[:user_id])
  user_role.destroy
  redirect_to authengine_user_user_roles_path(params[:user_id])
end

#editObject



36
37
38
39
40
# File 'app/controllers/authengine/user_roles_controller.rb', line 36

def edit
  @user = User.find(params[:user_id])
  @user_role = UserRole.new(:user_id => @user.id)
  @roles = Role.lower_than(current_user.user_roles.map(&:role))
end

#indexObject



2
3
4
5
6
# File 'app/controllers/authengine/user_roles_controller.rb', line 2

def index
  @user = User.find(params[:user_id])
  @all_roles = Role.all(:order => :name)
  @user_role = UserRole.new(:user_id => @user.id)
end

#newObject



30
31
32
33
34
# File 'app/controllers/authengine/user_roles_controller.rb', line 30

def new
  @user = User.find(params[:user_id])
  @user_role = UserRole.new(:user_id => @user.id)
  @roles = Role.lower_than(current_user.user_roles.map(&:role))
end

#updateObject

session role is being downgraded for the logged-in user



43
44
45
46
47
# File 'app/controllers/authengine/user_roles_controller.rb', line 43

def update
  update_session_role(params[:user_role][:role_id])
  flash[:notice] = "Current session now has #{Role.find(params[:user_role][:role_id]).name} role"
  redirect_to new_authengine_session_path
end