[refs #94] Add new notifier rules. Fix some issues and comments bugs
This commit is contained in:
parent
980e455b31
commit
db0a66846b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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»
|
|
@ -493,6 +493,7 @@ ru:
|
|||
attributes:
|
||||
settings:
|
||||
notifier:
|
||||
can_notify: Включить оповещения по электронной почте
|
||||
new_comment: Оповещать о новом комментарии в задаче
|
||||
new_comment_reply: Оповещать о новом ответе на мой комментарий
|
||||
new_issue: Оповещать о новых задачах в моих проектах
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue