Class: API::V1::GroupsController

Inherits:
APIController
  • Object
show all
Defined in:
app/controllers/red_base/api/v1/groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/red_base/api/v1/groups_controller.rb', line 15

def create
  authorize! :create, RedBase::Group

  permissions = [];

  (params[:permissions] || []).each do |perm_string|
    perm, model = perm_string.split "|"
    permission = Permission.find_or_create_by_model_and_permission_type(model, perm)
    permissions << permission
  end

  @group = Group.create!({
                           name: params[:name],
                           permissions: permissions,
                         })
  respond_with(@group)

end

#destroyObject



57
58
59
60
61
62
# File 'app/controllers/red_base/api/v1/groups_controller.rb', line 57

def destroy
  ids = params[:id].split(",")
  @groups = Group.where(:id => ids)
  authorize! :destory, @groups
  @groups.destroy_all
end

#indexObject

GET /api/v1/groups



9
10
11
12
13
# File 'app/controllers/red_base/api/v1/groups_controller.rb', line 9

def index
  @groups = Group.includes(:permissions).all
  authorize! :read, @groups
  respond_with(@groups)
end

#showObject



34
35
36
37
38
# File 'app/controllers/red_base/api/v1/groups_controller.rb', line 34

def show
  @group = Group.find(params[:id])
  authorize! :read, @group
  respond_with(@group)
end

#updateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/red_base/api/v1/groups_controller.rb', line 40

def update

  @group = Group.find(params[:id])
  authorize! :update, @group

  permissions = [];
  (params[:permissions] || []).each do |perm_string|
    perm, model = perm_string.split "|"
    permission = Permission.find_or_create_by_model_and_permission_type(model, perm)
    permissions << permission
  end

  @group.update(:name => params[:name],
                :permissions => permissions)
  respond_with(@group)
end