Commit 70ccb75cd5f2506f9617c991ee8ff62f28a76836
1 parent
f1e0dc83
Exists in
master
and in
28 other branches
Send e-Mail feature to all members of a community
Only users with send_mail_of_members permission is allowed to send mails (ActionItem2388)
Showing
9 changed files
with
123 additions
and
4 deletions
Show diff stats
app/controllers/public/profile_controller.rb
@@ -2,11 +2,13 @@ class ProfileController < PublicController | @@ -2,11 +2,13 @@ class ProfileController < PublicController | ||
2 | 2 | ||
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] | 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] |
7 | 7 | ||
8 | helper TagsHelper | 8 | helper TagsHelper |
9 | 9 | ||
10 | + protect 'send_mail_to_members', :profile, :only => [:send_mail] | ||
11 | + | ||
10 | def index | 12 | def index |
11 | @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) : [] | 13 | @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) : [] |
12 | if logged_in? && current_person.follows?(@profile) | 14 | if logged_in? && current_person.follows?(@profile) |
@@ -327,6 +329,20 @@ class ProfileController < PublicController | @@ -327,6 +329,20 @@ class ProfileController < PublicController | ||
327 | end | 329 | end |
328 | end | 330 | end |
329 | 331 | ||
332 | + def send_mail | ||
333 | + @mailing = profile.mailings.build(params[:mailing]) | ||
334 | + if request.post? | ||
335 | + @mailing.locale = locale | ||
336 | + @mailing.person = user | ||
337 | + if @mailing.save | ||
338 | + session[:notice] = _('The e-mails are being sent') | ||
339 | + redirect_to_previous_location | ||
340 | + else | ||
341 | + session[:notice] = _('Could not create the e-mail') | ||
342 | + end | ||
343 | + end | ||
344 | + end | ||
345 | + | ||
330 | protected | 346 | protected |
331 | 347 | ||
332 | def check_access_to_profile | 348 | def check_access_to_profile |
app/models/profile.rb
@@ -57,6 +57,7 @@ class Profile < ActiveRecord::Base | @@ -57,6 +57,7 @@ class Profile < ActiveRecord::Base | ||
57 | 'view_private_content' => N_('View private content'), | 57 | 'view_private_content' => N_('View private content'), |
58 | 'publish_content' => N_('Publish content'), | 58 | 'publish_content' => N_('Publish content'), |
59 | 'invite_members' => N_('Invite members'), | 59 | 'invite_members' => N_('Invite members'), |
60 | + 'send_mail_to_members' => N_('Send e-Mail to members'), | ||
60 | } | 61 | } |
61 | 62 | ||
62 | acts_as_accessible | 63 | acts_as_accessible |
app/views/profile/members.rhtml
@@ -16,8 +16,13 @@ | @@ -16,8 +16,13 @@ | ||
16 | 16 | ||
17 | <% button_bar do %> | 17 | <% button_bar do %> |
18 | <%= button :back, _('Go back'), { :controller => 'profile' } %> | 18 | <%= button :back, _('Go back'), { :controller => 'profile' } %> |
19 | - <% if profile.community? and user and user.has_permission?(:invite_members, profile) %> | ||
20 | - <%= button :search, _('Invite your friends to join %s') % profile.name, :controller => 'invite', :action => 'select_address_book' %> | 19 | + <% if profile.community? and user %> |
20 | + <% if user.has_permission?(:invite_members, profile) %> | ||
21 | + <%= button :search, _('Invite your friends to join %s') % profile.name, :controller => 'invite', :action => 'select_address_book' %> | ||
22 | + <% end %> | ||
23 | + <% if user.has_permission?(:send_mail_to_members, profile) %> | ||
24 | + <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %> | ||
25 | + <% end %> | ||
21 | <% end %> | 26 | <% end %> |
22 | <% end %> | 27 | <% end %> |
23 | 28 |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
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 => 'members' %> | ||
14 | +<% end %> |
features/send_email_to_organization_members.feature
1 | Feature: send emails to organization members | 1 | Feature: send emails to organization members |
2 | - As a organization administrator | 2 | + As a organization administrator or moderator |
3 | I want to send email to all members | 3 | I want to send email to all members |
4 | 4 | ||
5 | Background: | 5 | Background: |
6 | Given the following users | 6 | Given the following users |
7 | | login | name | | 7 | | login | name | |
8 | | joaosilva | Joao Silva | | 8 | | joaosilva | Joao Silva | |
9 | + | jose | Jose Silva | | ||
10 | + | manoel | Manoel Silva | | ||
9 | And the following communities | 11 | And the following communities |
10 | | identifier | name | | 12 | | identifier | name | |
11 | | sample-community | Sample Community | | 13 | | sample-community | Sample Community | |
12 | And "Joao Silva" is admin of "Sample Community" | 14 | And "Joao Silva" is admin of "Sample Community" |
15 | + And "Jose Silva" is moderator of "Sample Community" | ||
16 | + And "Manoel Silva" is a member of "Sample Community" | ||
13 | 17 | ||
14 | Scenario: Cant access if not logged in | 18 | Scenario: Cant access if not logged in |
15 | Given I am not logged in | 19 | Given I am not logged in |
@@ -55,3 +59,34 @@ Feature: send emails to organization members | @@ -55,3 +59,34 @@ Feature: send emails to organization members | ||
55 | And I follow "Send e-mail to members" | 59 | And I follow "Send e-mail to members" |
56 | When I follow "Cancel e-mail" | 60 | When I follow "Cancel e-mail" |
57 | Then I should be on Sample Community's members management | 61 | Then I should be on Sample Community's members management |
62 | + | ||
63 | + Scenario: Cant access if has no send_mail_to_members permission | ||
64 | + Given I am logged in as "manoel" | ||
65 | + When I go to /profile/sample-community/send_mail | ||
66 | + Then I should see "Access denied" | ||
67 | + | ||
68 | + Scenario: Show button "Send e-Mail to members" of community to an moderator | ||
69 | + Given I am logged in as "jose" | ||
70 | + When I go to Sample Community's members page | ||
71 | + Then I should see "Send e-mail to members" link | ||
72 | + | ||
73 | + Scenario: Not show button "Send e-Mail to members" if user has no right permission | ||
74 | + Given I am logged in as "manoel" | ||
75 | + When I go to Sample Community's members page | ||
76 | + Then I should not see "Send e-mail to members" link | ||
77 | + | ||
78 | + Scenario: Redirect back to profile members page after send mail | ||
79 | + Given I am logged in as "jose" | ||
80 | + When I go to Sample Community's members page | ||
81 | + And I follow "Send e-mail to members" | ||
82 | + And I fill in "Subject" with "Hello, member!" | ||
83 | + And I fill in "body" with "We have some news" | ||
84 | + When I press "Send" | ||
85 | + Then I should be on Sample Community's members page | ||
86 | + | ||
87 | + Scenario: Back to profile members page after cancel creation of mailing | ||
88 | + Given I am logged in as "jose" | ||
89 | + And I go to Sample Community's members page | ||
90 | + And I follow "Send e-mail to members" | ||
91 | + When I follow "Cancel e-mail" | ||
92 | + Then I should be on Sample Community's members page |
features/step_definitions/noosfero_steps.rb
@@ -355,6 +355,12 @@ Given /^"(.+)" is admin of "(.+)"$/ do |person, organization| | @@ -355,6 +355,12 @@ Given /^"(.+)" is admin of "(.+)"$/ do |person, organization| | ||
355 | org.add_admin(user) | 355 | org.add_admin(user) |
356 | end | 356 | end |
357 | 357 | ||
358 | +Given /^"(.+)" is moderator of "(.+)"$/ do |person, organization| | ||
359 | + org = Profile.find_by_name(organization) | ||
360 | + user = Profile.find_by_name(person) | ||
361 | + org.add_moderator(user) | ||
362 | +end | ||
363 | + | ||
358 | Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization| | 364 | Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization| |
359 | org = Organization.find_by_name(organization) | 365 | org = Organization.find_by_name(organization) |
360 | user = Person.find_by_name(person) | 366 | user = Person.find_by_name(person) |
features/support/paths.rb
@@ -108,6 +108,9 @@ module NavigationHelpers | @@ -108,6 +108,9 @@ module NavigationHelpers | ||
108 | when /the user data path/ | 108 | when /the user data path/ |
109 | '/account/user_data' | 109 | '/account/user_data' |
110 | 110 | ||
111 | + when /^(.+)'s members page/ | ||
112 | + '/profile/%s/members' % Profile.find_by_name($1).identifier | ||
113 | + | ||
111 | # Add more mappings here. | 114 | # Add more mappings here. |
112 | # Here is a more fancy example: | 115 | # Here is a more fancy example: |
113 | # | 116 | # |
test/fixtures/roles.yml
@@ -70,6 +70,7 @@ profile_moderator: | @@ -70,6 +70,7 @@ profile_moderator: | ||
70 | permissions: | 70 | permissions: |
71 | - moderate_comments | 71 | - moderate_comments |
72 | - view_private_content | 72 | - view_private_content |
73 | + - send_mail_to_members | ||
73 | environment_administrator: | 74 | environment_administrator: |
74 | id: 8 | 75 | id: 8 |
75 | environment_id: 1 | 76 | environment_id: 1 |
test/functional/profile_controller_test.rb
@@ -1324,4 +1324,42 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1324,4 +1324,42 @@ class ProfileControllerTest < ActionController::TestCase | ||
1324 | 1324 | ||
1325 | assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} | 1325 | assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} |
1326 | end | 1326 | end |
1327 | + | ||
1328 | + should 'add locale on mailing' do | ||
1329 | + community = fast_create(Community) | ||
1330 | + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | ||
1331 | + login_as('profile_moderator_user') | ||
1332 | + @controller.stubs(:locale).returns('pt') | ||
1333 | + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} | ||
1334 | + assert_equal 'pt', assigns(:mailing).locale | ||
1335 | + end | ||
1336 | + | ||
1337 | + should 'queue mailing to process later' do | ||
1338 | + community = fast_create(Community) | ||
1339 | + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | ||
1340 | + login_as('profile_moderator_user') | ||
1341 | + @controller.stubs(:locale).returns('pt') | ||
1342 | + assert_difference Delayed::Job, :count, 1 do | ||
1343 | + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} | ||
1344 | + end | ||
1345 | + end | ||
1346 | + | ||
1347 | + should 'save mailing' do | ||
1348 | + community = fast_create(Community) | ||
1349 | + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | ||
1350 | + login_as('profile_moderator_user') | ||
1351 | + @controller.stubs(:locale).returns('pt') | ||
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] | ||
1354 | + assert_redirected_to :action => 'members' | ||
1355 | + end | ||
1356 | + | ||
1357 | + should 'add the user logged on mailing' do | ||
1358 | + community = fast_create(Community) | ||
1359 | + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | ||
1360 | + login_as('profile_moderator_user') | ||
1361 | + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} | ||
1362 | + assert_equal Profile['profile_moderator_user'], assigns(:mailing).person | ||
1363 | + end | ||
1364 | + | ||
1327 | end | 1365 | end |