Commit 1445c0a767a994e4f680170e647314b301516bec
1 parent
a717e2b7
Exists in
staging
sub-organizations: rename scope parents to parentz to avoid active_record method override
Showing
6 changed files
with
9 additions
and
9 deletions
Show diff stats
plugins/sub_organizations/controllers/sub_organizations_plugin_profile_controller.rb
@@ -10,7 +10,7 @@ class SubOrganizationsPluginProfileController < ProfileController | @@ -10,7 +10,7 @@ class SubOrganizationsPluginProfileController < ProfileController | ||
10 | end | 10 | end |
11 | 11 | ||
12 | def parents | 12 | def parents |
13 | - parents = Organization.parents(profile) | 13 | + parents = Organization.parentz(profile) |
14 | family_relation(parents) | 14 | family_relation(parents) |
15 | render 'related_organizations' | 15 | render 'related_organizations' |
16 | end | 16 | end |
plugins/sub_organizations/lib/ext/organization.rb
@@ -18,7 +18,7 @@ class Organization | @@ -18,7 +18,7 @@ class Organization | ||
18 | where("relations.parent_id = ?", parent.id) | 18 | where("relations.parent_id = ?", parent.id) |
19 | } | 19 | } |
20 | 20 | ||
21 | - scope :parents, -> *children { | 21 | + scope :parentz, -> *children { |
22 | joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id"). | 22 | joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id"). |
23 | where("relations.child_id in (?)", children.map(&:id)) | 23 | where("relations.child_id in (?)", children.map(&:id)) |
24 | } | 24 | } |
plugins/sub_organizations/lib/related_organizations_block.rb
@@ -41,7 +41,7 @@ class RelatedOrganizationsBlock < ProfileListBlock | @@ -41,7 +41,7 @@ class RelatedOrganizationsBlock < ProfileListBlock | ||
41 | 41 | ||
42 | def related_organizations | 42 | def related_organizations |
43 | profile = self.owner | 43 | profile = self.owner |
44 | - organizations = Organization.parents(profile) | 44 | + organizations = Organization.parentz(profile) |
45 | 45 | ||
46 | if organizations.blank? | 46 | if organizations.blank? |
47 | @display_type = {:title => 'sub', :action => 'children'} | 47 | @display_type = {:title => 'sub', :action => 'children'} |
plugins/sub_organizations/lib/sub_organizations_plugin.rb
@@ -19,7 +19,7 @@ class SubOrganizationsPlugin < Noosfero::Plugin | @@ -19,7 +19,7 @@ class SubOrganizationsPlugin < Noosfero::Plugin | ||
19 | end | 19 | end |
20 | 20 | ||
21 | def control_panel_buttons | 21 | def control_panel_buttons |
22 | - if context.profile.organization? && Organization.parents(context.profile).blank? | 22 | + if context.profile.organization? && Organization.parentz(context.profile).blank? |
23 | { title: _('Manage sub-groups'), icon: 'groups', url: {profile: profile.identifier, controller: :sub_organizations_plugin_myprofile} } | 23 | { title: _('Manage sub-groups'), icon: 'groups', url: {profile: profile.identifier, controller: :sub_organizations_plugin_myprofile} } |
24 | end | 24 | end |
25 | end | 25 | end |
@@ -34,12 +34,12 @@ class SubOrganizationsPlugin < Noosfero::Plugin | @@ -34,12 +34,12 @@ class SubOrganizationsPlugin < Noosfero::Plugin | ||
34 | end | 34 | end |
35 | 35 | ||
36 | def person_memberships(person) | 36 | def person_memberships(person) |
37 | - Organization.parents(*Profile.memberships_of(person)) | 37 | + Organization.parentz(*Profile.memberships_of(person)) |
38 | end | 38 | end |
39 | 39 | ||
40 | def has_permission?(person, permission, target) | 40 | def has_permission?(person, permission, target) |
41 | if !target.kind_of?(Environment) && target.organization? | 41 | if !target.kind_of?(Environment) && target.organization? |
42 | - Organization.parents(target).map do |parent| | 42 | + Organization.parentz(target).map do |parent| |
43 | person.has_permission_without_plugins?(permission, parent) | 43 | person.has_permission_without_plugins?(permission, parent) |
44 | end.include?(true) | 44 | end.include?(true) |
45 | end | 45 | end |
plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb
@@ -21,7 +21,7 @@ class SubOrganizationsPlugin::Relation < ApplicationRecord | @@ -21,7 +21,7 @@ class SubOrganizationsPlugin::Relation < ApplicationRecord | ||
21 | end | 21 | end |
22 | 22 | ||
23 | def no_multi_level | 23 | def no_multi_level |
24 | - if Organization.parents(parent).present? || Organization.children(child).present? | 24 | + if Organization.parentz(parent).present? || Organization.children(child).present? |
25 | errors.add(:child, _('multi-level paternity is not allowed.')) | 25 | errors.add(:child, _('multi-level paternity is not allowed.')) |
26 | end | 26 | end |
27 | end | 27 | end |
plugins/sub_organizations/test/unit/relation_test.rb
@@ -39,8 +39,8 @@ class RelationTest < ActiveSupport::TestCase | @@ -39,8 +39,8 @@ class RelationTest < ActiveSupport::TestCase | ||
39 | SubOrganizationsPlugin::Relation.create!(:parent => parent1, :child => child) | 39 | SubOrganizationsPlugin::Relation.create!(:parent => parent1, :child => child) |
40 | SubOrganizationsPlugin::Relation.create!(:parent => parent2, :child => child) | 40 | SubOrganizationsPlugin::Relation.create!(:parent => parent2, :child => child) |
41 | 41 | ||
42 | - assert_includes Organization.parents(child), parent1 | ||
43 | - assert_includes Organization.parents(child), parent2 | 42 | + assert_includes Organization.parentz(child), parent1 |
43 | + assert_includes Organization.parentz(child), parent2 | ||
44 | end | 44 | end |
45 | 45 | ||
46 | should 'be able to retrieve children of an organization' do | 46 | should 'be able to retrieve children of an organization' do |