Class: API::V1::PermissionsController

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

Defined Under Namespace

Classes: DummyPerm

Instance Method Summary (collapse)

Instance Method Details

- (Object) index

api GET permissions return All permissions



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/faalis/api/v1/permissions_controller.rb', line 15

def index
  @permissions = {}

  Faalis::Permission.all.each do |perm|
    if @permissions.include? perm.model
      @permissions[perm.model] << perm.action
    else
      @permissions[perm.model] = [perm.action]
    end
  end

  respond_with(@permissions)
end

- (Object) user_permissions

api GET permissions/user return current user permissions



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/faalis/api/v1/permissions_controller.rb', line 31

def user_permissions

  @permissions = {}
  current_user.permissions.each do |perm|
    if @permissions.include? perm.model
      @permissions[perm.model] << perm.action
    else
      @permissions[perm.model] = [perm.action]
    end
  end

  respond_with(@permissions)
  return

  @permissions = {}
  perms = []

  # Generate a suitable Hash for permissions
  perms.each do |perm|
    if @permissions.include? perm.model
      @permissions[perm.model] << perm.permission_type.to_s
      @permissions[perm.model] = @permissions[perm.model].uniq
    else
      @permissions[perm.model] = [perm.permission_type.to_s]
    end
  end
  respond_with(@permissions)
end