Commit 3cdf7126e9312a27d5b9292707e2f18a1094f7d2
1 parent
80ebad1f
Exists in
web_steps_improvements
and in
9 other branches
adds member selection to organization mailing
Signed-off-by: Gustavo Jaruga <darkshades@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
10 changed files
with
48 additions
and
18 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
@@ -10,10 +10,20 @@ class ProfileMembersController < MyProfileController | @@ -10,10 +10,20 @@ class ProfileMembersController < MyProfileController | ||
10 | 10 | ||
11 | @data[:members] = profile.members_by(field,@filters[:name]).by_role(@filters[:roles]) | 11 | @data[:members] = profile.members_by(field,@filters[:name]).by_role(@filters[:roles]) |
12 | session[:members_filtered] = @data[:members].map{|m|m.id} if request.post? | 12 | session[:members_filtered] = @data[:members].map{|m|m.id} if request.post? |
13 | - @data[:roles] = Profile::Roles.organization_member_roles(environment.id) | 13 | + @data[:roles] = Profile::Roles.organization_member_roles(environment.id) | Profile::Roles.organization_custom_roles(environment.id, profile.id) |
14 | 14 | ||
15 | end | 15 | end |
16 | 16 | ||
17 | + def send_mail | ||
18 | + session[:members_filtered] = params[:members_filtered].select{|value| value!="0"} | ||
19 | + if session[:members_filtered].present? | ||
20 | + redirect_to :controller => :profile, :action => :send_mail | ||
21 | + else | ||
22 | + session[:notice] = _("Select at least one member.") | ||
23 | + redirect_to :action => :index | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
17 | def update_roles | 27 | def update_roles |
18 | @roles = params[:roles] ? environment.roles.find(params[:roles].select{|r|!r.to_i.zero?}) : [] | 28 | @roles = params[:roles] ? environment.roles.find(params[:roles].select{|r|!r.to_i.zero?}) : [] |
19 | @roles = @roles.select{|r| r.has_kind?('Profile') } | 29 | @roles = @roles.select{|r| r.has_kind?('Profile') } |
app/mailers/organization_mailing.rb
@@ -5,13 +5,14 @@ class OrganizationMailing < Mailing | @@ -5,13 +5,14 @@ class OrganizationMailing < Mailing | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def recipients(offset=0, limit=100) | 7 | def recipients(offset=0, limit=100) |
8 | + result = source.members.order(:id).offset(offset).limit(limit) | ||
9 | + | ||
8 | if data.present? and data.is_a?(Hash) and data[:members_filtered] | 10 | if data.present? and data.is_a?(Hash) and data[:members_filtered] |
9 | - result = source.members.where('profiles.id IN (?)', data[:members_filtered]) | 11 | + result = result.where('profiles.id IN (?)', data[:members_filtered]) |
10 | end | 12 | end |
11 | 13 | ||
12 | if result.blank? | 14 | if result.blank? |
13 | - result = source.members.order(:id).offset(offset).limit(limit) | ||
14 | - .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") | 15 | + result = result.joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") |
15 | .where("m.person_id" => nil) | 16 | .where("m.person_id" => nil) |
16 | end | 17 | end |
17 | result | 18 | result |
app/models/profile.rb
@@ -49,6 +49,9 @@ class Profile < ActiveRecord::Base | @@ -49,6 +49,9 @@ class Profile < ActiveRecord::Base | ||
49 | def self.organization_member_roles(env_id) | 49 | def self.organization_member_roles(env_id) |
50 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} | 50 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} |
51 | end | 51 | end |
52 | + def self.organization_custom_roles(env_id, profile_id) | ||
53 | + all_roles(env_id).where('profile_id = ?', profile_id) | ||
54 | + end | ||
52 | def self.all_roles(env_id) | 55 | def self.all_roles(env_id) |
53 | Role.where(environment_id: env_id) | 56 | Role.where(environment_id: env_id) |
54 | end | 57 | end |
app/views/profile_members/_index_buttons.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <%= button :person, _('Invite people to join'), :controller => 'invite', :action => 'invite_friends' %> | 5 | <%= button :person, _('Invite people to join'), :controller => 'invite', :action => 'invite_friends' %> |
6 | <% end %> | 6 | <% end %> |
7 | <% if profile.community? and user.has_permission?(:send_mail_to_members, profile) %> | 7 | <% if profile.community? and user.has_permission?(:send_mail_to_members, profile) %> |
8 | - <%= button :send, _('Send e-mail to members'), :controller => 'profile', :action => 'send_mail' %> | 8 | + <%= submit_button(:send, _('Send e-mail to members')) %> |
9 | <% end %> | 9 | <% end %> |
10 | <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> | 10 | <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> |
11 | <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> | 11 | <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> |
app/views/profile_members/_members_list.html.erb
@@ -2,17 +2,21 @@ | @@ -2,17 +2,21 @@ | ||
2 | <% collection = @collection == :profile_admins ? profile.admins : members %> | 2 | <% collection = @collection == :profile_admins ? profile.admins : members %> |
3 | <% title = @title ? @title : _('Current members') %> | 3 | <% title = @title ? @title : _('Current members') %> |
4 | <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> | 4 | <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> |
5 | +<%= javascript_include_tag params[:controller] %> | ||
5 | 6 | ||
6 | <h3><%= title %></h3> | 7 | <h3><%= title %></h3> |
7 | 8 | ||
8 | <table> | 9 | <table> |
10 | + <col width="1"> | ||
9 | <tr> | 11 | <tr> |
12 | + <th><%= check_box_tag 'checkbox-all', 1, false, :onClick => "toggle(this)" %></th> | ||
10 | <th><%= _('Member') %></th> | 13 | <th><%= _('Member') %></th> |
11 | <th><%= _('Actions') %></th> | 14 | <th><%= _('Actions') %></th> |
12 | </tr> | 15 | </tr> |
13 | 16 | ||
14 | <% collection.each do |m| %> | 17 | <% collection.each do |m| %> |
15 | <tr title="<%= m.name %>"> | 18 | <tr title="<%= m.name %>"> |
19 | + <td><%= labelled_check_box('', 'members_filtered[]', m.id.to_s, false, :id => 'checkbox-'+m.identifier) %></td> | ||
16 | <td><%= link_to_profile m.short_name, m.identifier, :title => m.name %> </td> | 20 | <td><%= link_to_profile m.short_name, m.identifier, :title => m.name %> </td> |
17 | <td> | 21 | <td> |
18 | <div class="members-buttons-cell"> | 22 | <div class="members-buttons-cell"> |
app/views/profile_members/index.html.erb
1 | <h1><%= h profile.short_name(50) %></h1> | 1 | <h1><%= h profile.short_name(50) %></h1> |
2 | 2 | ||
3 | -<%= render :partial => 'index_buttons' %> | ||
4 | - | ||
5 | <%= render :partial => 'members_filter' %> | 3 | <%= render :partial => 'members_filter' %> |
6 | 4 | ||
7 | -<div id="members-list"> | ||
8 | - <%= render :partial => 'members_list' %> | ||
9 | -</div> | 5 | +<%= form_tag 'profile_members/send_mail', :method => 'post' do %> |
6 | + <div id="members-list"> | ||
7 | + <%= render :partial => 'members_list' %> | ||
8 | + </div> | ||
9 | + | ||
10 | + <%= render :partial => 'index_buttons' %> | ||
10 | 11 | ||
11 | -<%= render :partial => 'index_buttons' %> | 12 | +<% end %> |
features/send_email_to_organization_members.feature
@@ -31,7 +31,8 @@ Feature: send emails to organization members | @@ -31,7 +31,8 @@ Feature: send emails to organization members | ||
31 | Scenario: Send e-mail to members | 31 | Scenario: Send e-mail to members |
32 | Given I am logged in as "joaosilva" | 32 | Given I am logged in as "joaosilva" |
33 | And I go to Sample Community's members management | 33 | And I go to Sample Community's members management |
34 | - And I follow "Send e-mail to members" | 34 | + And I check "checkbox-manoel" |
35 | + And I press "Send e-mail to members" | ||
35 | And I fill in "Subject" with "Hello, member!" | 36 | And I fill in "Subject" with "Hello, member!" |
36 | And I fill in "Body" with "We have some news" | 37 | And I fill in "Body" with "We have some news" |
37 | When I press "Send" | 38 | When I press "Send" |
@@ -40,7 +41,8 @@ Feature: send emails to organization members | @@ -40,7 +41,8 @@ Feature: send emails to organization members | ||
40 | Scenario: Not send e-mail to members if subject is blank | 41 | Scenario: Not send e-mail to members if subject is blank |
41 | Given I am logged in as "joaosilva" | 42 | Given I am logged in as "joaosilva" |
42 | And I go to Sample Community's members management | 43 | And I go to Sample Community's members management |
43 | - And I follow "Send e-mail to members" | 44 | + And I check "checkbox-manoel" |
45 | + And I press "Send e-mail to members" | ||
44 | And I fill in "Body" with "We have some news" | 46 | And I fill in "Body" with "We have some news" |
45 | When I press "Send" | 47 | When I press "Send" |
46 | Then I should be on /profile/sample-community/send_mail | 48 | Then I should be on /profile/sample-community/send_mail |
@@ -48,7 +50,8 @@ Feature: send emails to organization members | @@ -48,7 +50,8 @@ Feature: send emails to organization members | ||
48 | Scenario: Not send e-mail to members if body is blank | 50 | Scenario: Not send e-mail to members if body is blank |
49 | Given I am logged in as "joaosilva" | 51 | Given I am logged in as "joaosilva" |
50 | And I go to Sample Community's members management | 52 | And I go to Sample Community's members management |
51 | - And I follow "Send e-mail to members" | 53 | + And I check "checkbox-manoel" |
54 | + And I press "Send e-mail to members" | ||
52 | And I fill in "Subject" with "Hello, user!" | 55 | And I fill in "Subject" with "Hello, user!" |
53 | When I press "Send" | 56 | When I press "Send" |
54 | Then I should be on /profile/sample-community/send_mail | 57 | Then I should be on /profile/sample-community/send_mail |
@@ -56,7 +59,8 @@ Feature: send emails to organization members | @@ -56,7 +59,8 @@ Feature: send emails to organization members | ||
56 | Scenario: Cancel creation of mailing | 59 | Scenario: Cancel creation of mailing |
57 | Given I am logged in as "joaosilva" | 60 | Given I am logged in as "joaosilva" |
58 | And I go to Sample Community's members management | 61 | And I go to Sample Community's members management |
59 | - And I follow "Send e-mail to members" | 62 | + And I check "checkbox-manoel" |
63 | + And I press "Send e-mail to members" | ||
60 | When I follow "Cancel e-mail" | 64 | When I follow "Cancel e-mail" |
61 | Then I should be on Sample Community's members management | 65 | Then I should be on Sample Community's members management |
62 | 66 |
public/javascripts/profile_members.js
@@ -14,5 +14,12 @@ | @@ -14,5 +14,12 @@ | ||
14 | }); | 14 | }); |
15 | } | 15 | } |
16 | }); | 16 | }); |
17 | +})(jQuery); | ||
17 | 18 | ||
18 | -})(jQuery); | ||
19 | \ No newline at end of file | 19 | \ No newline at end of file |
20 | + | ||
21 | +function toggle(source) { | ||
22 | + checkboxes = document.getElementsByName('members_filtered[]'); | ||
23 | + for(var i=0, n=checkboxes.length;i<n;i++) { | ||
24 | + checkboxes[i].checked = source.checked; | ||
25 | + } | ||
26 | +} |
test/functional/profile_controller_test.rb
@@ -1497,7 +1497,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1497,7 +1497,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1497 | 1497 | ||
1498 | @request.session[:members_filtered] = [Profile.last.id+1] | 1498 | @request.session[:members_filtered] = [Profile.last.id+1] |
1499 | post :send_mail, :profile => community.identifier, :mailing => {:subject => 'RUN!!', :body => 'Run to the hills!!'} | 1499 | post :send_mail, :profile => community.identifier, :mailing => {:subject => 'RUN!!', :body => 'Run to the hills!!'} |
1500 | - assert_equivalent community.members, OrganizationMailing.last.recipients | 1500 | + assert_empty OrganizationMailing.last.recipients |
1501 | end | 1501 | end |
1502 | 1502 | ||
1503 | should 'save mailing' do | 1503 | should 'save mailing' do |
test/functional/profile_members_controller_test.rb
@@ -196,7 +196,7 @@ class ProfileMembersControllerTest < ActionController::TestCase | @@ -196,7 +196,7 @@ class ProfileMembersControllerTest < ActionController::TestCase | ||
196 | login_as :test_user | 196 | login_as :test_user |
197 | 197 | ||
198 | get :index, :profile => community.identifier | 198 | get :index, :profile => community.identifier |
199 | - assert_tag :tag => 'a', :attributes => {:href => /send_mail/} | 199 | + assert_tag :tag => 'input', :attributes => {:value => 'Send e-mail to members'} |
200 | end | 200 | end |
201 | 201 | ||
202 | should 'not display send email to members if doesn\'t have the permission' do | 202 | should 'not display send email to members if doesn\'t have the permission' do |