Module: GroupedModel::GroupedInstanceMethods

Defined in:
lib/grouped_model.rb

Instance Method Summary collapse

Instance Method Details

#groupObject



105
106
107
108
109
110
111
# File 'lib/grouped_model.rb', line 105

def group
  if self.permitted_groups.length == 1
    self.permitted_groups.first
  else
    nil
  end
end

#group_ids=(ids) ⇒ Object



129
130
131
# File 'lib/grouped_model.rb', line 129

def group_ids=(ids)
  self.groups = Group.from_list(ids)
end

#has_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/grouped_model.rb', line 121

def has_group?(group)
  return self.permitted_groups.include?(group)
end

#permit(group) ⇒ Object



125
126
127
# File 'lib/grouped_model.rb', line 125

def permit(group)
  self.groups << group unless self.has_group?(group)
end

#permitted_groupsObject

in GroupedPage this is chained to include inherited groups



93
94
95
# File 'lib/grouped_model.rb', line 93

def permitted_groups
  groups
end

#permitted_readersObject



117
118
119
# File 'lib/grouped_model.rb', line 117

def permitted_readers
  permitted_groups.any? ? Reader.in_groups(permitted_groups) : Reader.all
end

#visible?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/grouped_model.rb', line 113

def visible?
  permitted_groups.empty?
end

#visible_to_with_groups?(reader) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
# File 'lib/grouped_model.rb', line 97

def visible_to_with_groups?(reader)
  return false unless visible_to_without_groups?(reader)
  return true if self.permitted_groups.empty?
  return false if reader.nil?
  return true if reader.is_admin?
  return (reader.groups & self.permitted_groups).any?
end