Commit fe514b17 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Adding groups to notification settings

parent f3cbbfe0
...@@ -4,6 +4,7 @@ class NotificationsController < ApplicationController ...@@ -4,6 +4,7 @@ class NotificationsController < ApplicationController
def show def show
@notification = current_user.notification @notification = current_user.notification
@users_projects = current_user.users_projects @users_projects = current_user.users_projects
@users_groups = current_user.users_groups
end end
def update def update
...@@ -12,6 +13,10 @@ class NotificationsController < ApplicationController ...@@ -12,6 +13,10 @@ class NotificationsController < ApplicationController
@saved = if type == 'global' @saved = if type == 'global'
current_user.notification_level = params[:notification_level] current_user.notification_level = params[:notification_level]
current_user.save current_user.save
elsif type == 'group'
users_group = current_user.users_groups.find(params[:notification_id])
users_group.notification_level = params[:notification_level]
users_group.save
else else
users_project = current_user.users_projects.find(params[:notification_id]) users_project = current_user.users_projects.find(params[:notification_id])
users_project.notification_level = params[:notification_level] users_project.notification_level = params[:notification_level]
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
# #
class UsersGroup < ActiveRecord::Base class UsersGroup < ActiveRecord::Base
include Notifiable
GUEST = 10 GUEST = 10
REPORTER = 20 REPORTER = 20
DEVELOPER = 30 DEVELOPER = 30
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
class UsersProject < ActiveRecord::Base class UsersProject < ActiveRecord::Base
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include Notifiable
GUEST = 10 GUEST = 10
REPORTER = 20 REPORTER = 20
...@@ -30,7 +31,6 @@ class UsersProject < ActiveRecord::Base ...@@ -30,7 +31,6 @@ class UsersProject < ActiveRecord::Base
validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" } validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true
validates :project, presence: true validates :project, presence: true
validates :notification_level, inclusion: { in: Notification.project_notification_levels }, presence: true
delegate :name, :username, :email, to: :user, prefix: true delegate :name, :username, :email, to: :user, prefix: true
...@@ -134,8 +134,4 @@ class UsersProject < ActiveRecord::Base ...@@ -134,8 +134,4 @@ class UsersProject < ActiveRecord::Base
def skip_git? def skip_git?
!!@skip_git !!@skip_git
end end
def notification
@notification ||= Notification.new(self)
end
end end
...@@ -148,13 +148,18 @@ class NotificationService ...@@ -148,13 +148,18 @@ class NotificationService
# Get project users with WATCH notification level # Get project users with WATCH notification level
def project_watchers(project) def project_watchers(project)
# Get project notification settings since it has higher priority member_methods = [:users_projects]
user_ids = project.users_projects.where(notification_level: Notification::N_WATCH).pluck(:user_id) member_methods << :users_groups if project.group
project_watchers = User.where(id: user_ids)
# next collect users who use global settings with watch state member_methods.each do |member_method|
user_ids = project.users_projects.where(notification_level: Notification::N_GLOBAL).pluck(:user_id) # Get project notification settings since it has higher priority
project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH) user_ids = project.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id)
project_watchers = User.where(id: user_ids)
# next collect users who use global settings with watch state
user_ids = project.send(member_method).where(notification_level: Notification::N_GLOBAL).pluck(:user_id)
project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH)
end
project_watchers.uniq project_watchers.uniq
end end
......
%li
.row
.span4
%span
- if membership.kind_of? UsersGroup
= link_to membership.group.name, membership.group
- else
= link_to_project(membership.project)
.span7
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do
= hidden_field_tag :notification_type, type, id: dom_id(membership, 'notification_type')
= hidden_field_tag :notification_id, membership.id, id: dom_id(membership, 'notification_id')
= label_tag do
= radio_button_tag :notification_level, Notification::N_GLOBAL, notification.global?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit'
%span Use global setting
= label_tag do
= radio_button_tag :notification_level, Notification::N_DISABLED, notification.disabled?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit'
%span Disabled
= label_tag do
= radio_button_tag :notification_level, Notification::N_PARTICIPATING, notification.participating?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit'
%span Participating
= label_tag do
= radio_button_tag :notification_level, Notification::N_WATCH, notification.watch?, id: dom_id(membership, 'notification_level'), class: 'trigger-submit'
%span Watch
...@@ -36,36 +36,19 @@ ...@@ -36,36 +36,19 @@
= link_to '#', class: 'js-toggle-visibility-link' do = link_to '#', class: 'js-toggle-visibility-link' do
%h6.btn.btn-tiny %h6.btn.btn-tiny
%i.icon-chevron-down %i.icon-chevron-down
%span Per project notifications setting %span Advanced notifications settings
.js-toggle-visibility-container.hide
%ul.well-list.js-toggle-visibility-container.hide %h5 Groups:
- @users_projects.each do |users_project| %ul.well-list
- notification = Notification.new(users_project) - @users_groups.each do |users_group|
%li - notification = Notification.new(users_group)
.row = render 'settings', type: 'project', membership: users_group, notification: notification
.span4
%span %h5 Projects:
= link_to_project(users_project.project) %ul.well-list
.span7 - @users_projects.each do |users_project|
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do - notification = Notification.new(users_project)
= hidden_field_tag :notification_type, 'project', id: dom_id(users_project, 'notification_type') = render 'settings', type: 'project', membership: users_project, notification: notification
= hidden_field_tag :notification_id, users_project.id, id: dom_id(users_project, 'notification_id')
= label_tag do
= radio_button_tag :notification_level, Notification::N_GLOBAL, notification.global?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit'
%span Use global setting
= label_tag do
= radio_button_tag :notification_level, Notification::N_DISABLED, notification.disabled?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit'
%span Disabled
= label_tag do
= radio_button_tag :notification_level, Notification::N_PARTICIPATING, notification.participating?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit'
%span Participating
= label_tag do
= radio_button_tag :notification_level, Notification::N_WATCH, notification.watch?, id: dom_id(users_project, 'notification_level'), class: 'trigger-submit'
%span Watch
.save-status-fixed .save-status-fixed
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130617095603) do ActiveRecord::Schema.define(:version => 20130621195223) do
create_table "deploy_keys_projects", :force => true do |t| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
...@@ -301,11 +301,12 @@ ActiveRecord::Schema.define(:version => 20130617095603) do ...@@ -301,11 +301,12 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
add_index "users", ["username"], :name => "index_users_on_username" add_index "users", ["username"], :name => "index_users_on_username"
create_table "users_groups", :force => true do |t| create_table "users_groups", :force => true do |t|
t.integer "group_access", :null => false t.integer "group_access", :null => false
t.integer "group_id", :null => false t.integer "group_id", :null => false
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.integer "notification_level", :default => 3, :null => false
end end
create_table "users_projects", :force => true do |t| create_table "users_projects", :force => true do |t|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment