Commit 4ddf4cfc7f9d4a8d2f0824417af7a6180f9c0b9f
Committed by
Antonio Terceiro
1 parent
6e11fc41
Exists in
staging
and in
42 other branches
A duplicated membership request doesn't create a new task
(ActionItem1374)
Showing
4 changed files
with
22 additions
and
11 deletions
Show diff stats
app/models/organization.rb
@@ -28,7 +28,7 @@ class Organization < Profile | @@ -28,7 +28,7 @@ class Organization < Profile | ||
28 | end | 28 | end |
29 | 29 | ||
30 | def find_pending_validation(code) | 30 | def find_pending_validation(code) |
31 | - validations.pending.find { |pending| pending.code == code } | 31 | + validations.pending.find(:first, :conditions => {:code => code}) |
32 | end | 32 | end |
33 | 33 | ||
34 | def processed_validations | 34 | def processed_validations |
@@ -36,7 +36,7 @@ class Organization < Profile | @@ -36,7 +36,7 @@ class Organization < Profile | ||
36 | end | 36 | end |
37 | 37 | ||
38 | def find_processed_validation(code) | 38 | def find_processed_validation(code) |
39 | - validations.finished.find { |pending| pending.code == code } | 39 | + validations.finished.find(:first, :conditions => {:code => code}) |
40 | end | 40 | end |
41 | 41 | ||
42 | def is_validation_entity? | 42 | def is_validation_entity? |
@@ -93,4 +93,7 @@ class Organization < Profile | @@ -93,4 +93,7 @@ class Organization < Profile | ||
93 | [contact_email.blank? ? nil : contact_email].compact + admins.map(&:email) | 93 | [contact_email.blank? ? nil : contact_email].compact + admins.map(&:email) |
94 | end | 94 | end |
95 | 95 | ||
96 | + def already_request_membership?(person) | ||
97 | + self.tasks.pending.find_by_requestor_id(person.id, :conditions => { :type => 'AddMember' }) | ||
98 | + end | ||
96 | end | 99 | end |
app/models/profile.rb
@@ -475,7 +475,7 @@ private :generate_url, :url_options | @@ -475,7 +475,7 @@ private :generate_url, :url_options | ||
475 | def add_member(person) | 475 | def add_member(person) |
476 | if self.has_members? | 476 | if self.has_members? |
477 | if self.closed? | 477 | if self.closed? |
478 | - AddMember.create!(:person => person, :organization => self) | 478 | + AddMember.create!(:person => person, :organization => self) unless self.already_request_membership?(person) |
479 | else | 479 | else |
480 | self.affiliate(person, Profile::Roles.member(environment.id)) | 480 | self.affiliate(person, Profile::Roles.member(environment.id)) |
481 | end | 481 | end |
app/models/task.rb
@@ -176,15 +176,10 @@ class Task < ActiveRecord::Base | @@ -176,15 +176,10 @@ class Task < ActiveRecord::Base | ||
176 | end | 176 | end |
177 | end | 177 | end |
178 | 178 | ||
179 | - class << self | 179 | + named_scope :pending, :conditions => { :status => Task::Status::ACTIVE } |
180 | + named_scope :finished, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } | ||
180 | 181 | ||
181 | - def pending | ||
182 | - self.find(:all, :conditions => { :status => Task::Status::ACTIVE }) | ||
183 | - end | ||
184 | - | ||
185 | - def finished | ||
186 | - self.find(:all, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED]}) | ||
187 | - end | 182 | + class << self |
188 | 183 | ||
189 | # generates a random code string consisting of length characters (or 36 by | 184 | # generates a random code string consisting of length characters (or 36 by |
190 | # default) in the ranges a-z and 0-9 | 185 | # default) in the ranges a-z and 0-9 |
test/unit/community_test.rb
@@ -187,4 +187,17 @@ class CommunityTest < Test::Unit::TestCase | @@ -187,4 +187,17 @@ class CommunityTest < Test::Unit::TestCase | ||
187 | Community.create_after_moderation(person, {:environment => env, :name => 'Example'}) | 187 | Community.create_after_moderation(person, {:environment => env, :name => 'Example'}) |
188 | end | 188 | end |
189 | end | 189 | end |
190 | + | ||
191 | + should 'not create new request membership if it already exists' do | ||
192 | + community = fast_create(Community) | ||
193 | + community.closed = true | ||
194 | + community.save | ||
195 | + assert_difference AddMember, :count do | ||
196 | + community.add_member(person) | ||
197 | + end | ||
198 | + | ||
199 | + assert_no_difference AddMember, :count do | ||
200 | + community.add_member(person) | ||
201 | + end | ||
202 | + end | ||
190 | end | 203 | end |