Commit fe514b17ab6de8c9d1f091e50e94aaf27183aa6d
1 parent
f3cbbfe0
Exists in
master
and in
4 other branches
Adding groups to notification settings
Showing
7 changed files
with
68 additions
and
47 deletions
Show diff stats
app/controllers/notifications_controller.rb
| ... | ... | @@ -4,6 +4,7 @@ class NotificationsController < ApplicationController |
| 4 | 4 | def show |
| 5 | 5 | @notification = current_user.notification |
| 6 | 6 | @users_projects = current_user.users_projects |
| 7 | + @users_groups = current_user.users_groups | |
| 7 | 8 | end |
| 8 | 9 | |
| 9 | 10 | def update |
| ... | ... | @@ -12,6 +13,10 @@ class NotificationsController < ApplicationController |
| 12 | 13 | @saved = if type == 'global' |
| 13 | 14 | current_user.notification_level = params[:notification_level] |
| 14 | 15 | current_user.save |
| 16 | + elsif type == 'group' | |
| 17 | + users_group = current_user.users_groups.find(params[:notification_id]) | |
| 18 | + users_group.notification_level = params[:notification_level] | |
| 19 | + users_group.save | |
| 15 | 20 | else |
| 16 | 21 | users_project = current_user.users_projects.find(params[:notification_id]) |
| 17 | 22 | users_project.notification_level = params[:notification_level] | ... | ... |
app/models/users_group.rb
app/models/users_project.rb
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | |
| 14 | 14 | class UsersProject < ActiveRecord::Base |
| 15 | 15 | include Gitlab::ShellAdapter |
| 16 | + include Notifiable | |
| 16 | 17 | |
| 17 | 18 | GUEST = 10 |
| 18 | 19 | REPORTER = 20 |
| ... | ... | @@ -30,7 +31,6 @@ class UsersProject < ActiveRecord::Base |
| 30 | 31 | validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" } |
| 31 | 32 | validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true |
| 32 | 33 | validates :project, presence: true |
| 33 | - validates :notification_level, inclusion: { in: Notification.project_notification_levels }, presence: true | |
| 34 | 34 | |
| 35 | 35 | delegate :name, :username, :email, to: :user, prefix: true |
| 36 | 36 | |
| ... | ... | @@ -134,8 +134,4 @@ class UsersProject < ActiveRecord::Base |
| 134 | 134 | def skip_git? |
| 135 | 135 | !!@skip_git |
| 136 | 136 | end |
| 137 | - | |
| 138 | - def notification | |
| 139 | - @notification ||= Notification.new(self) | |
| 140 | - end | |
| 141 | 137 | end | ... | ... |
app/services/notification_service.rb
| ... | ... | @@ -148,13 +148,18 @@ class NotificationService |
| 148 | 148 | # Get project users with WATCH notification level |
| 149 | 149 | def project_watchers(project) |
| 150 | 150 | |
| 151 | - # Get project notification settings since it has higher priority | |
| 152 | - user_ids = project.users_projects.where(notification_level: Notification::N_WATCH).pluck(:user_id) | |
| 153 | - project_watchers = User.where(id: user_ids) | |
| 151 | + member_methods = [:users_projects] | |
| 152 | + member_methods << :users_groups if project.group | |
| 154 | 153 | |
| 155 | - # next collect users who use global settings with watch state | |
| 156 | - user_ids = project.users_projects.where(notification_level: Notification::N_GLOBAL).pluck(:user_id) | |
| 157 | - project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH) | |
| 154 | + member_methods.each do |member_method| | |
| 155 | + # Get project notification settings since it has higher priority | |
| 156 | + user_ids = project.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id) | |
| 157 | + project_watchers = User.where(id: user_ids) | |
| 158 | + | |
| 159 | + # next collect users who use global settings with watch state | |
| 160 | + user_ids = project.send(member_method).where(notification_level: Notification::N_GLOBAL).pluck(:user_id) | |
| 161 | + project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH) | |
| 162 | + end | |
| 158 | 163 | |
| 159 | 164 | project_watchers.uniq |
| 160 | 165 | end | ... | ... |
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +%li | |
| 2 | + .row | |
| 3 | + .span4 | |
| 4 | + %span | |
| 5 | + - if membership.kind_of? UsersGroup | |
| 6 | + = link_to membership.group.name, membership.group | |
| 7 | + - else | |
| 8 | + = link_to_project(membership.project) | |
| 9 | + .span7 | |
| 10 | + = form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do | |
| 11 | + = hidden_field_tag :notification_type, type, id: dom_id(membership, 'notification_type') | |
| 12 | + = hidden_field_tag :notification_id, membership.id, id: dom_id(membership, 'notification_id') | |
| 13 | + | |
| 14 | + = label_tag do | |
| 15 | + = radio_button_tag :notification_level, Notification::N_GLOBAL, notification.global?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit' | |
| 16 | + %span Use global setting | |
| 17 | + | |
| 18 | + = label_tag do | |
| 19 | + = radio_button_tag :notification_level, Notification::N_DISABLED, notification.disabled?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit' | |
| 20 | + %span Disabled | |
| 21 | + | |
| 22 | + = label_tag do | |
| 23 | + = radio_button_tag :notification_level, Notification::N_PARTICIPATING, notification.participating?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit' | |
| 24 | + %span Participating | |
| 25 | + | |
| 26 | + = label_tag do | |
| 27 | + = radio_button_tag :notification_level, Notification::N_WATCH, notification.watch?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit' | |
| 28 | + %span Watch | |
| 29 | + | ... | ... |
app/views/notifications/show.html.haml
| ... | ... | @@ -36,36 +36,19 @@ |
| 36 | 36 | = link_to '#', class: 'js-toggle-visibility-link' do |
| 37 | 37 | %h6.btn.btn-tiny |
| 38 | 38 | %i.icon-chevron-down |
| 39 | - %span Per project notifications setting | |
| 40 | - | |
| 41 | -%ul.well-list.js-toggle-visibility-container.hide | |
| 42 | - - @users_projects.each do |users_project| | |
| 43 | - - notification = Notification.new(users_project) | |
| 44 | - %li | |
| 45 | - .row | |
| 46 | - .span4 | |
| 47 | - %span | |
| 48 | - = link_to_project(users_project.project) | |
| 49 | - .span7 | |
| 50 | - = form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do | |
| 51 | - = hidden_field_tag :notification_type, 'project', id: dom_id(users_project, 'notification_type') | |
| 52 | - = hidden_field_tag :notification_id, users_project.id, id: dom_id(users_project, 'notification_id') | |
| 53 | - | |
| 54 | - = label_tag do | |
| 55 | - = radio_button_tag :notification_level, Notification::N_GLOBAL, notification.global?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit' | |
| 56 | - %span Use global setting | |
| 57 | - | |
| 58 | - = label_tag do | |
| 59 | - = radio_button_tag :notification_level, Notification::N_DISABLED, notification.disabled?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit' | |
| 60 | - %span Disabled | |
| 61 | - | |
| 62 | - = label_tag do | |
| 63 | - = radio_button_tag :notification_level, Notification::N_PARTICIPATING, notification.participating?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit' | |
| 64 | - %span Participating | |
| 65 | - | |
| 66 | - = label_tag do | |
| 67 | - = radio_button_tag :notification_level, Notification::N_WATCH, notification.watch?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit' | |
| 68 | - %span Watch | |
| 39 | + %span Advanced notifications settings | |
| 40 | +.js-toggle-visibility-container.hide | |
| 41 | + %h5 Groups: | |
| 42 | + %ul.well-list | |
| 43 | + - @users_groups.each do |users_group| | |
| 44 | + - notification = Notification.new(users_group) | |
| 45 | + = render 'settings', type: 'project', membership: users_group, notification: notification | |
| 46 | + | |
| 47 | + %h5 Projects: | |
| 48 | + %ul.well-list | |
| 49 | + - @users_projects.each do |users_project| | |
| 50 | + - notification = Notification.new(users_project) | |
| 51 | + = render 'settings', type: 'project', membership: users_project, notification: notification | |
| 69 | 52 | |
| 70 | 53 | |
| 71 | 54 | .save-status-fixed | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(:version => 20130617095603) do | |
| 14 | +ActiveRecord::Schema.define(:version => 20130621195223) do | |
| 15 | 15 | |
| 16 | 16 | create_table "deploy_keys_projects", :force => true do |t| |
| 17 | 17 | t.integer "deploy_key_id", :null => false |
| ... | ... | @@ -301,11 +301,12 @@ ActiveRecord::Schema.define(:version => 20130617095603) do |
| 301 | 301 | add_index "users", ["username"], :name => "index_users_on_username" |
| 302 | 302 | |
| 303 | 303 | create_table "users_groups", :force => true do |t| |
| 304 | - t.integer "group_access", :null => false | |
| 305 | - t.integer "group_id", :null => false | |
| 306 | - t.integer "user_id", :null => false | |
| 307 | - t.datetime "created_at", :null => false | |
| 308 | - t.datetime "updated_at", :null => false | |
| 304 | + t.integer "group_access", :null => false | |
| 305 | + t.integer "group_id", :null => false | |
| 306 | + t.integer "user_id", :null => false | |
| 307 | + t.datetime "created_at", :null => false | |
| 308 | + t.datetime "updated_at", :null => false | |
| 309 | + t.integer "notification_level", :default => 3, :null => false | |
| 309 | 310 | end |
| 310 | 311 | |
| 311 | 312 | create_table "users_projects", :force => true do |t| | ... | ... |