Commit 86f07a0e248ab543baa2f83f14894056050d2924
1 parent
b8a7be04
Exists in
master
and in
28 other branches
ActionItem165: just add members if profile is opened, if closed create taks to admin
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1843 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
16 additions
and
9 deletions
Show diff stats
app/controllers/my_profile/memberships_controller.rb
| @@ -9,13 +9,7 @@ class MembershipsController < MyProfileController | @@ -9,13 +9,7 @@ class MembershipsController < MyProfileController | ||
| 9 | def join | 9 | def join |
| 10 | @to_join = Profile.find(params[:id]) | 10 | @to_join = Profile.find(params[:id]) |
| 11 | if request.post? && params[:confirmation] | 11 | if request.post? && params[:confirmation] |
| 12 | - if @to_join.closed? | ||
| 13 | - # FIXME closed field added to organization, dont to profile. its correct? | ||
| 14 | - AddMember.create!(:person => profile, :community => @to_join) | ||
| 15 | - else | ||
| 16 | - @to_join.add_member(profile) | ||
| 17 | - end | ||
| 18 | - | 12 | + @to_join.add_member(profile) |
| 19 | redirect_to @to_join.url | 13 | redirect_to @to_join.url |
| 20 | end | 14 | end |
| 21 | end | 15 | end |
app/models/add_member.rb
| @@ -7,9 +7,13 @@ class AddMember < Task | @@ -7,9 +7,13 @@ class AddMember < Task | ||
| 7 | 7 | ||
| 8 | alias :community :target | 8 | alias :community :target |
| 9 | alias :community= :target= | 9 | alias :community= :target= |
| 10 | + alias :organization :target | ||
| 11 | + alias :organization= :target= | ||
| 12 | + alias :enterprise :target | ||
| 13 | + alias :enterprise= :target= | ||
| 10 | 14 | ||
| 11 | def perform | 15 | def perform |
| 12 | - target.add_member(requestor) | 16 | + target.affiliate(requestor, Profile::Roles.member) |
| 13 | end | 17 | end |
| 14 | 18 | ||
| 15 | # FIXME should send email to community admin? | 19 | # FIXME should send email to community admin? |
app/models/profile.rb
| @@ -257,7 +257,11 @@ class Profile < ActiveRecord::Base | @@ -257,7 +257,11 @@ class Profile < ActiveRecord::Base | ||
| 257 | # Adds a person as member of this Profile. | 257 | # Adds a person as member of this Profile. |
| 258 | def add_member(person) | 258 | def add_member(person) |
| 259 | if self.has_members? | 259 | if self.has_members? |
| 260 | - self.affiliate(person, Profile::Roles.member) | 260 | + if self.closed? |
| 261 | + AddMember.create!(:person => person, :organization => self) | ||
| 262 | + else | ||
| 263 | + self.affiliate(person, Profile::Roles.member) | ||
| 264 | + end | ||
| 261 | else | 265 | else |
| 262 | raise _("%s can't has members") % self.class.name | 266 | raise _("%s can't has members") % self.class.name |
| 263 | end | 267 | end |
test/unit/add_member_test.rb
| @@ -61,4 +61,9 @@ class AddMemberTest < ActiveSupport::TestCase | @@ -61,4 +61,9 @@ class AddMemberTest < ActiveSupport::TestCase | ||
| 61 | assert_equal 'testuser1 wants to be a member', task.description | 61 | assert_equal 'testuser1 wants to be a member', task.description |
| 62 | end | 62 | end |
| 63 | 63 | ||
| 64 | + should 'has community alias to target' do | ||
| 65 | + t = AddMember.new | ||
| 66 | + assert_same t.target, t.community | ||
| 67 | + end | ||
| 68 | + | ||
| 64 | end | 69 | end |