Class: Faalis::Dashboard::GroupsController

Inherits:
Dashboard::ApplicationController
  • Object
show all
Defined in:
app/controllers/faalis/dashboard/groups_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) create



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 22

def create
  authorize Faalis::Group

  name = group_params[:name]
  @group = Faalis::Group.new(name: name, role: name.underscore)

  @group.permissions = populate_permissions

  respond_to do |f|
    if @group.save
      f.js
      f.html
    else
      f.js { render :errors }
      f.html
    end
  end

end

- (Object) edit



17
18
19
20
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 17

def edit
  @group = Faalis::Group.find(params[:id])
  authorize @group
end

- (Object) get_all_permissions (private)



75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 75

def get_all_permissions
  @permissions = {}
  Faalis::Permission.all.each do |perm|
    if @permissions.include? perm.model
      @permissions[perm.model] << [perm.permission_type, perm.id]
    else
      @permissions[perm.model] = [[perm.permission_type, perm.id]]
    end
  end
end

- (Object) group_params (private)



71
72
73
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 71

def group_params
  params.require(:group).permit!
end

- (Object) index



6
7
8
9
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 6

def index
  authorize Faalis::Group
  @groups = Faalis::Group.all
end

- (Object) new



11
12
13
14
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 11

def new
  authorize Faalis::Group
  @group = Faalis::Group.new
end

- (Object) populate_permissions (private)



63
64
65
66
67
68
69
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 63

def populate_permissions
  unless group_params[:permissions].nil?
    # TODO: Fix this for mongoid too.
    ids = group_params[:permissions].keys.map(&:to_i)
    Faalis::Permission.where(id: ids)
  end
end

- (Object) update



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/faalis/dashboard/groups_controller.rb', line 42

def update
  @group = Faalis::Group.find(params[:id])
  authorize @group

  @group.permissions = populate_permissions
  @group.name        = group_params[:name]
  @group.role        = group_params[:name].underscore

  respond_to do |f|
    if @group.save
      f.js
      f.html
    else
      f.js { render :errors }
      f.html
    end
  end
end