Commit 76d1fba0d73a77718a3a2814b1099c0154318734
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/241' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/241
Showing
14 changed files
with
162 additions
and
65 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
| ... | ... | @@ -156,18 +156,4 @@ class ProfileMembersController < MyProfileController |
| 156 | 156 | end |
| 157 | 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 | 159 | end | ... | ... |
app/controllers/public/profile_controller.rb
| ... | ... | @@ -2,11 +2,13 @@ class ProfileController < PublicController |
| 2 | 2 | |
| 3 | 3 | needs_profile |
| 4 | 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] | |
| 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] | |
| 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, :send_mail] | |
| 7 | 7 | |
| 8 | 8 | helper TagsHelper |
| 9 | 9 | |
| 10 | + protect 'send_mail_to_members', :profile, :only => [:send_mail] | |
| 11 | + | |
| 10 | 12 | def index |
| 11 | 13 | @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) : [] |
| 12 | 14 | if logged_in? && current_person.follows?(@profile) |
| ... | ... | @@ -327,6 +329,20 @@ class ProfileController < PublicController |
| 327 | 329 | end |
| 328 | 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 | 346 | protected |
| 331 | 347 | |
| 332 | 348 | def check_access_to_profile | ... | ... |
app/models/profile.rb
| ... | ... | @@ -57,6 +57,7 @@ class Profile < ActiveRecord::Base |
| 57 | 57 | 'view_private_content' => N_('View private content'), |
| 58 | 58 | 'publish_content' => N_('Publish content'), |
| 59 | 59 | 'invite_members' => N_('Invite members'), |
| 60 | + 'send_mail_to_members' => N_('Send e-Mail to members'), | |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | acts_as_accessible | ... | ... |
app/views/profile/members.rhtml
| ... | ... | @@ -16,8 +16,13 @@ |
| 16 | 16 | |
| 17 | 17 | <% button_bar do %> |
| 18 | 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 | 26 | <% end %> |
| 22 | 27 | <% end %> |
| 23 | 28 | ... | ... |
| ... | ... | @@ -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'), :back %> | |
| 14 | +<% end %> | ... | ... |
app/views/profile_members/_index_buttons.rhtml
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | <% if profile.community? and user.has_permission?(:invite_members, profile) %> |
| 5 | 5 | <%= button :search, _('Invite your friends to join %s') % profile.short_name, :controller => 'invite', :action => 'select_address_book' %> |
| 6 | 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 | 8 | <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> |
| 9 | 9 | <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> |
| 10 | 10 | <% end %> | ... | ... |
app/views/profile_members/send_mail.rhtml
| ... | ... | @@ -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 %> |
db/migrate/20120824165019_add_permission_for_send_mail_to_members_to_admin_and_moderator_roles.rb
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +class AddPermissionForSendMailToMembersToAdminAndModeratorRoles < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + Environment.all.map(&:id).each do |id| | |
| 4 | + role = Profile::Roles.admin(id) | |
| 5 | + role.permissions += ['send_mail_to_members'] | |
| 6 | + role.save! | |
| 7 | + role = Profile::Roles.moderator(id) | |
| 8 | + role.permissions += ['send_mail_to_members'] | |
| 9 | + role.save! | |
| 10 | + end | |
| 11 | + end | |
| 12 | + | |
| 13 | + def self.down | |
| 14 | + Environment.all.map(&:id).each do |id| | |
| 15 | + role = Profile::Roles.admin(id) | |
| 16 | + role.permissions -= ['send_mail_to_members'] | |
| 17 | + role.save! | |
| 18 | + role = Profile::Roles.moderator(id) | |
| 19 | + role.permissions -= ['send_mail_to_members'] | |
| 20 | + role.save! | |
| 21 | + end | |
| 22 | + end | |
| 23 | +end | ... | ... |
features/send_email_to_organization_members.feature
| 1 | 1 | Feature: send emails to organization members |
| 2 | - As a organization administrator | |
| 2 | + As a organization administrator or moderator | |
| 3 | 3 | I want to send email to all members |
| 4 | 4 | |
| 5 | 5 | Background: |
| 6 | 6 | Given the following users |
| 7 | 7 | | login | name | |
| 8 | 8 | | joaosilva | Joao Silva | |
| 9 | + | jose | Jose Silva | | |
| 10 | + | manoel | Manoel Silva | | |
| 9 | 11 | And the following communities |
| 10 | 12 | | identifier | name | |
| 11 | 13 | | sample-community | Sample Community | |
| 12 | 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 | 18 | Scenario: Cant access if not logged in |
| 15 | 19 | Given I am not logged in |
| 16 | - When I go to /myprofile/sample-community/profile_members/send_mail | |
| 20 | + When I go to /profile/sample-community/send_mail | |
| 17 | 21 | Then I should be on login page |
| 18 | 22 | |
| 19 | 23 | Scenario: Cant access as normal user |
| ... | ... | @@ -21,7 +25,7 @@ Feature: send emails to organization members |
| 21 | 25 | | login | |
| 22 | 26 | | josesilva | |
| 23 | 27 | And I am logged in as "josesilva" |
| 24 | - When I go to /myprofile/sample-community/profile_members/send_mail | |
| 28 | + When I go to /profile/sample-community/send_mail | |
| 25 | 29 | Then I should see "Access denied" |
| 26 | 30 | |
| 27 | 31 | Scenario: Send e-mail to members |
| ... | ... | @@ -39,7 +43,7 @@ Feature: send emails to organization members |
| 39 | 43 | And I follow "Send e-mail to members" |
| 40 | 44 | And I fill in "body" with "We have some news" |
| 41 | 45 | When I press "Send" |
| 42 | - Then I should be on /myprofile/sample-community/profile_members/send_mail | |
| 46 | + Then I should be on /profile/sample-community/send_mail | |
| 43 | 47 | |
| 44 | 48 | Scenario: Not send e-mail to members if body is blank |
| 45 | 49 | Given I am logged in as "joaosilva" |
| ... | ... | @@ -47,7 +51,7 @@ Feature: send emails to organization members |
| 47 | 51 | And I follow "Send e-mail to members" |
| 48 | 52 | And I fill in "Subject" with "Hello, user!" |
| 49 | 53 | When I press "Send" |
| 50 | - Then I should be on /myprofile/sample-community/profile_members/send_mail | |
| 54 | + Then I should be on /profile/sample-community/send_mail | |
| 51 | 55 | |
| 52 | 56 | Scenario: Cancel creation of mailing |
| 53 | 57 | Given I am logged in as "joaosilva" |
| ... | ... | @@ -55,3 +59,34 @@ Feature: send emails to organization members |
| 55 | 59 | And I follow "Send e-mail to members" |
| 56 | 60 | When I follow "Cancel e-mail" |
| 57 | 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 | 355 | org.add_admin(user) |
| 356 | 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 | 364 | Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization| |
| 359 | 365 | org = Organization.find_by_name(organization) |
| 360 | 366 | user = Person.find_by_name(person) | ... | ... |
features/support/paths.rb
| ... | ... | @@ -108,6 +108,9 @@ module NavigationHelpers |
| 108 | 108 | when /the user data path/ |
| 109 | 109 | '/account/user_data' |
| 110 | 110 | |
| 111 | + when /^(.+)'s members page/ | |
| 112 | + '/profile/%s/members' % Profile.find_by_name($1).identifier | |
| 113 | + | |
| 111 | 114 | # Add more mappings here. |
| 112 | 115 | # Here is a more fancy example: |
| 113 | 116 | # | ... | ... |
test/fixtures/roles.yml
| ... | ... | @@ -53,6 +53,7 @@ profile_admin: |
| 53 | 53 | - post_content |
| 54 | 54 | - view_private_content |
| 55 | 55 | - manage_products |
| 56 | + - send_mail_to_members | |
| 56 | 57 | profile_member: |
| 57 | 58 | id: 6 |
| 58 | 59 | environment_id: 1 |
| ... | ... | @@ -70,6 +71,7 @@ profile_moderator: |
| 70 | 71 | permissions: |
| 71 | 72 | - moderate_comments |
| 72 | 73 | - view_private_content |
| 74 | + - send_mail_to_members | |
| 73 | 75 | environment_administrator: |
| 74 | 76 | id: 8 |
| 75 | 77 | environment_id: 1 | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -1324,4 +1324,51 @@ class ProfileControllerTest < ActionController::TestCase |
| 1324 | 1324 | |
| 1325 | 1325 | assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} |
| 1326 | 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 | + end | |
| 1355 | + | |
| 1356 | + should 'add the user logged on mailing' do | |
| 1357 | + community = fast_create(Community) | |
| 1358 | + create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community) | |
| 1359 | + login_as('profile_moderator_user') | |
| 1360 | + post :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'} | |
| 1361 | + assert_equal Profile['profile_moderator_user'], assigns(:mailing).person | |
| 1362 | + end | |
| 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 | + | |
| 1327 | 1374 | end | ... | ... |
test/functional/profile_members_controller_test.rb
| ... | ... | @@ -328,33 +328,6 @@ class ProfileMembersControllerTest < ActionController::TestCase |
| 328 | 328 | assert p_roles, [r] |
| 329 | 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 | 331 | should 'set a community member as admin' do |
| 359 | 332 | community = fast_create(Community) |
| 360 | 333 | admin = create_user_with_permission('admin_user', 'manage_memberships', community) | ... | ... |