diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 6e33b405a..07d4d6630 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -52,7 +52,7 @@ class UserMailer < ActionMailer::Base end def build_list_notification(build_list, user) - I18n.locale = user.language if user.language + set_locale user @user, @build_list = user, build_list subject = "[№ #{build_list.id}] " @@ -69,7 +69,7 @@ class UserMailer < ActionMailer::Base end def invite_approve_notification(register_request) - I18n.locale = register_request.language if register_request.language + set_locale register_request @register_request = register_request mail( :to => register_request.email, @@ -79,8 +79,32 @@ class UserMailer < ActionMailer::Base end end + def git_delete_branch_notification(user, options) + set_locale user + mail( + :to => user.email, + :subject => I18n.t('notifications.subjects.new_commit') + ) do |format| + format.html { render 'git_delete_branch_notification', :locals => options } + end + end + + def git_new_push_notification(user, options) + set_locale user + mail( + :to => user.email, + :subject => I18n.t('notifications.subjects.new_commit') + ) do |format| + format.html { render 'git_new_push_notification', :locals => options } + end + end + protected + def set_locale(user) + I18n.locale = user.language if user.language + end + def email_with_name(user, email = APP_CONFIG['do-not-reply-email']) "\"#{user.user_appeal}\" <#{email}>" end diff --git a/app/views/api/v1/users/notifiers.json.jbuilder b/app/views/api/v1/users/notifiers.json.jbuilder index 4e38d0b4f..db71f3d5b 100644 --- a/app/views/api/v1/users/notifiers.json.jbuilder +++ b/app/views/api/v1/users/notifiers.json.jbuilder @@ -1,7 +1,8 @@ json.user do json.(@user, :id) json.notifiers do - json.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build) + json.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build, + :new_commit) end end diff --git a/app/views/user_mailer/git_delete_branch_notification.html.haml b/app/views/user_mailer/git_delete_branch_notification.html.haml new file mode 100644 index 000000000..22b1be763 --- /dev/null +++ b/app/views/user_mailer/git_delete_branch_notification.html.haml @@ -0,0 +1,8 @@ +- user = User.where(:email => user_email).first || User.new(:email => user_email) if defined?(user_email) + +%p + - _user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email) : nil + = t('notifications.bodies.delete_branch', :branch_name => branch_name, :user_link => _user_link).html_safe + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + += render 'footer' \ No newline at end of file diff --git a/app/views/user_mailer/git_new_push_notification.html.haml b/app/views/user_mailer/git_new_push_notification.html.haml new file mode 100644 index 000000000..01c9ea1a1 --- /dev/null +++ b/app/views/user_mailer/git_new_push_notification.html.haml @@ -0,0 +1,20 @@ +- user = User.where(:email => user_email).first || User.new(:email => user_email) if defined?(user_email) + + +%p + - _user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email) : nil + = raw t("notifications.bodies.#{change_type}_branch", {:branch_name => branch_name, :user_link => _user_link}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + + +%p + - last_commits.each do |commit| + = link_to shortest_hash_id(commit[0]), commit_path(project_owner, project_name, commit[0]) + = commit[1] + %br + - if defined? other_commits + %br + =link_to t('notifications.bodies.more_commits', :count => other_commits_count, :commits => commits_pluralize(other_commits_count)), + diff_path(project_owner, project_name, :diff => other_commits) + += render 'footer' \ No newline at end of file diff --git a/app/views/users/settings/notifiers.html.haml b/app/views/users/settings/notifiers.html.haml index 76ba13947..72f940b3a 100644 --- a/app/views/users/settings/notifiers.html.haml +++ b/app/views/users/settings/notifiers.html.haml @@ -9,7 +9,7 @@ = form_for @user.notifier, :url => notifiers_settings_path, :html => {:class => :form} do |f| = render 'notifier', :f => f, :field => :can_notify %h3= t("layout.settings.notifiers.code_header") - - [:new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor].each do |field| + - [:new_commit, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor].each do |field| = render 'notifier', :f => f, :field => field %h3= t("layout.settings.notifiers.tracker_header") - [:new_comment, :new_comment_reply, :new_issue, :issue_assign].each do |field| diff --git a/config/locales/en.yml b/config/locales/en.yml index e5176f2fc..b7fea0baf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -154,11 +154,11 @@ en: group_already_added: Group already added successfully_added: Member %s successfully added error_in_adding: Member %s adding error - wrong_user: User with nickname '%{uname}' not found! + wrong_user: "User with nickname '%{uname}' not found!" blob: - successfully_updated: File '%{name}' successfully updated - updating_error: Error updating file '%{name}' + successfully_updated: "File '%{name}' successfully updated" + updating_error: "Error updating file '%{name}'" attributes: password: Password @@ -188,6 +188,7 @@ en: new_comment_reply: New reply of comment notifications new_issue: New task notifications issue_assign: New task assignment notifications + new_commit: Notify about new commits in my projects new_comment_commit_owner: Notify about comments to my commit new_comment_commit_repo_owner: Notify about comments to my repository commits new_comment_commit_commentor: Notify about comments after my commit diff --git a/config/locales/models/activity_feed.en.yml b/config/locales/models/activity_feed.en.yml index c16af4eac..3ac0dea78 100644 --- a/config/locales/models/activity_feed.en.yml +++ b/config/locales/models/activity_feed.en.yml @@ -12,6 +12,7 @@ en: notifications: subjects: + new_commit: "[%{ project_name }] Update of project" new_comment_notification: New comment to your task new_commit_comment_notification: New comment to commit new_issue_notification: New task added to project diff --git a/config/locales/models/activity_feed.ru.yml b/config/locales/models/activity_feed.ru.yml index 94b1a6d76..75b2b2679 100644 --- a/config/locales/models/activity_feed.ru.yml +++ b/config/locales/models/activity_feed.ru.yml @@ -12,6 +12,7 @@ ru: notifications: subjects: + new_commit: "[%{ project_name }] Обновление проекта" new_comment_notification: Новый комментарий к Вашей задаче new_commit_comment_notification: Новый комментарий к коммиту new_issue_notification: Новая задача добавлена к проекту diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 7781cf2f3..e1261d3f4 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -154,11 +154,11 @@ ru: group_already_added: Группа уже добавлена successfully_added: Участник %s успешно добавлен error_in_adding: Ошибка при добавлении участника %s - wrong_user: Пользователь с ником '%{uname}' не найден. + wrong_user: "Пользователь с ником '%{uname}' не найден." blob: - successfully_updated: Файл '%{name}' успешно обновлен - updating_error: Ошибка обновления файла '%{name}' + successfully_updated: "Файл '%{name}' успешно обновлен" + updating_error: "Ошибка обновления файла '%{name}'" attributes: password: Пароль @@ -188,6 +188,7 @@ ru: new_comment_reply: Оповещать о новом ответе на мой комментарий new_issue: Оповещать о новых задачах в моих проектах issue_assign: Оповещать, когда на меня выставляют задачу + new_commit: Оповещать о новых коммитах в моих проектах new_comment_commit_owner: Оповещать о комментариях к моему коммиту new_comment_commit_repo_owner: Оповещать о комментариях к коммитам в моем репозитории new_comment_commit_commentor: Оповещать о комментариях к коммиту после моего diff --git a/db/migrate/20131126154305_add_new_commit_to_settings_notifier.rb b/db/migrate/20131126154305_add_new_commit_to_settings_notifier.rb new file mode 100644 index 000000000..8879d6593 --- /dev/null +++ b/db/migrate/20131126154305_add_new_commit_to_settings_notifier.rb @@ -0,0 +1,5 @@ +class AddNewCommitToSettingsNotifier < ActiveRecord::Migration + def change + add_column :settings_notifiers, :new_commit, :boolean, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index f1c62d3a2..6a8d7fe61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131107152408) do +ActiveRecord::Schema.define(:version => 20131126154305) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -21,6 +21,8 @@ ActiveRecord::Schema.define(:version => 20131107152408) do t.datetime "updated_at" end + add_index "activity_feeds", ["user_id", "kind"], :name => "index_activity_feeds_on_user_id_and_kind" + create_table "advisories", :force => true do |t| t.string "advisory_id" t.text "description", :default => "" @@ -509,7 +511,7 @@ ActiveRecord::Schema.define(:version => 20131107152408) do add_index "repository_statuses", ["repository_id", "platform_id"], :name => "index_repository_statuses_on_repository_id_and_platform_id", :unique => true create_table "settings_notifiers", :force => true do |t| - t.integer "user_id", :null => false + 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 @@ -522,6 +524,7 @@ ActiveRecord::Schema.define(:version => 20131107152408) do t.boolean "new_comment_commit_commentor", :default => true t.boolean "new_build", :default => true t.boolean "new_associated_build", :default => true + t.boolean "new_commit", :default => false end create_table "ssh_keys", :force => true do |t| diff --git a/lib/modules/observers/activity_feed/git.rb b/lib/modules/observers/activity_feed/git.rb index cf5b19ebd..48024a691 100644 --- a/lib/modules/observers/activity_feed/git.rb +++ b/lib/modules/observers/activity_feed/git.rb @@ -44,6 +44,9 @@ module Modules::Observers::ActivityFeed::Git :kind => kind, :data => options ) + if recipient.notifier.can_notify && recipient.notifier.new_commit + UserMailer.send(kind, recipient, options).deliver + end end when 'Hash' # 'Gollum::Committer'