Class: Faalis::API::V1::GroupsController
Instance Method Summary
collapse
allow_query_on, #allowed_fields, #authenticate_filter, #load_resource_by_query, #set_csrf_cookie_for_ng
#set_locale
Instance Method Details
#create ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 14
def create
authorize Faalis::Group, :create?
permissions = [];
(params[:permissions] || []).each do |perm_string|
perm, model = perm_string.split "|"
permission = Faalis::Permission.find_or_create_by_model_and_permission_type(model, perm)
permissions << permission
end
@group = Faalis::Group.new({ name: params[:name],
permissions: permissions })
if @group.save
respond_with(@group)
else
respond_to do |format|
format.json { render json: { fields: @group.errors },
status: :unprocessable_entity }
end
end
end
|
#destroy ⇒ Object
65
66
67
68
69
70
|
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 65
def destroy
ids = params[:id].split(",")
@groups = Faalis::Group.where(:id => ids)
authorize @groups
@groups.destroy_all
end
|
#index ⇒ Object
8
9
10
11
12
|
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 8
def index
@groups = Faalis::Group.includes(:permissions).all
authorize @groups
respond_with(@groups)
end
|
#show ⇒ Object
37
38
39
40
41
|
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 37
def show
@group = Faalis::Group.find(params[:id])
authorize @group
respond_with(@group)
end
|
#update ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 43
def update
@group = Faalis::Group.find(params[:id])
authorize @group
permissions = [];
(params[:permissions] || []).each do |perm_string|
perm, model = perm_string.split '|'
permission = Faalis::Permission.find_or_create_by_model_and_permission_type(model, perm)
permissions << permission
end
if @group.update(:name => params[:name],
:permissions => permissions)
respond_with(@group)
else
respond_to do |format|
format.json { render json: { fields: @group.errors },
status: :unprocessable_entity }
end
end
end
|