[refs #123] Add fixes for activity feed

This commit is contained in:
konstantin.grabar 2012-01-27 16:06:04 +04:00
parent 0eb0eb9713
commit 72fd821bc8
14 changed files with 84 additions and 61 deletions

View File

@ -14,16 +14,18 @@ class ActivityFeedObserver < ActiveRecord::Observer
ActivityFeed.create(
:user => recipient,
:kind => 'new_issue_notification',
:data => {:user_name => recipient.name, :issue_id => record.id, :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name}
:data => {:user_name => recipient.name, :issue_serial_id => record.serial_id, :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name}
)
end
UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify
ActivityFeed.create(
:user_name => record.user.name,
:kind => 'issue_assign_notification',
:data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title}
)
if record.user_id_was != record.user_id
UserMailer.delay.issue_assign_notification(record, record.user) if record.user.notifier.issue_assign && record.user.notifier.can_notify
ActivityFeed.create(
:user => record.user,
:kind => 'issue_assign_notification',
:data => {:user_name => record.user.name, :issue_serial_id => record.serial_id, :project_id => record.project.id, :issue_title => record.title}
)
end
when 'Comment'
subscribes = record.commentable.subscribes
@ -34,14 +36,14 @@ class ActivityFeedObserver < ActiveRecord::Observer
ActivityFeed.create(
:user => subscribe.user,
:kind => 'new_comment_reply_notification',
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id}
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id}
)
else
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
ActivityFeed.create(
:user => subscribe.user,
:kind => 'new_comment_notification',
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id}
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id}
)
end
end
@ -52,12 +54,14 @@ class ActivityFeedObserver < ActiveRecord::Observer
def after_update(record)
case record.class.to_s
when 'Issue'
UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify
ActivityFeed.create(
:user_name => record.user.name,
:kind => 'issue_assign_notification',
:data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title}
)
if record.user_id_was != record.user_id
UserMailer.delay.issue_assign_notification(record, record.user) if record.user.notifier.issue_assign && record.user.notifier.can_notify
ActivityFeed.create(
:user => record.user,
:kind => 'issue_assign_notification',
:data => {:user_name => record.user.name, :issue_serial_id => record.serial_id, :project_id => record.project.id, :issue_title => record.title}
)
end
end
end

View File

@ -38,6 +38,19 @@ class Issue < ActiveRecord::Base
end
end
def collect_recipient_ids
recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) }
recipients = recipients | [self.user_id] if self.user_id
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'
# filter by notification settings
recipients = recipients.select do |recipient|
User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify
end
recipients
end
protected
def set_serial_id
@ -65,19 +78,6 @@ class Issue < ActiveRecord::Base
end
end
def collect_recipient_ids
recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) }
recipients = recipients | [self.user_id] if self.user_id
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'
# filter by notification settings
recipients = recipients.select do |recipient|
User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify
end
recipients
end
def subscribe_issue_assigned_user
if self.user_id_was != self.user_id
self.subscribes.where(:user_id => self.user_id_was).first.destroy unless self.user_id_was.blank?

View File

@ -0,0 +1,3 @@
%p== #{ t("notifications.bodies.issue_assign_notification.title", :user_name => user_name) }
%p= raw t("notifications.bodies.issue_assign_notification.content", :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id)))

View File

@ -0,0 +1,5 @@
%p== #{ t("notifications.bodies.new_comment_notification.title", :user_name => user_name) }
%p= raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))})
%p "#{ comment_body }"

View File

@ -0,0 +1,5 @@
%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) }
%p= raw t("notifications.bodies.new_comment_reply_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))})
%p "#{ comment_body }"

View File

@ -0,0 +1,3 @@
%p== #{ t("notifications.bodies.new_issue_notification.title", :user_name => user_name) }
%p= raw t("notifications.bodies.new_issue_notification.content", :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id)), :project_link => link_to(project_name, project_path(project_id)))

View File

@ -0,0 +1,10 @@
%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.new_user_notification.content") }
%p
#{ t("notifications.bodies.new_user_notification.email", :user_email => user_email) }
%br/
#{ t("notifications.bodies.new_user_notification.password", :user_password => user_email) }

View File

@ -1,3 +0,0 @@
%p== #{ t("notifications.bodies.issue_assign_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.issue_assign_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) }

View File

@ -1,5 +0,0 @@
%p== #{ t("notifications.bodies.new_comment_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.new_comment_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) }
%p "#{ comment_body }"

View File

@ -1,5 +0,0 @@
%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.new_comment_reply_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) }
%p "#{ comment_body }"

View File

@ -1,3 +0,0 @@
%p== #{ t("notifications.bodies.new_issue_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.new_issue_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id]), :project_link => link_to(project_name, project_path(project_id)) }

View File

@ -1,10 +0,0 @@
%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) }
%p #{ t("notifications.bodies.new_user_notification.content") }
%p
#{ t("notifications.bodies.new_user_notification.email"), :user_email => user_email }
%br/
#{ t("notifications.bodies.new_user_notification.password"), :user_password => user_email }

View File

@ -691,4 +691,23 @@ en:
new_comment_notification: New comment to your task
new_issue_notification: New task added to project
new_user_notification: Registered on project «%{ project_name }»
issue_assign_notification: New task assigned
issue_assign_notification: New task assigned
bodies:
new_comment_notification:
title: Hello, %{user_name}.
content: To the issue %{issue_link} added a comment.
new_comment_reply_notification:
title: Hello, %{user_name}.
content: Your comment into issue %{issue_link} has been answered.
new_issue_notification:
title: Hello, %{user_name}.
content: To project %{project_link} has been added an issue %{issue_link}
new_user_notification:
title: Hello, %{user_name}.
content: You have been sign up to project «ROSA Build System» and now can sign in.
email: ==Your email %{user_email}
password: ==Your password %{user_password}
issue_assign_notification:
title: Hello, %{user_name}.
content: You have been assigned to issue %{issue_link}

View File

@ -700,18 +700,18 @@ ru:
bodies:
new_comment_notification:
title: Здравствуйте, %{user_name}.
content: К задаче %{ issue_link } был добавлен новый комментарий.
content: К задаче %{issue_link} был добавлен новый комментарий.
new_comment_reply_notification:
title: Здравствуйте, %{user_name}.
content: На Ваш комментарий в задаче %{ issue_link } был дан ответ.
content: На Ваш комментарий в задаче %{issue_link} был дан ответ.
new_issue_notification:
title: Здравствуйте, %{user_name}.
content: К проекту %{ project_link } была добавлена задача %{ issue_link }
content: К проекту %{project_link} была добавлена задача %{issue_link}
new_user_notification:
title: Здравствуйте, %{user_name}.
content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему.
email: ==Ваш email : %{user_email}
password: ==Ваш пароль: %{user_password}
email: ==Ваш email %{user_email}
password: ==Ваш пароль %{user_password}
issue_assign_notification:
title: Здравствуйте, %{user_name}.
content: Вам была назначена задача %{ issue_link }
content: Вам была назначена задача %{issue_link}