diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index a1abff7..370bd07 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -10,10 +10,20 @@ class ProfileMembersController < MyProfileController @data[:members] = profile.members_by(field,@filters[:name]).by_role(@filters[:roles]) session[:members_filtered] = @data[:members].map{|m|m.id} if request.post? - @data[:roles] = Profile::Roles.organization_member_roles(environment.id) + @data[:roles] = Profile::Roles.organization_member_roles(environment.id) | Profile::Roles.organization_custom_roles(environment.id, profile.id) end + def send_mail + session[:members_filtered] = params[:members_filtered].select{|value| value!="0"} + if session[:members_filtered].present? + redirect_to :controller => :profile, :action => :send_mail + else + session[:notice] = _("Select at least one member.") + redirect_to :action => :index + end + end + def update_roles @roles = params[:roles] ? environment.roles.find(params[:roles].select{|r|!r.to_i.zero?}) : [] @roles = @roles.select{|r| r.has_kind?('Profile') } diff --git a/app/mailers/organization_mailing.rb b/app/mailers/organization_mailing.rb index 9e45813..a9fd5cc 100644 --- a/app/mailers/organization_mailing.rb +++ b/app/mailers/organization_mailing.rb @@ -5,13 +5,14 @@ class OrganizationMailing < Mailing end def recipients(offset=0, limit=100) + result = source.members.order(:id).offset(offset).limit(limit) + if data.present? and data.is_a?(Hash) and data[:members_filtered] - result = source.members.where('profiles.id IN (?)', data[:members_filtered]) + result = result.where('profiles.id IN (?)', data[:members_filtered]) end if result.blank? - result = source.members.order(:id).offset(offset).limit(limit) - .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") + result = result.joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") .where("m.person_id" => nil) end result diff --git a/app/models/profile.rb b/app/models/profile.rb index 51364a7..23ec42d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -49,6 +49,9 @@ class Profile < ActiveRecord::Base def self.organization_member_roles(env_id) all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} end + def self.organization_custom_roles(env_id, profile_id) + all_roles(env_id).where('profile_id = ?', profile_id) + end def self.all_roles(env_id) Role.where(environment_id: env_id) end diff --git a/app/views/profile_members/_index_buttons.html.erb b/app/views/profile_members/_index_buttons.html.erb index 480e4f1..49ce882 100644 --- a/app/views/profile_members/_index_buttons.html.erb +++ b/app/views/profile_members/_index_buttons.html.erb @@ -5,7 +5,7 @@ <%= button :person, _('Invite people to join'), :controller => 'invite', :action => 'invite_friends' %> <% end %> <% if profile.community? and user.has_permission?(:send_mail_to_members, profile) %> - <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %> + <%= submit_button(:send, _('Send e-mail to members')) %> <% end %> <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> diff --git a/app/views/profile_members/_members_list.html.erb b/app/views/profile_members/_members_list.html.erb index 2c92a87..f9da6ae 100644 --- a/app/views/profile_members/_members_list.html.erb +++ b/app/views/profile_members/_members_list.html.erb @@ -2,17 +2,21 @@ <% collection = @collection == :profile_admins ? profile.admins : members %> <% title = @title ? @title : _('Current members') %> <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> +<%= javascript_include_tag params[:controller] %>

<%= title %>

+ + <% collection.each do |m| %> +
<%= check_box_tag 'checkbox-all', 1, false, :onClick => "toggle(this)" %> <%= _('Member') %> <%= _('Actions') %>
<%= labelled_check_box('', 'members_filtered[]', m.id.to_s, false, :id => 'checkbox-'+m.identifier) %> <%= link_to_profile m.short_name, m.identifier, :title => m.name %>
diff --git a/app/views/profile_members/index.html.erb b/app/views/profile_members/index.html.erb index bfc2f0e..7f9467b 100644 --- a/app/views/profile_members/index.html.erb +++ b/app/views/profile_members/index.html.erb @@ -1,11 +1,12 @@

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

-<%= render :partial => 'index_buttons' %> - <%= render :partial => 'members_filter' %> -
- <%= render :partial => 'members_list' %> -
+<%= form_tag 'profile_members/send_mail', :method => 'post' do %> +
+ <%= render :partial => 'members_list' %> +
+ + <%= render :partial => 'index_buttons' %> -<%= render :partial => 'index_buttons' %> +<% end %> diff --git a/features/send_email_to_organization_members.feature b/features/send_email_to_organization_members.feature index 98762d5..d89346c 100644 --- a/features/send_email_to_organization_members.feature +++ b/features/send_email_to_organization_members.feature @@ -31,7 +31,8 @@ Feature: send emails to organization members Scenario: Send e-mail to members Given I am logged in as "joaosilva" And I go to Sample Community's members management - And I follow "Send e-mail to members" + And I check "checkbox-manoel" + And I press "Send e-mail to members" And I fill in "Subject" with "Hello, member!" And I fill in "Body" with "We have some news" When I press "Send" @@ -40,7 +41,8 @@ Feature: send emails to organization members Scenario: Not send e-mail to members if subject is blank Given I am logged in as "joaosilva" And I go to Sample Community's members management - And I follow "Send e-mail to members" + And I check "checkbox-manoel" + And I press "Send e-mail to members" And I fill in "Body" with "We have some news" When I press "Send" Then I should be on /profile/sample-community/send_mail @@ -48,7 +50,8 @@ Feature: send emails to organization members Scenario: Not send e-mail to members if body is blank Given I am logged in as "joaosilva" And I go to Sample Community's members management - And I follow "Send e-mail to members" + And I check "checkbox-manoel" + And I press "Send e-mail to members" And I fill in "Subject" with "Hello, user!" When I press "Send" Then I should be on /profile/sample-community/send_mail @@ -56,7 +59,8 @@ Feature: send emails to organization members Scenario: Cancel creation of mailing Given I am logged in as "joaosilva" And I go to Sample Community's members management - And I follow "Send e-mail to members" + And I check "checkbox-manoel" + And I press "Send e-mail to members" When I follow "Cancel e-mail" Then I should be on Sample Community's members management diff --git a/public/javascripts/profile_members.js b/public/javascripts/profile_members.js index eef0105..798a3d5 100644 --- a/public/javascripts/profile_members.js +++ b/public/javascripts/profile_members.js @@ -14,5 +14,12 @@ }); } }); +})(jQuery); -})(jQuery); \ No newline at end of file + +function toggle(source) { + checkboxes = document.getElementsByName('members_filtered[]'); + for(var i=0, n=checkboxes.length;i community.identifier, :mailing => {:subject => 'RUN!!', :body => 'Run to the hills!!'} - assert_equivalent community.members, OrganizationMailing.last.recipients + assert_empty OrganizationMailing.last.recipients end should 'save mailing' do diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index 332a551..3332325 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -196,7 +196,7 @@ class ProfileMembersControllerTest < ActionController::TestCase login_as :test_user get :index, :profile => community.identifier - assert_tag :tag => 'a', :attributes => {:href => /send_mail/} + assert_tag :tag => 'input', :attributes => {:value => 'Send e-mail to members'} end should 'not display send email to members if doesn\'t have the permission' do -- libgit2 0.21.2