diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index af02d409c..99f13be95 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -30,7 +30,10 @@ class IssuesController < ApplicationController @issue = Issue.new(params[:issue]) @issue.user_id = @user_id @issue.project_id = @project.id + if @issue.save + @issue.subscribe_creator(current_user.id) + flash[:notice] = I18n.t("flash.issue.saved") redirect_to project_issues_path(@project) else diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 9be195dd4..39ceffa17 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -18,6 +18,14 @@ class UserMailer < ActionMailer::Base end end + def new_comment_reply_notification(comment, user) + @user = user + @comment = comment + mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_comment_reply_notification")) do |format| + format.html + end + end + def new_issue_notification(issue, user) @user = user @issue = issue diff --git a/app/models/comment.rb b/app/models/comment.rb index 1f8d3b779..41ba6602e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -4,6 +4,7 @@ class Comment < ActiveRecord::Base validates :body, :user_id, :commentable_id, :commentable_type, :presence => true + after_create :subscribe_on_reply after_create :deliver_new_comment_notification protected @@ -12,7 +13,17 @@ class Comment < ActiveRecord::Base subscribes = self.commentable.subscribes subscribes.each do |subscribe| recipient = subscribe.user - UserMailer.delay.new_comment_notification(self, recipient) unless self.user_id == subscribe.user_id + if self.user_id != subscribe.user_id && User.find(recipient).notifier.new_comment_reply && User.find(recipient).notifier.can_notify + if self.commentable.comments.exists?(:user_id => recipient.id) + UserMailer.delay.new_comment_reply_notification(self, recipient) + else + UserMailer.delay.new_comment_notification(self, recipient) + end + end end end + + def subscribe_on_reply + self.commentable.subscribes.create(:user_id => self.user_id) if !self.commentable.subscribes.exists?(:user_id => self.user_id) + end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 5bdde0246..d7a16af35 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -26,6 +26,12 @@ class Issue < ActiveRecord::Base serial_id.to_s end + def subscribe_creator(creator_id) + if !self.subscribes.exists?(:user_id => creator_id) + self.subscribes.create(:user_id => creator_id) + end + end + protected def set_serial_id @@ -37,12 +43,12 @@ class Issue < ActiveRecord::Base recipients = collect_recipient_ids recipients.each do |recipient_id| recipient = User.find(recipient_id) - UserMailer.delay.new_issue_notification(self, recipient)#.deliver + UserMailer.delay.new_issue_notification(self, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue end end def deliver_issue_assign_notification - UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign + UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign && self.user.notifier.can_notify end def subscribe_users @@ -60,7 +66,7 @@ class Issue < ActiveRecord::Base # filter by notification settings recipients = recipients.select do |recipient| - User.find(recipient).notifier.new_issue + User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify end recipients @@ -68,9 +74,9 @@ class Issue < ActiveRecord::Base def subscribe_issue_assigned_user if self.user_id_was != self.user_id - self.subscribes.where(:user_id => self.user_id_was).first.destroy + self.subscribes.where(:user_id => self.user_id_was).first.destroy unless self.user_id_was.blank? if self.user.notifier.issue_assign && !self.subscribes.exists?(:user_id => self.user_id) - self.subscribes.create(:user_id => self.user_id) + self.subscribes.create(:user_id => self.user_id) end end end diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index ea6a25a13..9f1c6306d 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -19,4 +19,4 @@ = render :partial => 'issues/list' .actions-bar.wat-cf .actions - = will_paginate @issues, :param_name => :issue_page + = will_paginate @issues#, :param_name => :issue_page diff --git a/app/views/settings/notifiers/_form.html.haml b/app/views/settings/notifiers/_form.html.haml index 140de2655..2631874bc 100644 --- a/app/views/settings/notifiers/_form.html.haml +++ b/app/views/settings/notifiers/_form.html.haml @@ -1,18 +1,22 @@ +.group + = f.label :can_notify, t('activerecord.attributes.settings.notifier.can_notify'), :class => :label + = f.check_box :can_notify#, :class => 'text_field' + .group = f.label :new_comment, t('activerecord.attributes.settings.notifier.new_comment'), :class => :label - = f.check_box :new_comment#, :class => 'text_field' + = f.check_box :new_comment, :class => 'notify_cbx' .group = f.label :new_comment_reply, t('activerecord.attributes.settings.notifier.new_comment_reply'), :class => :label - = f.check_box :new_comment_reply#, :class => 'text_field' + = f.check_box :new_comment_reply, :class => 'notify_cbx' .group = f.label :new_issue, t('activerecord.attributes.settings.notifier.new_issue'), :class => :label - = f.check_box :new_issue#, :class => 'text_field' + = f.check_box :new_issue, :class => 'notify_cbx' .group = f.label :issue_assign, t('activerecord.attributes.settings.notifier.issue_assign'), :class => :label - = f.check_box :issue_assign#, :class => 'text_field' + = f.check_box :issue_assign, :class => 'notify_cbx' .group.navform.wat-cf %button.button{:type => "submit"} @@ -21,3 +25,5 @@ %span.text_button_padding= t("layout.or") = link_to t("layout.cancel"), user_settings_notifier_path(@user), :class => "text_button_padding link_button" +:javascript + disableNotifierCbx($('#settings_notifier_can_notify')); diff --git a/app/views/user_mailer/new_comment_reply_notification.haml b/app/views/user_mailer/new_comment_reply_notification.haml new file mode 100644 index 000000000..48ff0ab4b --- /dev/null +++ b/app/views/user_mailer/new_comment_reply_notification.haml @@ -0,0 +1,9 @@ +%p== Здравствуйте, #{@user.name}. + + +%p На Ваш комментарий в задаче #{ link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] } был дан ответ. + +%p "#{ @comment.body }" + + +%p== Команда поддержки «ROSA Build System» diff --git a/config/locales/ru.yml b/config/locales/ru.yml index a9bffa4a5..b0e848110 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -493,6 +493,7 @@ ru: attributes: settings: notifier: + can_notify: Включить оповещения по электронной почте new_comment: Оповещать о новом комментарии в задаче new_comment_reply: Оповещать о новом ответе на мой комментарий new_issue: Оповещать о новых задачах в моих проектах diff --git a/db/migrate/20120111072106_create_settings_notifiers.rb b/db/migrate/20120111072106_create_settings_notifiers.rb index ab8da3aaf..b8517a9e9 100644 --- a/db/migrate/20120111072106_create_settings_notifiers.rb +++ b/db/migrate/20120111072106_create_settings_notifiers.rb @@ -2,6 +2,8 @@ class CreateSettingsNotifiers < ActiveRecord::Migration def self.up create_table :settings_notifiers do |t| t.integer :user_id, :null => false + + t.boolean :can_notify, :default => true t.boolean :new_comment, :default => true t.boolean :new_comment_reply, :default => true t.boolean :new_issue, :default => true diff --git a/db/migrate/20120113121748_add_issue_status_default_value.rb b/db/migrate/20120113121748_add_issue_status_default_value.rb new file mode 100644 index 000000000..bbc58f3cc --- /dev/null +++ b/db/migrate/20120113121748_add_issue_status_default_value.rb @@ -0,0 +1,9 @@ +class AddIssueStatusDefaultValue < ActiveRecord::Migration + def self.up + change_column :issues, :status, :string, :default => 'open' + end + + def self.down + change_column :issues, :status, :string, :null => true + end +end diff --git a/db/schema.rb b/db/schema.rb index b91476bc7..d1c2da240 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120111135443) do +ActiveRecord::Schema.define(:version => 20120113121748) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -158,7 +158,7 @@ ActiveRecord::Schema.define(:version => 20120111135443) do t.integer "user_id" t.string "title" t.text "body" - t.string "status" + t.string "status", :default => "open" t.datetime "created_at" t.datetime "updated_at" end @@ -274,6 +274,7 @@ ActiveRecord::Schema.define(:version => 20120111135443) do create_table "settings_notifiers", :force => true do |t| t.integer "user_id", :null => false + t.boolean "can_notify", :default => true t.boolean "new_comment", :default => true t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true diff --git a/public/javascripts/application.js b/public/javascripts/application.js index b2617a1c7..2ab692666 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1,3 +1,13 @@ +function disableNotifierCbx(global_cbx) { + if ($(global_cbx).attr('checked')) { + $('.notify_cbx').removeAttr('disabled'); + $('.notify_cbx').each(function(i,el) { $(el).prev().removeAttr('disabled'); }) + } else { + $('.notify_cbx').attr('disabled', 'disabled'); + $('.notify_cbx').each(function(i,el) { $(el).prev().attr('disabled', 'disabled'); }) + } +} + $(document).ready(function() { $('select#build_list_pl_id').change(function() { var platform_id = $(this).val(); @@ -29,4 +39,8 @@ $(document).ready(function() { } }); }); + + $('#settings_notifier_can_notify').click(function() { + disableNotifierCbx($(this)); + }); });