From 3331bbc7585e87d11ca2f6bd029b968d6df0989e Mon Sep 17 00:00:00 2001 From: Carlos Purificacao Date: Wed, 1 Jul 2015 16:28:48 -0300 Subject: [PATCH] Implemented the administrator task notification option --- app/models/profile.rb | 3 ++- app/models/task.rb | 17 ++++++++++++++++- app/views/profile_editor/_moderation.html.erb | 10 ++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 7c5a0e9..2c474f7 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,7 +3,7 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :administrator_mail_notification # use for internationalizable human type names in search facets # reimplement on subclasses @@ -178,6 +178,7 @@ class Profile < ActiveRecord::Base settings_items :description settings_items :fields_privacy, :type => :hash, :default => {} settings_items :email_suggestions, :type => :boolean, :default => false + settings_items :administrator_mail_notification, :type => :boolean, :default => true validates_length_of :description, :maximum => 550, :allow_nil => true diff --git a/app/models/task.rb b/app/models/task.rb index 927031d..8ec4b33 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -57,6 +57,7 @@ class Task < ActiveRecord::Base end after_create do |task| + binding.pry unless task.status == Task::Status::HIDDEN begin task.send(:send_notification, :created) @@ -67,7 +68,9 @@ class Task < ActiveRecord::Base begin target_msg = task.target_notification_message if target_msg && task.target && !task.target.notification_emails.empty? - TaskMailer.target_notification(task, target_msg).deliver + if target_profile_accepts_notification?(task) + TaskMailer.target_notification(task, target_msg).deliver + end end rescue NotImplementedError => ex Rails.logger.info ex.to_s @@ -75,6 +78,18 @@ class Task < ActiveRecord::Base end end + def target_profile_accepts_notification?(task) + if target_is_profile?(task) + return task.target.administrator_mail_notification + else + true + end + end + + def target_is_profile?(task) + task.target.kind_of? Profile + end + # this method finished the task. It calls #perform, which must be overriden # by subclasses. At the end a message (as returned by #finish_message) is # sent to the requestor with #notify_requestor. diff --git a/app/views/profile_editor/_moderation.html.erb b/app/views/profile_editor/_moderation.html.erb index 749c653..989cbbd 100644 --- a/app/views/profile_editor/_moderation.html.erb +++ b/app/views/profile_editor/_moderation.html.erb @@ -1,6 +1,16 @@

<%= _('Moderation options') %>

<% if profile.community? %>
+

<%= _('Email Configuration:')%>

+
+
+ <%= check_box(:profile_data, :administrator_mail_notification, :style => 'float: left') %> +
+ <%= _('Send administrator Email for every task (Default: yes)') %> +
+
+ +

<%= _('Invitation moderation:')%>

-- libgit2 0.21.2