Commit 8ffa32e9d288d2d5f5bc376f63fb265d09f1368e

Authored by Joenio Costa
1 parent 70ccb75c

Removing send_mail method from profile_members_controller

(ActionItem2388)
app/controllers/my_profile/profile_members_controller.rb
@@ -156,18 +156,4 @@ class ProfileMembersController < MyProfileController @@ -156,18 +156,4 @@ class ProfileMembersController < MyProfileController
156 end 156 end
157 end 157 end
158 158
159 - def send_mail  
160 - @mailing = profile.mailings.build(params[:mailing])  
161 - if request.post?  
162 - @mailing.locale = locale  
163 - @mailing.person = user  
164 - if @mailing.save  
165 - session[:notice] = _('The e-mails are being sent')  
166 - redirect_to :action => 'index'  
167 - else  
168 - session[:notice] = _('Could not create the e-mail')  
169 - end  
170 - end  
171 - end  
172 -  
173 end 159 end
app/controllers/public/profile_controller.rb
@@ -3,7 +3,7 @@ class ProfileController < PublicController @@ -3,7 +3,7 @@ class ProfileController < PublicController
3 needs_profile 3 needs_profile
4 before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] 4 before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add]
5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] 5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail]
6 - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity] 6 + before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail]
7 7
8 helper TagsHelper 8 helper TagsHelper
9 9
app/views/profile/send_mail.rhtml
@@ -10,5 +10,5 @@ @@ -10,5 +10,5 @@
10 <%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %> 10 <%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %>
11 <%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %> 11 <%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %>
12 <%= submit_button(:send, _('Send')) %> 12 <%= submit_button(:send, _('Send')) %>
13 - <%= button :cancel, _('Cancel e-mail'), :action => 'members' %> 13 + <%= button :cancel, _('Cancel e-mail'), :back %>
14 <% end %> 14 <% end %>
app/views/profile_members/_index_buttons.rhtml
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 <% if profile.community? and user.has_permission?(:invite_members, profile) %> 4 <% if profile.community? and user.has_permission?(:invite_members, profile) %>
5 <%= button :search, _('Invite your friends to join %s') % profile.short_name, :controller => 'invite', :action => 'select_address_book' %> 5 <%= button :search, _('Invite your friends to join %s') % profile.short_name, :controller => 'invite', :action => 'select_address_book' %>
6 <% end %> 6 <% end %>
7 - <%= button :send, _('Send e-mail to members'), :action => 'send_mail' %> 7 + <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %>
8 <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> 8 <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %>
9 <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> 9 <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %>
10 <% end %> 10 <% end %>
app/views/profile_members/send_mail.rhtml
@@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
1 -<h1><%= h profile.short_name(50) %></h1>  
2 -  
3 -<h2><%= _('Send e-mail to members') %></h2>  
4 -  
5 -<%= error_messages_for :mailing %>  
6 -  
7 -<%= render :file => 'shared/tiny_mce' %>  
8 -  
9 -<% form_for :mailing, :url => {:action => 'send_mail'}, :html => {:id => 'mailing-form'} do |f| %>  
10 - <%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %>  
11 - <%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %>  
12 - <%= submit_button(:send, _('Send')) %>  
13 - <%= button :cancel, _('Cancel e-mail'), :action => 'index' %>  
14 -<% end %>  
features/send_email_to_organization_members.feature
@@ -17,7 +17,7 @@ Feature: send emails to organization members @@ -17,7 +17,7 @@ Feature: send emails to organization members
17 17
18 Scenario: Cant access if not logged in 18 Scenario: Cant access if not logged in
19 Given I am not logged in 19 Given I am not logged in
20 - When I go to /myprofile/sample-community/profile_members/send_mail 20 + When I go to /profile/sample-community/send_mail
21 Then I should be on login page 21 Then I should be on login page
22 22
23 Scenario: Cant access as normal user 23 Scenario: Cant access as normal user
@@ -25,7 +25,7 @@ Feature: send emails to organization members @@ -25,7 +25,7 @@ Feature: send emails to organization members
25 | login | 25 | login |
26 | josesilva | 26 | josesilva |
27 And I am logged in as "josesilva" 27 And I am logged in as "josesilva"
28 - When I go to /myprofile/sample-community/profile_members/send_mail 28 + When I go to /profile/sample-community/send_mail
29 Then I should see "Access denied" 29 Then I should see "Access denied"
30 30
31 Scenario: Send e-mail to members 31 Scenario: Send e-mail to members
@@ -43,7 +43,7 @@ Feature: send emails to organization members @@ -43,7 +43,7 @@ Feature: send emails to organization members
43 And I follow "Send e-mail to members" 43 And I follow "Send e-mail to members"
44 And I fill in "body" with "We have some news" 44 And I fill in "body" with "We have some news"
45 When I press "Send" 45 When I press "Send"
46 - Then I should be on /myprofile/sample-community/profile_members/send_mail 46 + Then I should be on /profile/sample-community/send_mail
47 47
48 Scenario: Not send e-mail to members if body is blank 48 Scenario: Not send e-mail to members if body is blank
49 Given I am logged in as "joaosilva" 49 Given I am logged in as "joaosilva"
@@ -51,7 +51,7 @@ Feature: send emails to organization members @@ -51,7 +51,7 @@ Feature: send emails to organization members
51 And I follow "Send e-mail to members" 51 And I follow "Send e-mail to members"
52 And I fill in "Subject" with "Hello, user!" 52 And I fill in "Subject" with "Hello, user!"
53 When I press "Send" 53 When I press "Send"
54 - Then I should be on /myprofile/sample-community/profile_members/send_mail 54 + Then I should be on /profile/sample-community/send_mail
55 55
56 Scenario: Cancel creation of mailing 56 Scenario: Cancel creation of mailing
57 Given I am logged in as "joaosilva" 57 Given I am logged in as "joaosilva"
test/fixtures/roles.yml
@@ -53,6 +53,7 @@ profile_admin: @@ -53,6 +53,7 @@ profile_admin:
53 - post_content 53 - post_content
54 - view_private_content 54 - view_private_content
55 - manage_products 55 - manage_products
  56 + - send_mail_to_members
56 profile_member: 57 profile_member:
57 id: 6 58 id: 6
58 environment_id: 1 59 environment_id: 1
test/functional/profile_controller_test.rb
@@ -1351,7 +1351,6 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1351,7 +1351,6 @@ class ProfileControllerTest &lt; ActionController::TestCase
1351 @controller.stubs(:locale).returns('pt') 1351 @controller.stubs(:locale).returns('pt')
1352 post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} 1352 post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}
1353 assert_equal ['Hello', 'We have some news'], [assigns(:mailing).subject, assigns(:mailing).body] 1353 assert_equal ['Hello', 'We have some news'], [assigns(:mailing).subject, assigns(:mailing).body]
1354 - assert_redirected_to :action => 'members'  
1355 end 1354 end
1356 1355
1357 should 'add the user logged on mailing' do 1356 should 'add the user logged on mailing' do
@@ -1362,4 +1361,14 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1362,4 +1361,14 @@ class ProfileControllerTest &lt; ActionController::TestCase
1362 assert_equal Profile['profile_moderator_user'], assigns(:mailing).person 1361 assert_equal Profile['profile_moderator_user'], assigns(:mailing).person
1363 end 1362 end
1364 1363
  1364 + should 'redirect back to right place after mail' do
  1365 + community = fast_create(Community)
  1366 + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community)
  1367 + login_as('profile_moderator_user')
  1368 + @controller.stubs(:locale).returns('pt')
  1369 + @request.expects(:referer).returns("/profile/#{community.identifier}/members")
  1370 + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}
  1371 + assert_redirected_to :action => 'members'
  1372 + end
  1373 +
1365 end 1374 end
test/functional/profile_members_controller_test.rb
@@ -328,33 +328,6 @@ class ProfileMembersControllerTest &lt; ActionController::TestCase @@ -328,33 +328,6 @@ class ProfileMembersControllerTest &lt; ActionController::TestCase
328 assert p_roles, [r] 328 assert p_roles, [r]
329 end 329 end
330 330
331 - should 'add locale on mailing' do  
332 - community = fast_create(Community)  
333 - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community)  
334 - login_as('profile_admin_user')  
335 - @controller.stubs(:locale).returns('pt')  
336 - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}  
337 - assert_equal 'pt', assigns(:mailing).locale  
338 - end  
339 -  
340 - should 'save mailing' do  
341 - community = fast_create(Community)  
342 - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community)  
343 - login_as('profile_admin_user')  
344 - @controller.stubs(:locale).returns('pt')  
345 - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}  
346 - assert_equal ['Hello', 'We have some news'], [assigns(:mailing).subject, assigns(:mailing).body]  
347 - assert_redirected_to :action => 'index'  
348 - end  
349 -  
350 - should 'add the user logged on mailing' do  
351 - community = fast_create(Community)  
352 - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community)  
353 - login_as('profile_admin_user')  
354 - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}  
355 - assert_equal Profile['profile_admin_user'], assigns(:mailing).person  
356 - end  
357 -  
358 should 'set a community member as admin' do 331 should 'set a community member as admin' do
359 community = fast_create(Community) 332 community = fast_create(Community)
360 admin = create_user_with_permission('admin_user', 'manage_memberships', community) 333 admin = create_user_with_permission('admin_user', 'manage_memberships', community)