Class: Cms::Group

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
DefaultAccessible
Defined in:
app/models/cms/group.rb

Overview

A group represents a collection of permissions. Each User can be assigned to one or more groups, and the sum of their permissions from all groups combined represents what they can do.

Constant Summary collapse

GUEST_CODE =
"guest"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefaultAccessible

non_permitted_params, permitted_params

Class Method Details

.guestObject

Finds the guest group, which is a special group that represents public non-logged in users.



52
53
54
# File 'app/models/cms/group.rb', line 52

def self.guest
  guest_groups.first
end

.guest_groupsObject



56
57
58
# File 'app/models/cms/group.rb', line 56

def self.guest_groups
  with_code(GUEST_CODE)
end

.named(n) ⇒ Object



30
31
32
# File 'app/models/cms/group.rb', line 30

def named(n)
  where name: n
end

.permitted_paramsObject



22
23
24
# File 'app/models/cms/group.rb', line 22

def self.permitted_params
  super + [:group_type_id] +[section_ids: [], permission_ids: []]
end

.with_code(c) ⇒ Object



34
35
36
# File 'app/models/cms/group.rb', line 34

def with_code(c)
  where code: c
end

Instance Method Details

#cms_access?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/cms/group.rb', line 47

def cms_access?
  group_type && group_type.cms_access?
end

#guest?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/cms/group.rb', line 43

def guest?
  group_type && group_type.guest?
end

#has_permission?(permission) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
# File 'app/models/cms/group.rb', line 60

def has_permission?(permission)
  permissions.any? do |p|
    return true if permission.to_sym == p.name.to_sym
  end
  false
end