Class: Alberich::RolesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/alberich/roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /roles POST /roles.json



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/alberich/roles_controller.rb', line 52

def create
  require_privilege(Privilege::PERM_SET)
  @role = Role.new(params[:role])
  
  respond_to do |format|
    if @role.save
      format.html { redirect_to @role, notice: "New role added"}
      format.json { render json: @role, status: :created, location: @role }
    else
      format.html { render action: "new" }
      format.json { render json: @role.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /roles/1 DELETE /roles/1.json



86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/alberich/roles_controller.rb', line 86

def destroy
  require_privilege(Privilege::PERM_SET)
  @role = Role.find(params[:id])
  @role.destroy
  
  respond_to do |format|
    format.html { redirect_to roles_url }
    format.json { head :no_content }
  end
end

#editObject

GET /roles/1/edit



44
45
46
47
48
# File 'app/controllers/alberich/roles_controller.rb', line 44

def edit
  require_privilege(Privilege::PERM_SET)
  @role = Role.find(params[:id])
  @scope_list = Role::VALID_SCOPES
end

#indexObject

GET /roles GET /roles.json



9
10
11
12
13
14
15
16
17
# File 'app/controllers/alberich/roles_controller.rb', line 9

def index
  require_privilege(Privilege::PERM_VIEW)
  @roles = Role.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @roles }
  end
end

#newObject

GET /roles/new GET /roles/new.json



33
34
35
36
37
38
39
40
41
# File 'app/controllers/alberich/roles_controller.rb', line 33

def new
  require_privilege(Privilege::PERM_SET)
  @role = Role.new
  @scope_list = Role::VALID_SCOPES
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @role }
  end
end

#showObject

GET /roles/1 GET /roles/1.json



21
22
23
24
25
26
27
28
29
# File 'app/controllers/alberich/roles_controller.rb', line 21

def show
  require_privilege(Privilege::PERM_VIEW)
  @role = Role.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @role }
  end
end

#updateObject

PUT /roles/1 PUT /roles/1.json



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/alberich/roles_controller.rb', line 69

def update
  require_privilege(Privilege::PERM_SET)
  @role = Role.find(params[:id])
  
  respond_to do |format|
    if @role.update_attributes(params[:role])
      format.html { redirect_to @role, notice: "Role updated successfully"}
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @role.errors, status: :unprocessable_entity }
    end
  end
end