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)
member_methods = [:users_projects]
member_methods << :users_groups if project.group
member_methods.each do |member_method|
# Get project notification settings since it has higher priority # Get project notification settings since it has higher priority
user_ids = project.users_projects.where(notification_level: Notification::N_WATCH).pluck(:user_id) user_ids = project.send(member_method).where(notification_level: Notification::N_WATCH).pluck(:user_id)
project_watchers = User.where(id: user_ids) project_watchers = User.where(id: user_ids)
# next collect users who use global settings with watch state # next collect users who use global settings with watch state
user_ids = project.users_projects.where(notification_level: Notification::N_GLOBAL).pluck(:user_id) 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) 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:
%ul.well-list
- @users_groups.each do |users_group|
- notification = Notification.new(users_group)
= render 'settings', type: 'project', membership: users_group, notification: notification
%h5 Projects:
%ul.well-list
- @users_projects.each do |users_project| - @users_projects.each do |users_project|
- notification = Notification.new(users_project) - notification = Notification.new(users_project)
%li = render 'settings', type: 'project', membership: users_project, notification: notification
.row
.span4
%span
= link_to_project(users_project.project)
.span7
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do
= hidden_field_tag :notification_type, 'project', id: dom_id(users_project, 'notification_type')
= 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
...@@ -306,6 +306,7 @@ ActiveRecord::Schema.define(:version => 20130617095603) do ...@@ -306,6 +306,7 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
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