diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 0e212c5..0dbf0cf 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -353,7 +353,7 @@ class ProfileController < PublicController def send_mail @mailing = profile.mailings.build(params[:mailing]) - @email_templates = profile.email_templates + @email_templates = profile.email_templates.find_all_by_template_type(:organization_members) if request.post? @mailing.locale = locale @mailing.person = user diff --git a/app/models/email_template.rb b/app/models/email_template.rb index 0b3e42b..e1ffe80 100644 --- a/app/models/email_template.rb +++ b/app/models/email_template.rb @@ -14,6 +14,13 @@ class EmailTemplate < ActiveRecord::Base @parsed_subject ||= parse(subject, params) end + def available_types + HashWithIndifferentAccess.new ({ + :task_rejection => {:description => _('Task Rejection')}, + :organization_members => {:description => _('Organization Members')} + }) + end + protected def parse(source, params) diff --git a/app/views/email_templates/_form.html.erb b/app/views/email_templates/_form.html.erb index 72f5ed9..4de3081 100644 --- a/app/views/email_templates/_form.html.erb +++ b/app/views/email_templates/_form.html.erb @@ -5,6 +5,7 @@
<%= _('Name') %> | +<%= _('Type') %> | |
---|---|---|
<%= email_template.name %> | +<%= email_template.available_types[email_template.template_type][:description] if email_template.template_type.present? %> |
<%= link_to 'Edit', url_for(:controller => :email_templates, :action => :edit, :id => email_template.id) %>
<%= link_to 'Destroy', url_for(:controller => :email_templates, :action => :destroy, :id => email_template.id), method: :delete, data: { confirm: 'Are you sure?' } %>
diff --git a/app/views/profile/send_mail.html.erb b/app/views/profile/send_mail.html.erb
index b206210..cd2c197 100644
--- a/app/views/profile/send_mail.html.erb
+++ b/app/views/profile/send_mail.html.erb
@@ -4,11 +4,11 @@
<%= error_messages_for :mailing %>
-
- <% if @email_templates.present? %>
+<% if @email_templates.present? %>
+
+<% end %>
<%= form_for :mailing, :url => {:action => 'send_mail'}, :html => {:id => 'mailing-form'} do |f| %>
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 5f4a779..9d9f509 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -1471,6 +1471,29 @@ class ProfileControllerTest < ActionController::TestCase
assert_redirected_to :action => 'members'
end
+ should 'display email templates as an option to send mail' do
+ community = fast_create(Community)
+ create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community)
+ login_as('profile_moderator_user')
+
+ template1 = EmailTemplate.create!(:owner => community, :name => "Template 1", :template_type => :organization_members)
+ template2 = EmailTemplate.create!(:owner => community, :name => "Template 2")
+
+ get :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}
+ assert_select '.template-selection'
+ assert_equal [template1], assigns(:email_templates)
+ end
+
+ should 'do not display email template selection when there is no template for organization members' do
+ community = fast_create(Community)
+ create_user_with_permission('profile_moderator_user', 'send_mail_to_members', community)
+ login_as('profile_moderator_user')
+
+ get :send_mail, :profile => community.identifier, :mailing => {:subject => 'Hello', :body => 'We have some news'}
+ assert_select '.template-selection', 0
+ assert assigns(:email_templates).empty?
+ end
+
should 'show all fields to anonymous user' do
viewed = create_user('person_1').person
Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
--
libgit2 0.21.2
<%= labelled_form_field(_('Select a template:'), select_tag(:template, options_from_collection_for_select(@email_templates, :id, :name), :include_blank => true, 'data-url' => url_for(:controller => 'email_templates', :action => 'show_parsed'))) %>
- <% end %>
-
+ |