Commit 9c9f0fbcf6f586fb71a768fd0706331fb15f228f

Authored by Rodrigo Souto
2 parents 5e8e25e9 8ac3abc1

Merge branch 'show_email_in_task' into 'master'

Show email of requestor in AddMember task

Add user email on the screen to process the request to enter on the community.

softwarepublico issue: https://softwarepublico.gov.br/gitlab/softwarepublico/softwarepublico/issues/238

See merge request !696
app/models/add_member.rb
... ... @@ -29,8 +29,10 @@ class AddMember < Task
29 29 end
30 30  
31 31 def information
32   - {:message => _("%{requestor} wants to be a member of '%{organization}'."),
33   - variables: {requestor: requestor.name, organization: organization.name}}
  32 + requestor_email = " (#{requestor.email})" if requestor.may_display_field_to?("email")
  33 +
  34 + {:message => _("%{requestor}%{requestor_email} wants to be a member of '%{organization}'."),
  35 + variables: {requestor: requestor.name, requestor_email: requestor_email, organization: organization.name}}
34 36 end
35 37  
36 38 def accept_details
... ... @@ -46,7 +48,9 @@ class AddMember < Task
46 48 end
47 49  
48 50 def target_notification_description
49   - _("%{requestor} wants to be a member of '%{organization}'.") % {:requestor => requestor.name, :organization => organization.name}
  51 + requestor_email = " (#{requestor.email})" if requestor.may_display_field_to?("email")
  52 +
  53 + _("%{requestor}%{requestor_email} wants to be a member of '%{organization}'.") % {:requestor => requestor.name, :requestor_email => requestor_email, :organization => organization.name}
50 54 end
51 55  
52 56 def target_notification_message
... ...
test/unit/add_member_test.rb
... ... @@ -121,4 +121,21 @@ class AddMemberTest < ActiveSupport::TestCase
121 121 assert_match(/#{task.requestor.name} wants to be a member of '#{community.name}'/, email.subject)
122 122 end
123 123  
  124 + should 'notification description with requestor email if requestor email is public' do
  125 + new_person = create_user('testuser').person
  126 + new_person.update_attributes!({:fields_privacy => {:email => 'public'}})
  127 +
  128 + task = AddMember.new(:person => new_person, :organization => community)
  129 +
  130 + assert_match(/\(#{task.requestor.email}\)/, task.target_notification_description)
  131 + end
  132 +
  133 + should 'notification description without requestor email if requestor email is not public' do
  134 + new_person = create_user('testuser').person
  135 + new_person.update_attributes!({:fields_privacy => {:email => '0'}})
  136 +
  137 + task = AddMember.new(:person => new_person, :organization => community)
  138 +
  139 + assert_not_match(/\(#{task.requestor.email}\)/, task.target_notification_description)
  140 + end
124 141 end
... ...