Commit 4ddf4cfc7f9d4a8d2f0824417af7a6180f9c0b9f
Committed by
Antonio Terceiro
1 parent
6e11fc41
Exists in
master
and in
22 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 | 28 | end |
| 29 | 29 | |
| 30 | 30 | def find_pending_validation(code) |
| 31 | - validations.pending.find { |pending| pending.code == code } | |
| 31 | + validations.pending.find(:first, :conditions => {:code => code}) | |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | def processed_validations |
| ... | ... | @@ -36,7 +36,7 @@ class Organization < Profile |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 38 | def find_processed_validation(code) |
| 39 | - validations.finished.find { |pending| pending.code == code } | |
| 39 | + validations.finished.find(:first, :conditions => {:code => code}) | |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | def is_validation_entity? |
| ... | ... | @@ -93,4 +93,7 @@ class Organization < Profile |
| 93 | 93 | [contact_email.blank? ? nil : contact_email].compact + admins.map(&:email) |
| 94 | 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 | 99 | end | ... | ... |
app/models/profile.rb
| ... | ... | @@ -475,7 +475,7 @@ private :generate_url, :url_options |
| 475 | 475 | def add_member(person) |
| 476 | 476 | if self.has_members? |
| 477 | 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 | 479 | else |
| 480 | 480 | self.affiliate(person, Profile::Roles.member(environment.id)) |
| 481 | 481 | end | ... | ... |
app/models/task.rb
| ... | ... | @@ -176,15 +176,10 @@ class Task < ActiveRecord::Base |
| 176 | 176 | end |
| 177 | 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 | 184 | # generates a random code string consisting of length characters (or 36 by |
| 190 | 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 | 187 | Community.create_after_moderation(person, {:environment => env, :name => 'Example'}) |
| 188 | 188 | end |
| 189 | 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 | 203 | end | ... | ... |