Commit 9b7b90a1b5aa48c6da9ad6d1e12d5719a40a021d

Authored by Rodrigo Souto
1 parent cb340c2b

Fixing report abuse for organizations

(ActionItem2104)
app/models/organization.rb
@@ -157,4 +157,8 @@ class Organization < Profile @@ -157,4 +157,8 @@ class Organization < Profile
157 members_by_role(role).map { |member| {:id => member.id, :name => member.name} }.to_json 157 members_by_role(role).map { |member| {:id => member.id, :name => member.name} }.to_json
158 end 158 end
159 159
  160 + def disable
  161 + self.visible = false
  162 + save!
  163 + end
160 end 164 end
app/models/person.rb
@@ -406,6 +406,14 @@ class Person < Profile @@ -406,6 +406,14 @@ class Person < Profile
406 {:title => _('Profile Info and settings'), :icon => 'edit-profile'} 406 {:title => _('Profile Info and settings'), :icon => 'edit-profile'}
407 end 407 end
408 408
  409 + def disable
  410 + self.visible = false
  411 + user.password = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{identifier}--")
  412 + user.password_confirmation = user.password
  413 + save!
  414 + user.save!
  415 + end
  416 +
409 protected 417 protected
410 418
411 def followed_by?(profile) 419 def followed_by?(profile)
app/models/profile.rb
@@ -806,11 +806,6 @@ private :generate_url, :url_options @@ -806,11 +806,6 @@ private :generate_url, :url_options
806 end 806 end
807 807
808 def disable 808 def disable
809 - self.visible = false  
810 - user.password = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{identifier}--")  
811 - user.password_confirmation = user.password  
812 - save!  
813 - user.save!  
814 end 809 end
815 810
816 def control_panel_settings_button 811 def control_panel_settings_button
test/unit/organization_test.rb
@@ -408,4 +408,12 @@ class OrganizationTest < Test::Unit::TestCase @@ -408,4 +408,12 @@ class OrganizationTest < Test::Unit::TestCase
408 assert_match [{:id => p1.id, :name => p1.name}, {:id => p2.id, :name => p2.name}].to_json, organization.members_by_role_to_json(role) 408 assert_match [{:id => p1.id, :name => p1.name}, {:id => p2.id, :name => p2.name}].to_json, organization.members_by_role_to_json(role)
409 end 409 end
410 410
  411 + should 'disable organization' do
  412 + organization = fast_create(Organization, :visible => true)
  413 + assert organization.visible
  414 +
  415 + organization.disable
  416 + assert !organization.visible
  417 + end
  418 +
411 end 419 end
test/unit/person_test.rb
@@ -1227,4 +1227,14 @@ class PersonTest < Test::Unit::TestCase @@ -1227,4 +1227,14 @@ class PersonTest < Test::Unit::TestCase
1227 assert person.already_reported?(profile) 1227 assert person.already_reported?(profile)
1228 end 1228 end
1229 1229
  1230 + should 'disable person' do
  1231 + person = create_user('some-user').person
  1232 + password = person.user.password
  1233 + assert person.visible
  1234 +
  1235 + person.disable
  1236 +
  1237 + assert !person.visible
  1238 + assert_not_equal password, person.user.password
  1239 + end
1230 end 1240 end