Commit fe514b17 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Adding groups to notification settings

parent f3cbbfe0
......@@ -4,6 +4,7 @@ class NotificationsController < ApplicationController
def show
@notification = current_user.notification
@users_projects = current_user.users_projects
@users_groups = current_user.users_groups
end
def update
......@@ -12,6 +13,10 @@ def update
@saved = if type == 'global'
current_user.notification_level = params[:notification_level]
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
users_project = current_user.users_projects.find(params[:notification_id])
users_project.notification_level = params[:notification_level]
......
......@@ -11,6 +11,8 @@
#
class UsersGroup < ActiveRecord::Base
include Notifiable
GUEST = 10
REPORTER = 20
DEVELOPER = 30
......
......@@ -13,6 +13,7 @@
class UsersProject < ActiveRecord::Base
include Gitlab::ShellAdapter
include Notifiable
GUEST = 10
REPORTER = 20
......@@ -30,7 +31,6 @@ class UsersProject < ActiveRecord::Base
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, presence: true
validates :notification_level, inclusion: { in: Notification.project_notification_levels }, presence: true
delegate :name, :username, :email, to: :user, prefix: true
......@@ -134,8 +134,4 @@ def project_access_human
def skip_git?
!!@skip_git
end
def notification
@notification ||= Notification.new(self)
end
end
......@@ -148,13 +148,18 @@ def update_team_member(users_project)
# Get project users with WATCH notification level
def project_watchers(project)
# Get project notification settings since it has higher priority
user_ids = project.users_projects.where(notification_level: Notification::N_WATCH).pluck(:user_id)
project_watchers = User.where(id: user_ids)
member_methods = [:users_projects]
member_methods << :users_groups if project.group
# next collect users who use global settings with watch state
user_ids = project.users_projects.where(notification_level: Notification::N_GLOBAL).pluck(:user_id)
project_watchers += User.where(id: user_ids, notification_level: Notification::N_WATCH)
member_methods.each do |member_method|
# Get project notification settings since it has higher priority
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
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 @@
= link_to '#', class: 'js-toggle-visibility-link' do
%h6.btn.btn-tiny
%i.icon-chevron-down
%span Per project notifications setting
%ul.well-list.js-toggle-visibility-container.hide
- @users_projects.each do |users_project|
- notification = Notification.new(users_project)
%li
.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
%span Advanced notifications settings
.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|
- notification = Notification.new(users_project)
= render 'settings', type: 'project', membership: users_project, notification: notification
.save-status-fixed
......
......@@ -11,7 +11,7 @@
#
# 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|
t.integer "deploy_key_id", :null => false
......@@ -301,11 +301,12 @@
add_index "users", ["username"], :name => "index_users_on_username"
create_table "users_groups", :force => true do |t|
t.integer "group_access", :null => false
t.integer "group_id", :null => false
t.integer "user_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "group_access", :null => false
t.integer "group_id", :null => false
t.integer "user_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "notification_level", :default => 3, :null => false
end
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