diff --git a/app/controllers/settings/notifiers_controller.rb b/app/controllers/settings/notifiers_controller.rb new file mode 100644 index 000000000..03df52237 --- /dev/null +++ b/app/controllers/settings/notifiers_controller.rb @@ -0,0 +1,22 @@ +class Settings::NotifiersController < ApplicationController + layout "sessions" + + before_filter :authenticate_user! + + load_and_authorize_resource :user + load_and_authorize_resource :class => Settings::Notifier, :through => :user, :singleton => true, :shallow => true + + def show + end + + def update + if @notifier.update_attributes(params[:settings_notifier]) + flash[:notice] = I18n.t("flash.settings.saved") + redirect_to [@user, @notifier] + else + flash[:notice] = I18n.t("flash.settings.save_error") + redirect_to [@user, @notifier] + end + end + +end diff --git a/app/helpers/settings/notifiers_helper.rb b/app/helpers/settings/notifiers_helper.rb new file mode 100644 index 000000000..295af1e51 --- /dev/null +++ b/app/helpers/settings/notifiers_helper.rb @@ -0,0 +1,2 @@ +module Settings::NotifiersHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 1b7509a2b..3697ea035 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -28,6 +28,8 @@ class Ability else # Registered user rights can [:show, :autocomplete_user_uname], User + can [:show, :update], Settings::Notifier, :user_id => user.id + can [:read, :create], Group can [:update, :manage_members], Group do |group| group.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin') # or group.owner_id = user.id diff --git a/app/models/issue.rb b/app/models/issue.rb index 9ae96f439..193254e47 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -41,7 +41,7 @@ class Issue < ActiveRecord::Base end def deliver_issue_assign_notification - UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id + UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign end def subscribe_users @@ -56,7 +56,12 @@ class Issue < ActiveRecord::Base 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 + end + recipients end - end diff --git a/app/models/settings.rb b/app/models/settings.rb new file mode 100644 index 000000000..f6af89076 --- /dev/null +++ b/app/models/settings.rb @@ -0,0 +1,5 @@ +module Settings + def self.table_name_prefix + 'settings_' + end +end diff --git a/app/models/settings/notifier.rb b/app/models/settings/notifier.rb new file mode 100644 index 000000000..af21fd811 --- /dev/null +++ b/app/models/settings/notifier.rb @@ -0,0 +1,5 @@ +class Settings::Notifier < ActiveRecord::Base + belongs_to :user + + validates :user_id, :presence => true +end diff --git a/app/models/user.rb b/app/models/user.rb index 07e59a71f..c246dd6f9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,8 @@ class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable :recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable + has_one :notifier, :class_name => 'Settings::Notifier' #:notifier + has_many :authentications, :dependent => :destroy has_many :build_lists, :dependent => :destroy @@ -31,6 +33,8 @@ class User < ActiveRecord::Base attr_readonly :uname attr_accessor :login + after_create :create_settings_notifier + def admin? role == 'admin' end @@ -75,5 +79,11 @@ class User < ActiveRecord::Base clean_up_passwords result end + + private + + def create_settings_notifier + self.create_notifier + end end diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 75d6fcfa0..c4b6052ab 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -68,3 +68,5 @@ %span.text_button_padding = link_to t('layout.back'), :back, :class => "text_button_padding link_button" + .group.navform.wat-cf + = link_to t('layout.settings.notifier'), user_settings_notifier_path(current_user)#, :class => "text_button_padding link_button" diff --git a/app/views/settings/notifiers/_form.html.haml b/app/views/settings/notifiers/_form.html.haml new file mode 100644 index 000000000..140de2655 --- /dev/null +++ b/app/views/settings/notifiers/_form.html.haml @@ -0,0 +1,23 @@ +.group + = f.label :new_comment, t('activerecord.attributes.settings.notifier.new_comment'), :class => :label + = f.check_box :new_comment#, :class => 'text_field' + +.group + = f.label :new_comment_reply, t('activerecord.attributes.settings.notifier.new_comment_reply'), :class => :label + = f.check_box :new_comment_reply#, :class => 'text_field' + +.group + = f.label :new_issue, t('activerecord.attributes.settings.notifier.new_issue'), :class => :label + = f.check_box :new_issue#, :class => 'text_field' + +.group + = f.label :issue_assign, t('activerecord.attributes.settings.notifier.issue_assign'), :class => :label + = f.check_box :issue_assign#, :class => 'text_field' + +.group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) + = t("layout.save") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), user_settings_notifier_path(@user), :class => "text_button_padding link_button" + diff --git a/app/views/settings/notifiers/show.html.haml b/app/views/settings/notifiers/show.html.haml new file mode 100644 index 000000000..97f82b931 --- /dev/null +++ b/app/views/settings/notifiers/show.html.haml @@ -0,0 +1,5 @@ +#block-signup.block + %h2= title t("layout.settings.notifiers.edit_header") + .content + = form_for @notifier, :url => user_settings_notifier_path(@user), :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} diff --git a/config/locales/ru.yml b/config/locales/ru.yml index ef20defa1..a9bffa4a5 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -30,6 +30,10 @@ ru: not_access: Нет доступа! owner: Владелец confirm: Уверенны? + settings: + notifier: Настройки оповещений + notifiers: + edit_header: Настройки оповещений downloads: title: Статистика закачек пакетов @@ -353,6 +357,11 @@ ru: project_version_not_found: версия не найден flash: + settings: + saved: Настройки успешно сохранены + save_error: При обновлении настроек произошла ошибка + + subscribe: saved: Вы подписаны на оповещения для этой задачи destroyed: Подписка на оповещения для этой задачи убрана @@ -478,8 +487,17 @@ ru: build_list_item: Элемент сборочного листа download: Статистика auto_build_list: Автоматическая пересборка пакетов + settings: + notifier: Настройки оповещений attributes: + settings: + notifier: + new_comment: Оповещать о новом комментарии в задаче + new_comment_reply: Оповещать о новом ответе на мой комментарий + new_issue: Оповещать о новых задачах в моих проектах + issue_assign: Оповещать, когда на меня выставляют задачу + auto_build_list: project_id: Проект project: Проект diff --git a/config/routes.rb b/config/routes.rb index 7f3449cde..f44ccc250 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,9 @@ Rosa::Application.routes.draw do resources :users do resources :groups, :only => [:new, :create, :index] get :autocomplete_user_uname, :on => :collection + namespace :settings do + resource :notifier, :only => [:show, :update] + end end resources :event_logs, :only => :index diff --git a/db/migrate/20120111072106_create_settings_notifiers.rb b/db/migrate/20120111072106_create_settings_notifiers.rb new file mode 100644 index 000000000..ab8da3aaf --- /dev/null +++ b/db/migrate/20120111072106_create_settings_notifiers.rb @@ -0,0 +1,17 @@ +class CreateSettingsNotifiers < ActiveRecord::Migration + def self.up + create_table :settings_notifiers do |t| + t.integer :user_id, :null => false + t.boolean :new_comment, :default => true + t.boolean :new_comment_reply, :default => true + t.boolean :new_issue, :default => true + t.boolean :issue_assign, :default => true + + t.timestamps + end + end + + def self.down + drop_table :settings_notifiers + end +end diff --git a/db/migrate/20120111135443_add_settings_notifier_to_all_users.rb b/db/migrate/20120111135443_add_settings_notifier_to_all_users.rb new file mode 100644 index 000000000..de018150a --- /dev/null +++ b/db/migrate/20120111135443_add_settings_notifier_to_all_users.rb @@ -0,0 +1,13 @@ +class AddSettingsNotifierToAllUsers < ActiveRecord::Migration + def self.up + User.all.each do |user| + user.create_notifier + end + end + + def self.down + User.all.each do |user| + user.notifier.destroy + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c4eb51827..b91476bc7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111228182425) do +ActiveRecord::Schema.define(:version => 20120111135443) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -246,7 +246,6 @@ ActiveRecord::Schema.define(:version => 20111228182425) do t.string "object_type" t.integer "target_id" t.string "target_type" - t.integer "role_id" t.datetime "created_at" t.datetime "updated_at" t.string "role" @@ -273,6 +272,16 @@ ActiveRecord::Schema.define(:version => 20111228182425) do add_index "rpms", ["project_id", "arch_id"], :name => "index_rpms_on_project_id_and_arch_id" add_index "rpms", ["project_id"], :name => "index_rpms_on_project_id" + create_table "settings_notifiers", :force => true do |t| + t.integer "user_id", :null => false + t.boolean "new_comment", :default => true + t.boolean "new_comment_reply", :default => true + t.boolean "new_issue", :default => true + t.boolean "issue_assign", :default => true + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "subscribes", :force => true do |t| t.integer "subscribeable_id" t.string "subscribeable_type" @@ -283,16 +292,16 @@ ActiveRecord::Schema.define(:version => 20111228182425) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "password_salt", :default => "", :null => false t.string "reset_password_token" - t.datetime "reset_password_sent_at" + t.string "remember_token" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" - t.string "uname" t.text "ssh_key" - t.integer "role_id" + t.string "uname" t.string "role" end diff --git a/spec/controllers/settings/notifiers_controller_spec.rb b/spec/controllers/settings/notifiers_controller_spec.rb new file mode 100644 index 000000000..3ffcced81 --- /dev/null +++ b/spec/controllers/settings/notifiers_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Settings::NotifiersController do + +end diff --git a/spec/factories/settings_notifiers.rb b/spec/factories/settings_notifiers.rb new file mode 100644 index 000000000..d189db60e --- /dev/null +++ b/spec/factories/settings_notifiers.rb @@ -0,0 +1,6 @@ +# Read about factories at http://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :notifier do + end +end \ No newline at end of file diff --git a/spec/helpers/settings/notifiers_helper_spec.rb b/spec/helpers/settings/notifiers_helper_spec.rb new file mode 100644 index 000000000..9b16f8bda --- /dev/null +++ b/spec/helpers/settings/notifiers_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Settings::NotifiersHelper. For example: +# +# describe Settings::NotifiersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Settings::NotifiersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/settings/notifier_spec.rb b/spec/models/settings/notifier_spec.rb new file mode 100644 index 000000000..fb73cfe7d --- /dev/null +++ b/spec/models/settings/notifier_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Settings::Notifier do + pending "add some examples to (or delete) #{__FILE__}" +end