Commit e713df48762190e0402655f43ddd9b2e94e497e1
1 parent
cc56cb65
Exists in
master
and in
29 other branches
ActionItem5: changed the way of getting the memberships of a user
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@558 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
20 additions
and
24 deletions
Show diff stats
app/controllers/profile_admin/membership_editor_controller.rb
app/models/person.rb
... | ... | @@ -10,7 +10,6 @@ class Person < Profile |
10 | 10 | has_one :person_info |
11 | 11 | |
12 | 12 | has_many :role_assignments |
13 | - has_many :memberships, :through => :role_assignments, :source => 'resource', :class_name => 'Enterprise' | |
14 | 13 | |
15 | 14 | def has_permission?(perm, res=nil) |
16 | 15 | role_assignments.any? {|ra| ra.has_permission?(perm, res)} |
... | ... | @@ -30,27 +29,14 @@ class Person < Profile |
30 | 29 | new_conditions |
31 | 30 | end |
32 | 31 | |
33 | - def profiles(conditions = {}) | |
32 | + def memberships(conditions = {}) | |
34 | 33 | Profile.find( |
35 | 34 | :all, |
36 | 35 | :conditions => self.class.conditions_for_profiles(conditions, self), |
37 | 36 | :joins => "LEFT JOIN role_assignments ON profiles.id = role_assignments.resource_id AND role_assignments.resource_type = \"#{Profile.base_class.name}\"", |
38 | 37 | :select => 'profiles.*') |
39 | 38 | end |
40 | - | |
41 | 39 | |
42 | - def enterprises(conditions = {}) | |
43 | - profiles( ({:type => 'Enterprise'}).merge(conditions)) | |
44 | - end | |
45 | - | |
46 | - def pending_enterprises | |
47 | - enterprises :active => false | |
48 | - end | |
49 | - | |
50 | - def active_enterprises | |
51 | - enterprises :active => true | |
52 | - end | |
53 | - | |
54 | 40 | def info |
55 | 41 | person_info |
56 | 42 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -19,7 +19,7 @@ class PersonTest < Test::Unit::TestCase |
19 | 19 | assert pe.save |
20 | 20 | member_role = Role.create(:name => 'member') |
21 | 21 | pr.affiliate(pe, member_role) |
22 | - assert pe.profiles.include?(pr) | |
22 | + assert pe.memberships.include?(pr) | |
23 | 23 | end |
24 | 24 | |
25 | 25 | def test_can_belongs_to_an_enterprise |
... | ... | @@ -29,7 +29,7 @@ class PersonTest < Test::Unit::TestCase |
29 | 29 | assert p.save |
30 | 30 | member_role = Role.create(:name => 'member') |
31 | 31 | e.affiliate(p, member_role) |
32 | - assert p.enterprises.include?(e) | |
32 | + assert p.memberships.include?(e) | |
33 | 33 | end |
34 | 34 | |
35 | 35 | def test_can_have_user |
... | ... | @@ -65,15 +65,25 @@ class PersonTest < Test::Unit::TestCase |
65 | 65 | end |
66 | 66 | |
67 | 67 | should 'change the roles of the user' do |
68 | - assert p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person | |
69 | - assert e = Enterprise.create(:identifier => 'enter') | |
70 | - assert r1 = Role.create(:name => 'associate') | |
68 | + p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person | |
69 | + e = Enterprise.create(:identifier => 'enter', :name => 'Enter') | |
70 | + r1 = Role.create(:name => 'associate') | |
71 | 71 | assert e.affiliate(p, r1) |
72 | - assert r2 = Role.create(:name => 'partner') | |
72 | + r2 = Role.create(:name => 'partner') | |
73 | 73 | assert p.define_roles([r2], e) |
74 | - p = Person.find(p.id) | |
74 | + p.reload | |
75 | 75 | assert p.role_assignments.any? {|ra| ra.role == r2} |
76 | 76 | assert !p.role_assignments.any? {|ra| ra.role == r1} |
77 | 77 | end |
78 | 78 | |
79 | + should 'report that the user has the permission' do | |
80 | + p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person | |
81 | + r = Role.create(:name => 'associate', :permissions => ['edit_profile']) | |
82 | + e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri') | |
83 | + assert e.affiliate(p, r) | |
84 | + assert p.reload | |
85 | + assert e.reload | |
86 | + assert p.has_permission?('edit_profile', e) | |
87 | + assert !p.has_permission?('destroy_profile', e) | |
88 | + end | |
79 | 89 | end | ... | ... |
test/unit/profile_test.rb