ref: master
plugins/sub_organizations/lib/sub_organizations_plugin.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
require_dependency File.dirname(__FILE__) + '/related_organizations_block' class SubOrganizationsPlugin < Noosfero::Plugin; end; require_dependency 'sub_organizations_plugin/search_helper' class SubOrganizationsPlugin < Noosfero::Plugin include SearchHelper DISPLAY_LIMIT = 12 def self.plugin_name _("Sub-groups") end def self.plugin_description _("Adds the ability for groups to have sub-groups.") end def control_panel_buttons if context.profile.organization? && Organization.parentz(context.profile).blank? { title: _('Manage sub-groups'), icon: 'groups', url: {profile: profile.identifier, controller: :sub_organizations_plugin_myprofile} } end end def stylesheet? true end def organization_members(organization) children = Organization.children(organization) Person.members_of(children.all) if children.present? end def person_memberships(person) Organization.parentz(*Profile.memberships_of(person)) end def has_permission?(person, permission, target) if !target.kind_of?(Environment) && target.organization? Organization.parentz(target).map do |parent| person.has_permission_without_plugins?(permission, parent) end.include?(true) end end def new_community_hidden_fields parent_to_be = context.params[:sub_organizations_plugin_parent_to_be] {'sub_organizations_plugin_parent_to_be' => parent_to_be} if parent_to_be.present? end def enterprise_registration_hidden_fields parent_to_be = context.params[:sub_organizations_plugin_parent_to_be] {'sub_organizations_plugin_parent_to_be' => parent_to_be} if parent_to_be.present? end def self.limit(organizations) organizations.limit(DISPLAY_LIMIT).order('updated_at DESC').sort_by{ rand } end def self.extra_blocks { RelatedOrganizationsBlock => {:type => [Enterprise, Community], :position => ['1', '2', '3']} } end end |