[refs #123] Activity Feed logic global refactoring.
This commit is contained in:
parent
dd1493d677
commit
0eb0eb9713
|
@ -1,2 +1,5 @@
|
||||||
module ActivityFeedsHelper
|
module ActivityFeedsHelper
|
||||||
|
def render_activity_feed(activity_feed)
|
||||||
|
render :partial => activity_feed.partial, :locals => activity_feed.data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
class ActivityFeed < ActiveRecord::Base
|
class ActivityFeed < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
serialize :data
|
||||||
|
|
||||||
|
def partial
|
||||||
|
'activity_feeds/partials/' + self.kind
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,18 +4,26 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
def after_create(record)
|
def after_create(record)
|
||||||
case record.class.to_s
|
case record.class.to_s
|
||||||
when 'User'
|
when 'User'
|
||||||
ActivityFeed.create(:user => record, :body => render_body('new_user_notification'))
|
ActivityFeed.create(:user => record, :kind => 'new_user_notification', :date => {:user_name => record.name, :user_email => record.email, :password => user.password})
|
||||||
|
|
||||||
when 'Issue'
|
when 'Issue'
|
||||||
recipients = record.collect_recipient_ids
|
recipients = record.collect_recipient_ids
|
||||||
recipients.each do |recipient_id|
|
recipients.each do |recipient_id|
|
||||||
recipient = User.find(recipient_id)
|
recipient = User.find(recipient_id)
|
||||||
UserMailer.delay.new_issue_notification(record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
|
UserMailer.delay.new_issue_notification(record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
|
||||||
ActivityFeed.create(:user => recipient, :body => render_body('new_issue_notification', {:user => recipient, :issue => record}))
|
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}
|
||||||
|
)
|
||||||
end
|
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
|
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 => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record}))
|
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}
|
||||||
|
)
|
||||||
|
|
||||||
when 'Comment'
|
when 'Comment'
|
||||||
subscribes = record.commentable.subscribes
|
subscribes = record.commentable.subscribes
|
||||||
|
@ -23,10 +31,18 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
if record.user_id != subscribe.user_id
|
if record.user_id != subscribe.user_id
|
||||||
if record.reply? subscribe
|
if record.reply? subscribe
|
||||||
UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe)
|
UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe)
|
||||||
ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record}))
|
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}
|
||||||
|
)
|
||||||
else
|
else
|
||||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
||||||
ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record}))
|
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}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -37,13 +53,17 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
case record.class.to_s
|
case record.class.to_s
|
||||||
when 'Issue'
|
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
|
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 => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record}))
|
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}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_body(partial_name, locals={})
|
#def (partial_name, locals={})
|
||||||
@@stub_controller ||= StubController.new
|
# @@stub_controller ||= StubController.new
|
||||||
@@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals)
|
# @@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals)
|
||||||
end
|
#end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
.item
|
.item
|
||||||
= raw activity_feed.body
|
= render_activity_feed(activity_feed)
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
%p== Здравствуйте, #{user.name}.
|
%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])) }
|
||||||
%p Вам была назначена задача #{ link_to issue.title, [issue.project, issue] }
|
|
||||||
|
|
||||||
|
|
||||||
%p== Команда поддержки «ROSA Build System»
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
%p== Здравствуйте, #{user.name}.
|
%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 К задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был добавлен новый комментарий.
|
%p "#{ comment_body }"
|
||||||
|
|
||||||
%p "#{ comment.body }"
|
|
||||||
|
|
||||||
|
|
||||||
%p== Команда поддержки «ROSA Build System»
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
%p== Здравствуйте, #{user.name}.
|
%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 На Ваш комментарий в задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был дан ответ.
|
%p "#{ comment_body }"
|
||||||
|
|
||||||
%p "#{ comment.body }"
|
|
||||||
|
|
||||||
|
|
||||||
%p== Команда поддержки «ROSA Build System»
|
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
%p== Здравствуйте, #{user.name}.
|
%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)) }
|
||||||
%p К проекту #{ link_to issue.project.name, project_path(issue.project) } была добавлена задача #{ link_to issue.title, [issue.project, issue] }
|
|
||||||
|
|
||||||
|
|
||||||
%p== Команда поддержки «ROSA Build System»
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
%p== Здравствуйте, #{user.name}.
|
%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) }
|
||||||
|
|
||||||
|
|
||||||
%p Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему.
|
%p #{ t("notifications.bodies.new_user_notification.content") }
|
||||||
|
|
||||||
|
|
||||||
%p
|
%p
|
||||||
==Ваш email : #{user.email}
|
#{ t("notifications.bodies.new_user_notification.email"), :user_email => user_email }
|
||||||
%br/
|
%br/
|
||||||
==Ваш пароль: #{user.password}
|
#{ t("notifications.bodies.new_user_notification.password"), :user_password => user_email }
|
||||||
|
|
||||||
%p== Команда поддержки «ROSA Build System»
|
|
||||||
|
|
|
@ -692,6 +692,26 @@ ru:
|
||||||
notifications:
|
notifications:
|
||||||
subjects:
|
subjects:
|
||||||
new_comment_notification: Новый комментарий к Вашей задаче
|
new_comment_notification: Новый комментарий к Вашей задаче
|
||||||
|
new_comment_reply_notification: Новый комментарий к Вашей задаче
|
||||||
new_issue_notification: Новая задача добавлена к проекту
|
new_issue_notification: Новая задача добавлена к проекту
|
||||||
new_user_notification: Регистрация на проекте «%{ project_name }»
|
new_user_notification: Регистрация на проекте «%{ project_name }»
|
||||||
issue_assign_notification: Вам назначили задачу
|
issue_assign_notification: Вам назначили задачу
|
||||||
|
|
||||||
|
bodies:
|
||||||
|
new_comment_notification:
|
||||||
|
title: Здравствуйте, %{user_name}.
|
||||||
|
content: К задаче %{ issue_link } был добавлен новый комментарий.
|
||||||
|
new_comment_reply_notification:
|
||||||
|
title: Здравствуйте, %{user_name}.
|
||||||
|
content: На Ваш комментарий в задаче %{ issue_link } был дан ответ.
|
||||||
|
new_issue_notification:
|
||||||
|
title: Здравствуйте, %{user_name}.
|
||||||
|
content: К проекту %{ project_link } была добавлена задача %{ issue_link }
|
||||||
|
new_user_notification:
|
||||||
|
title: Здравствуйте, %{user_name}.
|
||||||
|
content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему.
|
||||||
|
email: ==Ваш email : %{user_email}
|
||||||
|
password: ==Ваш пароль: %{user_password}
|
||||||
|
issue_assign_notification:
|
||||||
|
title: Здравствуйте, %{user_name}.
|
||||||
|
content: Вам была назначена задача %{ issue_link }
|
||||||
|
|
|
@ -2,7 +2,8 @@ class CreateActivityFeeds < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
create_table :activity_feeds do |t|
|
create_table :activity_feeds do |t|
|
||||||
t.integer :user_id, :null => false
|
t.integer :user_id, :null => false
|
||||||
t.text :body
|
t.string :kind
|
||||||
|
t.text :data
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,8 @@ ActiveRecord::Schema.define(:version => 20120124065207) do
|
||||||
|
|
||||||
create_table "activity_feeds", :force => true do |t|
|
create_table "activity_feeds", :force => true do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.text "body"
|
t.string "kind"
|
||||||
|
t.text "data"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue