Module: GroupMixins::Roles

Extended by:
ActiveSupport::Concern
Included in:
Group
Defined in:
app/models/group_mixins/roles.rb

Overview

This mixin adds methods to special groups that are related to the role model.

Instance Method Summary collapse

Instance Method Details

#administrated_objectObject

Officers somehow administrate structureable objects, e.g. groups or pages. They may be admins, main_admins, editors or another kind of officer.

This method returns the object that is administrated by the officers that are in this group (self) if this is an officer group.

some_group
    |------- another_group   <---------------------------- this group is returned
                   |-------- officers
                                 |---- admins
                                          |--- main_admins

main_admins.administrated_object == another_group
admins.administrated_object == another_group
officers.administrated_object == another_group
another_group.administrated_object == nil
some_group.administrated_object == nil


29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/group_mixins/roles.rb', line 29

def administrated_object
  if self.ancestor_groups.find_all_by_flag( :officers_parent ).count == 0 and
      not self.has_flag? :officers_parent
    return nil
  end
  object = self
  until object.has_flag? :officers_parent
    object = object.parents.first
  end
  object = object.parents.first
end