[refs #123] Add base logic for activity feed
This commit is contained in:
parent
2a20b51c19
commit
990a46018c
|
@ -0,0 +1,7 @@
|
|||
class ActivityFeedsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@activity_feeds = current_user.activity_feeds
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
class StubController < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
include AbstractController::Layouts
|
||||
include AbstractController::Helpers
|
||||
include AbstractController::Translation
|
||||
include AbstractController::AssetPaths
|
||||
include ActionController::UrlWriter
|
||||
|
||||
# Uncomment if you want to use helpers
|
||||
# defined in ApplicationHelper in your views
|
||||
# helper ApplicationHelper
|
||||
|
||||
# Make sure your controller can find views
|
||||
self.view_paths = "app/views"
|
||||
|
||||
# You can define custom helper methods to be used in views here
|
||||
# helper_method :current_admin
|
||||
# def current_admin; nil; end
|
||||
|
||||
def partial_to_string(partial_name, locals)
|
||||
render_to_string(partial_name, :locals => locals)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module ActivityFeedsHelper
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class ActivityFeed < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
def render_body(partial_name, locals={})
|
||||
av = ActionView::Base.new(Rails::Configuration.new.view_path)
|
||||
av.render(
|
||||
:partial => 'app/views/activity_feeds/partials/' + partial_name + '.haml',
|
||||
:locals => locals
|
||||
)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,55 @@
|
|||
class ActivityFeedObserver < ActiveRecord::Observer
|
||||
observe :issue, :comment
|
||||
|
||||
def after_create(record)
|
||||
case record.class.to_s
|
||||
when 'User'
|
||||
ActivityFeed.create(:user => record, :body => render_body('new_user_notification'))
|
||||
when 'Issue'
|
||||
recipients = record.collect_recipient_ids
|
||||
recipients.each do |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
|
||||
ActivityFeed.create(:user => record, :body => render_body('new_issue_notification', {:user => recipient, :issue => record}))
|
||||
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 => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record}))
|
||||
when 'Comment'
|
||||
subscribes = record.commentable.subscribes
|
||||
subscribes.each do |subscribe|
|
||||
if record.user_id != subscribe.user_id
|
||||
if record.reply? subscribe
|
||||
UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe)
|
||||
ActivityFeed.create(:user => record.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record}))
|
||||
else
|
||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
||||
ActivityFeed.create(:user => record.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record}))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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 => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record}))
|
||||
end
|
||||
end
|
||||
|
||||
def render_body(partial_name, locals={})
|
||||
#ac = ActionController::Base.new
|
||||
#ac.render_to_string(
|
||||
# 'app/views/activity_feeds/partials/' + partial_name + '.haml',
|
||||
# :locals => locals
|
||||
#)
|
||||
|
||||
#ac = ActionView::Base.new([], locals)
|
||||
#ac.render(:inline => 'app/views/activity_feeds/partials/' + partial_name + '.haml')
|
||||
|
||||
StubController.new.partial_to_string('activity_feeds/partials/' + partial_name, locals)
|
||||
end
|
||||
|
||||
end
|
|
@ -7,22 +7,35 @@ class Comment < ActiveRecord::Base
|
|||
|
||||
# FIXME
|
||||
after_create :subscribe_on_reply, :unless => "commentable_type == 'Grit::Commit'"
|
||||
after_create :deliver_new_comment_notification, :unless => "commentable_type == 'Grit::Commit'"
|
||||
#after_create :deliver_new_comment_notification, :unless => "commentable_type == 'Grit::Commit'"
|
||||
|
||||
def reply?(subscribe)
|
||||
self.commentable.comments.exists?(:user_id => subscribe.user.id)
|
||||
end
|
||||
|
||||
def can_notify_on_reply?(subscribe)
|
||||
User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify
|
||||
end
|
||||
|
||||
def can_notify_on_new_comment?(subscribe)
|
||||
User.find(subscribe.user).notifier.new_comment && User.find(subscribe.user).notifier.can_notify
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def deliver_new_comment_notification
|
||||
subscribes = self.commentable.subscribes
|
||||
subscribes.each do |subscribe|
|
||||
if self.user_id != subscribe.user_id && User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify
|
||||
if self.commentable.comments.exists?(:user_id => subscribe.user.id)
|
||||
UserMailer.delay.new_comment_reply_notification(self, subscribe.user)
|
||||
else
|
||||
UserMailer.delay.new_comment_notification(self, subscribe.user)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#def deliver_new_comment_notification
|
||||
# subscribes = self.commentable.subscribes
|
||||
# subscribes.each do |subscribe|
|
||||
# # TODO: new_comment and new_comment_reply - you need to check each variant, not only new_comment_reply...
|
||||
# if self.user_id != subscribe.user_id && User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify
|
||||
# if self.reply? subscribe
|
||||
# UserMailer.delay.new_comment_reply_notification(self, subscribe.user)
|
||||
# else
|
||||
# UserMailer.delay.new_comment_notification(self, subscribe.user)
|
||||
# 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)
|
||||
|
|
|
@ -19,9 +19,9 @@ class Issue < ActiveRecord::Base
|
|||
|
||||
after_create :set_serial_id
|
||||
after_create :subscribe_users
|
||||
after_create :deliver_new_issue_notification
|
||||
after_create :deliver_issue_assign_notification
|
||||
after_update :deliver_issue_assign_notification
|
||||
#after_create :deliver_new_issue_notification
|
||||
#after_create :deliver_issue_assign_notification
|
||||
#after_update :deliver_issue_assign_notification
|
||||
after_update :subscribe_issue_assigned_user
|
||||
|
||||
def assign_uname
|
||||
|
@ -45,17 +45,17 @@ class Issue < ActiveRecord::Base
|
|||
self.save!
|
||||
end
|
||||
|
||||
def deliver_new_issue_notification
|
||||
recipients = collect_recipient_ids
|
||||
recipients.each do |recipient_id|
|
||||
recipient = User.find(recipient_id)
|
||||
UserMailer.delay.new_issue_notification(self, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
|
||||
end
|
||||
end
|
||||
#def deliver_new_issue_notification
|
||||
# recipients = collect_recipient_ids
|
||||
# recipients.each do |recipient_id|
|
||||
# recipient = User.find(recipient_id)
|
||||
# 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 && self.user.notifier.can_notify
|
||||
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 && self.user.notifier.can_notify
|
||||
#end
|
||||
|
||||
def subscribe_users
|
||||
recipients = collect_recipient_ids
|
||||
|
|
|
@ -8,6 +8,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
has_one :notifier, :class_name => 'Settings::Notifier' #:notifier
|
||||
|
||||
has_many :activity_feeds
|
||||
|
||||
has_many :authentications, :dependent => :destroy
|
||||
has_many :build_lists, :dependent => :destroy
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
%p== Здравствуйте, #{user.name}.
|
||||
|
||||
|
||||
%p Вам была назначена задача #{ link_to issue.title, [issue.project, issue] }
|
||||
|
||||
|
||||
%p== Команда поддержки «ROSA Build System»
|
|
@ -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»
|
|
@ -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»
|
|
@ -0,0 +1,7 @@
|
|||
%p== Здравствуйте, #{user.name}.
|
||||
|
||||
|
||||
%p К проекту #{ link_to issue.project.name, project_path(issue.project) } была добавлена задача #{ link_to issue.title, [issue.project, issue] }
|
||||
|
||||
|
||||
%p== Команда поддержки «ROSA Build System»
|
|
@ -0,0 +1,12 @@
|
|||
%p== Здравствуйте, #{user.name}.
|
||||
|
||||
|
||||
%p Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему.
|
||||
|
||||
|
||||
%p
|
||||
==Ваш email : #{user.email}
|
||||
%br/
|
||||
==Ваш пароль: #{user.password}
|
||||
|
||||
%p== Команда поддержки «ROSA Build System»
|
|
@ -24,7 +24,7 @@ module Rosa
|
|||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||
|
||||
# Activate observers that should always be running.
|
||||
config.active_record.observers = :event_log_observer
|
||||
config.active_record.observers = :event_log_observer, :activity_feed_observer
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
class CreateActivityFeeds < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :activity_feeds do |t|
|
||||
t.integer :user_id, :null => false
|
||||
t.text :body
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :activity_feeds
|
||||
end
|
||||
end
|
24
db/schema.rb
24
db/schema.rb
|
@ -10,7 +10,14 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120117110723) do
|
||||
ActiveRecord::Schema.define(:version => 20120124065207) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.text "body"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -167,13 +174,6 @@ ActiveRecord::Schema.define(:version => 20120117110723) do
|
|||
|
||||
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
|
||||
|
||||
create_table "permissions", :force => true do |t|
|
||||
t.integer "right_id"
|
||||
t.integer "role_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "platforms", :force => true do |t|
|
||||
t.string "description"
|
||||
t.string "name"
|
||||
|
@ -270,14 +270,6 @@ ActiveRecord::Schema.define(:version => 20120117110723) do
|
|||
t.string "owner_type"
|
||||
end
|
||||
|
||||
create_table "rights", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.string "controller", :null => false
|
||||
t.string "action", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "rpms", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "arch_id", :null => false
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ActivityFeedsController do
|
||||
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
# Read about factories at http://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :activity_feed do
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the ActivityFeedsHelper. For example:
|
||||
#
|
||||
# describe ActivityFeedsHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# helper.concat_strings("this","that").should == "this that"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe ActivityFeedsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ActivityFeedObserver do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ActivityFeed do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue