diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ce54bab7e..098167d2e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -15,8 +15,8 @@ class CommentsController < ApplicationController @comment = @commentable.comments.build(params[:comment]) if @commentable.class == Issue if @commentable.class == Grit::Commit @comment = Comment.new(params[:comment].merge(:commentable_id => @commentable.id.hex, :commentable_type => @commentable.class.name)) - @comment.project = @project end + @comment.project = @project @comment.user_id = current_user.id if @comment.save flash[:notice] = I18n.t("flash.comment.saved") diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index b7454e524..1c9185aee 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -19,7 +19,7 @@ class ActivityFeedObserver < ActiveRecord::Observer :user => recipient, :kind => 'new_issue_notification', :data => {:user_name => record.creator.name, :user_email => record.creator.email, :user_id => record.creator_id,:issue_serial_id => record.serial_id, - :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name} + :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name, :project_owner => record.project.owner.uname} ) end @@ -29,7 +29,7 @@ class ActivityFeedObserver < ActiveRecord::Observer :user => record.user, :kind => 'issue_assign_notification', :data => {:user_name => record.creator.name, :user_email => record.creator.email, :user_id => record.creator_id, :issue_serial_id => record.serial_id, - :project_id => record.project.id, :issue_title => record.title, :project_name => record.project.name} + :project_id => record.project.id, :issue_title => record.title, :project_name => record.project.name, :project_owner => record.project.owner.uname} ) end @@ -42,8 +42,9 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => subscribe.user, :kind => 'new_comment_notification', - :data => {:user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_id, :comment_body => record.body, :issue_title => record.commentable.title, - :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id, :comment_id => record.id} + :data => {:user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_id, :comment_body => record.body, + :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id, + :comment_id => record.id, :project_name => record.project.name, :project_owner => record.project.owner.uname} ) end end @@ -51,12 +52,18 @@ class ActivityFeedObserver < ActiveRecord::Observer subscribes = Subscribe.comment_subscribes(record).where(:status => true) subscribes.each do |subscribe| next if record.own_comment?(subscribe.user) - UserMailer.delay.new_comment_notification(record, subscribe.user) if subscribe.user.notifier.can_notify + if subscribe.user.notifier.can_notify and + ( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) or + (subscribe.user.commentor?(record.commentable) && subscribe.user.notifier.new_comment_commit_commentor) or + (subscribe.user.committer?(record.commentable) && subscribe.user.notifier.new_comment_commit_owner) ) + UserMailer.delay.new_comment_notification(record, subscribe.user) + end ActivityFeed.create( :user => subscribe.user, :kind => 'new_comment_commit_notification', - :data => {:user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_id, :comment_body => record.body, :commit_message => record.commentable.message.encode_to_default, - :commit_id => record.commentable.id, :project_id => record.project.id, :comment_id => record.id} + :data => {:user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_id, :comment_body => record.body, + :commit_message => record.commentable.message.encode_to_default, :commit_id => record.commentable.id, + :project_id => record.project.id, :comment_id => record.id, :project_name => record.project.name, :project_owner => record.project.owner.uname} ) end end @@ -73,11 +80,13 @@ class ActivityFeedObserver < ActiveRecord::Observer if change_type == 'delete' kind = 'git_delete_branch_notification' - options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name, :change_type => change_type} + options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name, + :change_type => change_type, :project_owner => record.project.owner.uname} else kind = 'git_new_push_notification' options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits, :branch_name => branch_name, - :change_type => change_type, :user_email => record.project.git_repository.repo.log(branch_name, nil).first.author.email} + :change_type => change_type, :user_email => record.project.git_repository.repo.log(branch_name, nil).first.author.email, + :project_owner => record.project.owner.uname} options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter end @@ -100,7 +109,8 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => User.find(recipient),#record.user, :kind => 'wiki_new_commit_notification', - :data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id, :project_name => project_name, :commit_sha => commit_sha} + :data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id, + :project_name => project_name, :commit_sha => commit_sha, :project_owner => project.owner.uname} ) end end @@ -114,7 +124,8 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => record.user, :kind => 'issue_assign_notification', - :data => {:user_name => record.user.name, :user_email => record.user.email, :issue_serial_id => record.serial_id, :project_id => record.project.id, :issue_title => record.title} + :data => {:user_name => record.user.name, :user_email => record.user.email, :issue_serial_id => record.serial_id, :issue_title => record.title, + :project_id => record.project.id, :project_name => record.project.name, :project_owner => record.project.owner.uname} ) end end diff --git a/app/models/subscribe.rb b/app/models/subscribe.rb index 497314fa4..8b6907d98 100644 --- a/app/models/subscribe.rb +++ b/app/models/subscribe.rb @@ -19,10 +19,7 @@ class Subscribe < ActiveRecord::Base def self.subscribed_to_commit?(project, user, commit) subscribe = user.subscribes.where(:subscribeable_id => commit.id.hex, :subscribeable_type => commit.class.name, :project_id => project.id).first return subscribe.subscribed? if subscribe # return status if already subscribe present - # return status by settings - (project.owner?(user) && user.notifier.new_comment_commit_repo_owner) or - (user.commentor?(commit) && user.notifier.new_comment_commit_commentor) or - (user.committer?(commit) && user.notifier.new_comment_commit_owner) + true end def self.subscribe_to_commit(options) diff --git a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml index 95914ac76..1b5ff12f0 100644 --- a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml +++ b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml @@ -1,6 +1,8 @@ .top - %span= t('notifications.bodies.delete_branch', {:branch_name => branch_name, :project_name => project_name}) - = activity_feed.created_at + .text + %span + = t('notifications.bodies.delete_branch', :branch_name => branch_name) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + .both + %span.date= activity_feed.created_at .both -.fulltext - = link_to(project_name, project_path(project_id)) diff --git a/app/views/activity_feeds/partials/_git_new_push_notification.haml b/app/views/activity_feeds/partials/_git_new_push_notification.haml index 9c5aa611a..43948fcb0 100644 --- a/app/views/activity_feeds/partials/_git_new_push_notification.haml +++ b/app/views/activity_feeds/partials/_git_new_push_notification.haml @@ -4,12 +4,11 @@ = image_tag(avatar_url_by_email(user_email, :small), :alt => 'avatar') .text %span - = raw t("notifications.bodies.#{change_type}_branch", {:branch_name => branch_name}) - = raw t("notifications.bodies.project", :project_link => link_to(project_name, project_path(project_id))) + = raw t("notifications.bodies.#{change_type}_branch", {:branch_name => branch_name, :user_link => defined?(user_name) ? link_to(user_name, user_path(user_id)) : user_email}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both - %br %span.subject - last_commits.each do |commit| = link_to commit[0], commit_path(project_id, commit[0]) diff --git a/app/views/activity_feeds/partials/_issue_assign_notification.haml b/app/views/activity_feeds/partials/_issue_assign_notification.haml index b09eb8c9c..89b44c1fb 100644 --- a/app/views/activity_feeds/partials/_issue_assign_notification.haml +++ b/app/views/activity_feeds/partials/_issue_assign_notification.haml @@ -1,10 +1,8 @@ .top - .image - = image_tag(avatar_url_by_email(activity_feed.user.email, :small), :alt => 'avatar') .text %span = raw t("notifications.bodies.issue_assign_notification", { :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) - = raw t("notifications.bodies.project", :project_link => link_to(project_name, project_path(project_id))) if defined? project_name + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_new_comment_commit_notification.haml b/app/views/activity_feeds/partials/_new_comment_commit_notification.haml index b72ab2b38..fc55dca15 100644 --- a/app/views/activity_feeds/partials/_new_comment_commit_notification.haml +++ b/app/views/activity_feeds/partials/_new_comment_commit_notification.haml @@ -4,8 +4,9 @@ .text %span = raw t("notifications.bodies.new_comment_notification.title", :user_link => link_to(user_name, user_path(user_id)) ) - = raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_id, commit_id))}) + = raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_id, commit_id) + "#comment##{comment_id}")}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both - %span.subject= link_to comment_body, commit_path(project_id, commit_id) + (defined?(comment_id) ? "#comment##{comment_id}" : '') + %span.subject= comment_body diff --git a/app/views/activity_feeds/partials/_new_comment_notification.haml b/app/views/activity_feeds/partials/_new_comment_notification.haml index 7ea321ee6..1f85c39e2 100644 --- a/app/views/activity_feeds/partials/_new_comment_notification.haml +++ b/app/views/activity_feeds/partials/_new_comment_notification.haml @@ -4,8 +4,9 @@ .text %span = raw t("notifications.bodies.new_comment_notification.title", {:user_link => link_to(user_name, user_path(user_id))}) - = raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) + = raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id) + "#comment##{comment_id}")}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both - %span.subject= link_to comment_body, project_issue_path(project_id, issue_serial_id) + (defined?(comment_id) ? "#comment##{comment_id}" : '') + %span.subject= comment_body diff --git a/app/views/activity_feeds/partials/_new_issue_notification.haml b/app/views/activity_feeds/partials/_new_issue_notification.haml index 8a002ebe6..dc82e2961 100644 --- a/app/views/activity_feeds/partials/_new_issue_notification.haml +++ b/app/views/activity_feeds/partials/_new_issue_notification.haml @@ -3,9 +3,9 @@ = image_tag(avatar_url_by_email(user_email, :small), :alt => 'avatar') .text %span - = raw t("notifications.bodies.new_issue_notification", { :user_link => link_to(activity_feed.user.uname, user_path(activity_feed.user.uname))}) - = raw t("notifications.bodies.project", :project_link => link_to(project_name, project_path(project_id))) + = raw t("notifications.bodies.new_issue_notification", { :user_link => link_to(user_name, user_path(user_id)), :issue_link => project_issue_path(project_id, issue_serial_id)}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both - %span.subject= link_to(issue_title, project_issue_path(project_id, issue_serial_id)) + %span.subject= issue_title diff --git a/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml index 3ce49bd9d..69b61f326 100644 --- a/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml +++ b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml @@ -4,7 +4,7 @@ .text %span = raw t("notifications.bodies.wiki_new_commit_notification", {:user_link => user_name, :history_link => link_to("wiki", history_project_wiki_index_path(project_id))}) - = raw t("notifications.bodies.project", :project_link => link_to(project_name, project_path(project_id))) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) .both %span.date= activity_feed.created_at .both diff --git a/config/locales/models/activity_feed.en.yml b/config/locales/models/activity_feed.en.yml index 3fa5f6da1..474ee3feb 100644 --- a/config/locales/models/activity_feed.en.yml +++ b/config/locales/models/activity_feed.en.yml @@ -20,19 +20,20 @@ en: bodies: new_comment_notification: title: '%{user_link} has been added a new comment' - content: in issue %{issue_link}. - commit_content: in commit %{commit_link}. - new_issue_notification: '%{user_link} has been added an issue' + content: in issue %{issue_link} + commit_content: in commit %{commit_link} + new_issue_notification: '%{user_link} has been added a new issue' + ussue: issue 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: You have been assigned to issue %{issue_link} - wiki_new_commit_notification: '%{user_link} has been updated wiki %{history_link}' + wiki_new_commit_notification: '%{user_link} has been updated %{history_link}' invite_approve_notification: Invite to ABF - project: in project %{project_link}. + project: in project %{project_link} delete_branch: Branch %{branch_name} has been deleted - create_branch: created new branch %{branch_name} - update_branch: pushed to branch %{branch_name} \ No newline at end of file + create_branch: '%{user_link} has been created a new branch %{branch_name}' + update_branch: '%{user_link} has been pushed to branch %{branch_name}' \ No newline at end of file diff --git a/config/locales/models/activity_feed.ru.yml b/config/locales/models/activity_feed.ru.yml index 15ef69fc9..b912d2266 100644 --- a/config/locales/models/activity_feed.ru.yml +++ b/config/locales/models/activity_feed.ru.yml @@ -20,19 +20,20 @@ ru: bodies: new_comment_notification: title: '%{user_link} добавил новый комментарий' - content: в задаче %{issue_link}. - commit_content: в коммите %{commit_link}. - new_issue_notification: '%{user_link} добавил новую задачу' + content: в задаче %{issue_link} + commit_content: в коммите %{commit_link} + new_issue_notification: '%{user_link} добавил новую задачу' + issue: задачу new_user_notification: title: Здравствуйте, %{user_name}. content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. email: ==Ваш email %{user_email} password: ==Ваш пароль %{user_password} issue_assign_notification: Вам была назначена задача %{issue_link} - wiki_new_commit_notification: '%{user_link} обновил wiki %{history_link}' + wiki_new_commit_notification: '%{user_link} обновил %{history_link}' invite_approve_notification: Приглашение в ABF - project: в проекте %{project_link}. + project: в проекте %{project_link} delete_branch: Удалена ветка %{branch_name} - create_branch: создал новую ветку %{branch_name} - update_branch: внес изменения в ветку %{branch_name} \ No newline at end of file + create_branch: '%{user_link} создал новую ветку %{branch_name}' + update_branch: '%{user_link} внес изменения в ветку %{branch_name}' \ No newline at end of file diff --git a/db/migrate/20120314151558_truncate_activity_feed.rb b/db/migrate/20120314151558_truncate_activity_feed.rb new file mode 100644 index 000000000..aea3a87fd --- /dev/null +++ b/db/migrate/20120314151558_truncate_activity_feed.rb @@ -0,0 +1,8 @@ +class TruncateActivityFeed < ActiveRecord::Migration + def up + ActivityFeed.destroy_all + end + + def down + end +end