Sha256: b511da7c1cc9aa61b0cee1b16e8df27b71cb0c5885b0d5b7231039117ea543dd
Contents?: true
Size: 1.28 KB
Versions: 13
Compression:
Stored size: 1.28 KB
Contents
module GroupedPage def self.included(base) base.class_eval { has_groups has_one :homegroup, :foreign_key => 'homepage_id', :class_name => 'Group' include InstanceMethods alias_method_chain :permitted_group_ids, :inheritance } end module InstanceMethods attr_reader :inherited_groups def inherited_groups @inherited_groups ||= self.parent ? Group.attached_to(self.ancestors) : [] end # If a grandparent page is associated with a supergroup page # then all of the descendant pages are bound to all of the descendant groups. def inherited_group_ids self.ancestors.map(&:group_ids).flatten.uniq end def permitted_group_ids_with_inheritance (permitted_group_ids_without_inheritance + inherited_group_ids).flatten.uniq end def restricted? self.permitted_groups.any? end # this is regrettably expensive and I plan to replace it with a # private? method that would be cascaded on page update # def cache? !restricted? end def has_inherited_group?(group) return self.inherited_groups.include?(group) end def group_is_inherited?(group) return self.has_inherited_group?(group) && !self.has_group?(group) end end end
Version data entries
13 entries across 13 versions & 1 rubygems