Module: GroupMixins::Corporations::ClassMethods
- Defined in:
- app/models/group_mixins/corporations.rb
Overview
Corporations
The parent group for all corporation groups is called ‘corporations_parent`. The group structure looks something like this:
everyone
|----- corporations_parent
|---------- corporation_a
| |--- ...
|---------- corporation_b
| |--- ...
|---------- corporation_c
|--- ...
Instance Method Summary collapse
-
#corporations ⇒ Object
Find all corporation groups, i.e.
-
#corporations_of(user) ⇒ Object
Find corporation groups of a certain user.
- #corporations_parent ⇒ Object
- #corporations_parent! ⇒ Object
- #create_corporations_parent_group ⇒ Object
-
#find_corporation_groups ⇒ Object
Find all corporation groups, i.e.
-
#find_corporation_groups_of(user) ⇒ Object
Find corporation groups of a certain user.
-
#find_corporations_branch_groups ⇒ Object
Find all groups of the corporations branch, i.e.
-
#find_corporations_branch_groups_of(user) ⇒ Object
Find all groups of the corporations branch of a certain user, i.e.
- #find_corporations_parent_group ⇒ Object
-
#find_non_corporations_branch_groups_of(user) ⇒ Object
Find all groups of a certain user that are not part of the user’s corporations_branch, see ‘self.find_corporations_branch_groups_of`.
- #find_or_create_corporations_parent_group ⇒ Object
Instance Method Details
#corporations ⇒ Object
Find all corporation groups, i.e. the children of ‘corporations_parent`. Alias method for `find_corporation_groups`.
71 72 73 |
# File 'app/models/group_mixins/corporations.rb', line 71 def corporations find_corporation_groups end |
#corporations_of(user) ⇒ Object
Find corporation groups of a certain user. Alias method of ‘find_corporation_groups_of`.
86 87 88 |
# File 'app/models/group_mixins/corporations.rb', line 86 def corporations_of( user ) self.find_corporation_groups_of user end |
#corporations_parent ⇒ Object
48 49 50 |
# File 'app/models/group_mixins/corporations.rb', line 48 def corporations_parent find_or_create_corporations_parent_group end |
#corporations_parent! ⇒ Object
52 53 54 |
# File 'app/models/group_mixins/corporations.rb', line 52 def corporations_parent! find_corporations_parent_group || raise('special group :corporations_parent does not exist.') end |
#create_corporations_parent_group ⇒ Object
38 39 40 41 42 |
# File 'app/models/group_mixins/corporations.rb', line 38 def create_corporations_parent_group g = create_special_group(:corporations_parent) g.add_flag :group_of_groups return g end |
#find_corporation_groups ⇒ Object
Find all corporation groups, i.e. the children of ‘corporations_parent`.
FIXME: This method does not filter out the officers_parent child_group. For some reason this would cause several specs to fail.
For the moment, if you want just the corporations, i.e. without the officers_parent, please use ‘Corporation.all`.
64 65 66 |
# File 'app/models/group_mixins/corporations.rb', line 64 def find_corporation_groups find_corporations_parent_group.try(:child_groups) || [] end |
#find_corporation_groups_of(user) ⇒ Object
Find corporation groups of a certain user.
77 78 79 80 81 |
# File 'app/models/group_mixins/corporations.rb', line 77 def find_corporation_groups_of( user ) ancestor_groups_of_user = user.groups corporation_groups = Group.find_corporation_groups if Group.find_corporations_parent_group return ancestor_groups_of_user & corporation_groups if ancestor_groups_of_user and corporation_groups end |
#find_corporations_branch_groups ⇒ Object
Find all groups of the corporations branch, i.e. the corporations_parent and its descendant groups.
everyone
|----- corporations_parent <
| |---------- corporation_a < These groups are returned
| | |--- ... < by this method.
| |---------- corporation_b <
| |--- ... <
|----- other_group_1
|----- other_group_2
102 103 104 105 106 |
# File 'app/models/group_mixins/corporations.rb', line 102 def find_corporations_branch_groups if Group.find_corporations_parent_group return [ Group.corporations_parent ] + Group.corporations_parent.descendant_groups end end |
#find_corporations_branch_groups_of(user) ⇒ Object
Find all groups of the corporations branch of a certain user, i.e. all corporations of a user and the descendant groups of these corporations.
This is used, for example, in the my-groups view, where the corporations groups are displayed separately.
114 115 116 117 118 |
# File 'app/models/group_mixins/corporations.rb', line 114 def find_corporations_branch_groups_of( user ) ancestor_groups = user.groups corporations_branch = self.find_corporations_branch_groups return ancestor_groups & corporations_branch if ancestor_groups and corporations_branch end |
#find_corporations_parent_group ⇒ Object
34 35 36 |
# File 'app/models/group_mixins/corporations.rb', line 34 def find_corporations_parent_group find_special_group(:corporations_parent) end |
#find_non_corporations_branch_groups_of(user) ⇒ Object
Find all groups of a certain user that are not part of the user’s corporations_branch, see ‘self.find_corporations_branch_groups_of`.
This is used, for example, in the my-groups view, where the corporations groups are displayed separately.
Some special groups are excluded manually, since they are not expected to show up in the groups list, e.g. attendee groups of corporation events.
129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/group_mixins/corporations.rb', line 129 def find_non_corporations_branch_groups_of( user ) ancestor_groups = user.groups corporations_branch = self.find_corporations_branch_groups corporations_branch = [] unless corporations_branch return ancestor_groups - corporations_branch - Group.find_all_by_flag(:attendees) - Group.find_all_by_flag(:contact_people) - Group.find_all_by_flag(:officers_parent) end |
#find_or_create_corporations_parent_group ⇒ Object
44 45 46 |
# File 'app/models/group_mixins/corporations.rb', line 44 def find_or_create_corporations_parent_group find_corporations_parent_group || create_corporations_parent_group end |