From 8ffa32e9d288d2d5f5bc376f63fb265d09f1368e Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Fri, 24 Aug 2012 10:20:07 -0300 Subject: [PATCH] Removing send_mail method from profile_members_controller --- app/controllers/my_profile/profile_members_controller.rb | 14 -------------- app/controllers/public/profile_controller.rb | 2 +- app/views/profile/send_mail.rhtml | 2 +- app/views/profile_members/_index_buttons.rhtml | 2 +- app/views/profile_members/send_mail.rhtml | 14 -------------- features/send_email_to_organization_members.feature | 8 ++++---- test/fixtures/roles.yml | 1 + test/functional/profile_controller_test.rb | 11 ++++++++++- test/functional/profile_members_controller_test.rb | 27 --------------------------- 9 files changed, 18 insertions(+), 63 deletions(-) delete mode 100644 app/views/profile_members/send_mail.rhtml diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index 8ae25c6..413ac62 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -156,18 +156,4 @@ class ProfileMembersController < MyProfileController end end - def send_mail - @mailing = profile.mailings.build(params[:mailing]) - if request.post? - @mailing.locale = locale - @mailing.person = user - if @mailing.save - session[:notice] = _('The e-mails are being sent') - redirect_to :action => 'index' - else - session[:notice] = _('Could not create the e-mail') - end - end - end - end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 712c45e..9d97368 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -3,7 +3,7 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] - 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] + 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] helper TagsHelper diff --git a/app/views/profile/send_mail.rhtml b/app/views/profile/send_mail.rhtml index 7bc068e..185f7cd 100644 --- a/app/views/profile/send_mail.rhtml +++ b/app/views/profile/send_mail.rhtml @@ -10,5 +10,5 @@ <%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %> <%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %> <%= submit_button(:send, _('Send')) %> - <%= button :cancel, _('Cancel e-mail'), :action => 'members' %> + <%= button :cancel, _('Cancel e-mail'), :back %> <% end %> diff --git a/app/views/profile_members/_index_buttons.rhtml b/app/views/profile_members/_index_buttons.rhtml index c94e889..e9c8fcb 100644 --- a/app/views/profile_members/_index_buttons.rhtml +++ b/app/views/profile_members/_index_buttons.rhtml @@ -4,7 +4,7 @@ <% if profile.community? and user.has_permission?(:invite_members, profile) %> <%= button :search, _('Invite your friends to join %s') % profile.short_name, :controller => 'invite', :action => 'select_address_book' %> <% end %> - <%= button :send, _('Send e-mail to members'), :action => 'send_mail' %> + <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %> <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> <% end %> diff --git a/app/views/profile_members/send_mail.rhtml b/app/views/profile_members/send_mail.rhtml deleted file mode 100644 index 48a3ef6..0000000 --- a/app/views/profile_members/send_mail.rhtml +++ /dev/null @@ -1,14 +0,0 @@ -

<%= h profile.short_name(50) %>

- -

<%= _('Send e-mail to members') %>

- -<%= error_messages_for :mailing %> - -<%= render :file => 'shared/tiny_mce' %> - -<% form_for :mailing, :url => {:action => 'send_mail'}, :html => {:id => 'mailing-form'} do |f| %> - <%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %> - <%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %> - <%= submit_button(:send, _('Send')) %> - <%= button :cancel, _('Cancel e-mail'), :action => 'index' %> -<% end %> diff --git a/features/send_email_to_organization_members.feature b/features/send_email_to_organization_members.feature index cdc8ceb..c0eefaf 100644 --- a/features/send_email_to_organization_members.feature +++ b/features/send_email_to_organization_members.feature @@ -17,7 +17,7 @@ Feature: send emails to organization members Scenario: Cant access if not logged in Given I am not logged in - When I go to /myprofile/sample-community/profile_members/send_mail + When I go to /profile/sample-community/send_mail Then I should be on login page Scenario: Cant access as normal user @@ -25,7 +25,7 @@ Feature: send emails to organization members | login | | josesilva | And I am logged in as "josesilva" - When I go to /myprofile/sample-community/profile_members/send_mail + When I go to /profile/sample-community/send_mail Then I should see "Access denied" Scenario: Send e-mail to members @@ -43,7 +43,7 @@ Feature: send emails to organization members And I follow "Send e-mail to members" And I fill in "body" with "We have some news" When I press "Send" - Then I should be on /myprofile/sample-community/profile_members/send_mail + Then I should be on /profile/sample-community/send_mail Scenario: Not send e-mail to members if body is blank Given I am logged in as "joaosilva" @@ -51,7 +51,7 @@ Feature: send emails to organization members And I follow "Send e-mail to members" And I fill in "Subject" with "Hello, user!" When I press "Send" - Then I should be on /myprofile/sample-community/profile_members/send_mail + Then I should be on /profile/sample-community/send_mail Scenario: Cancel creation of mailing Given I am logged in as "joaosilva" diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index 8b8da4a..4d01b92 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -53,6 +53,7 @@ profile_admin: - post_content - view_private_content - manage_products + - send_mail_to_members profile_member: id: 6 environment_id: 1 diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index c9072f9..fffb144 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1351,7 +1351,6 @@ class ProfileControllerTest < ActionController::TestCase @controller.stubs(:locale).returns('pt') post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} assert_equal ['Hello', 'We have some news'], [assigns(:mailing).subject, assigns(:mailing).body] - assert_redirected_to :action => 'members' end should 'add the user logged on mailing' do @@ -1362,4 +1361,14 @@ class ProfileControllerTest < ActionController::TestCase assert_equal Profile['profile_moderator_user'], assigns(:mailing).person end + should 'redirect back to right place after mail' do + community = fast_create(Community) + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) + login_as('profile_moderator_user') + @controller.stubs(:locale).returns('pt') + @request.expects(:referer).returns("/profile/#{community.identifier}/members") + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} + assert_redirected_to :action => 'members' + end + end diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index 9fdbb1a..7bcc28a 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -328,33 +328,6 @@ class ProfileMembersControllerTest < ActionController::TestCase assert p_roles, [r] end - should 'add locale on mailing' do - community = fast_create(Community) - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community) - login_as('profile_admin_user') - @controller.stubs(:locale).returns('pt') - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} - assert_equal 'pt', assigns(:mailing).locale - end - - should 'save mailing' do - community = fast_create(Community) - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community) - login_as('profile_admin_user') - @controller.stubs(:locale).returns('pt') - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} - assert_equal ['Hello', 'We have some news'], [assigns(:mailing).subject, assigns(:mailing).body] - assert_redirected_to :action => 'index' - end - - should 'add the user logged on mailing' do - community = fast_create(Community) - admin_user = create_user_with_permission('profile_admin_user', 'manage_memberships', community) - login_as('profile_admin_user') - post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} - assert_equal Profile['profile_admin_user'], assigns(:mailing).person - end - should 'set a community member as admin' do community = fast_create(Community) admin = create_user_with_permission('admin_user', 'manage_memberships', community) -- libgit2 0.21.2