summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-17 12:26:32 -0300
committerFelipe Artur <felipefac@gmail.com>2016-06-17 12:33:11 -0300
commitab236c76247d83c190b148acbffa48f244414553 (patch)
tree69b17bdec6f52d96d1e4d7a807f3432263ef3cd4 /app
parenta4b078bfb8b99a9852eb55abd498d65a374375e3 (diff)
downloadgitlab-ce-ab236c76247d83c190b148acbffa48f244414553.tar.gz
Allow users to set custom notifications in projects they don't own and several fixes to code
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/notifications_dropdown.js.coffee8
-rw-r--r--app/controllers/notification_settings_controller.rb14
-rw-r--r--app/views/profiles/notifications/_group_settings.html.haml2
-rw-r--r--app/views/profiles/notifications/_project_settings.html.haml2
-rw-r--r--app/views/profiles/notifications/show.html.haml10
-rw-r--r--app/views/projects/_home_panel.html.haml2
-rw-r--r--app/views/shared/notifications/buttons/_button.html.haml (renamed from app/views/notifications/buttons/_notifications.html.haml)2
-rw-r--r--app/views/shared/projects/_custom_notifications.html.haml26
-rw-r--r--app/views/shared/projects/_notification_dropdown.html.haml9
9 files changed, 22 insertions, 53 deletions
diff --git a/app/assets/javascripts/notifications_dropdown.js.coffee b/app/assets/javascripts/notifications_dropdown.js.coffee
index c13010f56ec..74d2298c1fa 100644
--- a/app/assets/javascripts/notifications_dropdown.js.coffee
+++ b/app/assets/javascripts/notifications_dropdown.js.coffee
@@ -9,14 +9,14 @@ class @NotificationsDropdown
notificationLevel = $(@).data 'notification-level'
label = $(@).data 'notification-title'
- form = $(this).parents('form:first')
+ form = $(this).parents('.notification-form:first')
form.find('.js-notification-loading').toggleClass 'fa-bell fa-spin fa-spinner'
form.find('#notification_setting_level').val(notificationLevel)
- form.submit();
+ form.submit()
$(document)
- .off 'ajax:success', '#notification-form'
- .on 'ajax:success', '#notification-form', (e, data) ->
+ .off 'ajax:success', '.notification-form'
+ .on 'ajax:success', '.notification-form', (e, data) ->
if data.saved
new Flash('Notification settings saved', 'notice')
$(e.currentTarget).closest('.notification-dropdown').replaceWith(data.html)
diff --git a/app/controllers/notification_settings_controller.rb b/app/controllers/notification_settings_controller.rb
index 5d425ad8420..acda174c229 100644
--- a/app/controllers/notification_settings_controller.rb
+++ b/app/controllers/notification_settings_controller.rb
@@ -2,12 +2,16 @@ class NotificationSettingsController < ApplicationController
before_action :authenticate_user!
def create
- project = current_user.projects.find(params[:project][:id])
+ project = Project.find(params[:project][:id])
- @notification_setting = current_user.notification_settings_for(project)
- @saved = @notification_setting.update_attributes(notification_setting_params)
+ if can?(current_user, :read_project, project)
+ @notification_setting = current_user.notification_settings_for(project)
+ @saved = @notification_setting.update_attributes(notification_setting_params)
- render_response
+ render_response
+ else
+ render_404
+ end
end
def update
@@ -21,7 +25,7 @@ class NotificationSettingsController < ApplicationController
def render_response
render json: {
- html: view_to_html_string("notifications/buttons/_notifications", notification_setting: @notification_setting),
+ html: view_to_html_string("shared/notifications/buttons/_button", notification_setting: @notification_setting),
saved: @saved
}
end
diff --git a/app/views/profiles/notifications/_group_settings.html.haml b/app/views/profiles/notifications/_group_settings.html.haml
index 04becd5d860..80c165db01b 100644
--- a/app/views/profiles/notifications/_group_settings.html.haml
+++ b/app/views/profiles/notifications/_group_settings.html.haml
@@ -9,4 +9,4 @@
= link_to group.name, group_path(group)
.pull-right
- = render 'notifications/buttons/notifications', notification_setting: setting
+ = render '/shared/notifications/buttons/button', notification_setting: setting
diff --git a/app/views/profiles/notifications/_project_settings.html.haml b/app/views/profiles/notifications/_project_settings.html.haml
index 664a17418db..e1a06a75e0c 100644
--- a/app/views/profiles/notifications/_project_settings.html.haml
+++ b/app/views/profiles/notifications/_project_settings.html.haml
@@ -9,4 +9,4 @@
= link_to_project(project)
.pull-right
- = render 'notifications/buttons/notifications', notification_setting: setting
+ = render '/shared/notifications/buttons/button', notification_setting: setting
diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml
index cfbb4d79da2..cd0112d6278 100644
--- a/app/views/profiles/notifications/show.html.haml
+++ b/app/views/profiles/notifications/show.html.haml
@@ -25,11 +25,11 @@
= f.label :notification_email, class: "label-light"
= f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2"
- = label_tag :global_notification_level, "Global notification level", class: "label-light"
- %br
- .clearfix
- .form-group.pull-left
- = render 'notifications/buttons/notifications', notification_setting: @global_notification_setting, left_align: true
+ = label_tag :global_notification_level, "Global notification level", class: "label-light"
+ %br
+ .clearfix
+ .form-group.pull-left
+ = render '/shared/notifications/buttons/button', notification_setting: @global_notification_setting, left_align: true
.clearfix
diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml
index df725d81a39..7dc762486e4 100644
--- a/app/views/projects/_home_panel.html.haml
+++ b/app/views/projects/_home_panel.html.haml
@@ -32,7 +32,7 @@
.project-repo-buttons.btn-group.project-right-buttons
= render "projects/buttons/download"
= render 'projects/buttons/dropdown'
- = render 'notifications/buttons/notifications', notification_setting: @notification_setting
+ = render '/shared/notifications/buttons/button', notification_setting: @notification_setting
:javascript
new Star();
diff --git a/app/views/notifications/buttons/_notifications.html.haml b/app/views/shared/notifications/buttons/_button.html.haml
index f97cde0ae0c..ff1cf966a9b 100644
--- a/app/views/notifications/buttons/_notifications.html.haml
+++ b/app/views/shared/notifications/buttons/_button.html.haml
@@ -1,7 +1,7 @@
- left_align = local_assigns[:left_align]
- if notification_setting
.dropdown.notification-dropdown.pull-right
- = form_for notification_setting, remote: true, html: { class: "inline", id: "notification-form" } do |f|
+ = form_for notification_setting, remote: true, html: { class: "inline notification-form" } do |f|
= hidden_setting_source_input(notification_setting)
= f.hidden_field :level, class: "notification_setting_level"
.js-notification-toggle-btns
diff --git a/app/views/shared/projects/_custom_notifications.html.haml b/app/views/shared/projects/_custom_notifications.html.haml
deleted file mode 100644
index ec4bad4ba3a..00000000000
--- a/app/views/shared/projects/_custom_notifications.html.haml
+++ /dev/null
@@ -1,26 +0,0 @@
-#custom-notifications-modal.modal.fade{ tabindex: "-1", role: "dialog", aria: { labelledby: "custom-notifications-title" } }
- .modal-dialog
- .modal-content
- .modal-header
- %button.close{ type: "button", data: { dismiss: "modal" }, aria: { label: "close" } }
- %span{ aria: { hidden: "true" } } ×
- %h4#custom-notifications-title.modal-title
- Custom notification events
- .modal-body
- .container-fluid
- = form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), method: :patch, html: { class: "custom-notifications-form" } do |f|
- .row
- .col-lg-3
- %h4.prepend-top-0
- Notification events
- .col-lg-9
- - NotificationSetting::EMAIL_EVENTS.each do |event, index|
- = index
- .form-group
- .checkbox{ class: ("prepend-top-0" if index == 0) }
- %label{ for: "events_#{event}" }
- = check_box("notification_setting", event, {id: "events_#{event}", class: "js-custom-notification-event"})
-
- %strong
- = event.to_s.humanize
- = icon("spinner spin", class: "custom-notification-event-loading")
diff --git a/app/views/shared/projects/_notification_dropdown.html.haml b/app/views/shared/projects/_notification_dropdown.html.haml
deleted file mode 100644
index 103d5f12f5c..00000000000
--- a/app/views/shared/projects/_notification_dropdown.html.haml
+++ /dev/null
@@ -1,9 +0,0 @@
-%ul.dropdown-menu.dropdown-menu-no-wrap.dropdown-menu-align-right.dropdown-menu-selectable.dropdown-menu-large{ role: "menu" }
- - NotificationSetting.levels.each do |level|
- - if level.first != "custom"
- = notification_list_item(level.first, @notification_setting)
- %li.divider
- %li
- %a.update-notification{ href: "#", role: "button", data: { toggle: "modal", target: "#custom-notifications-modal", notification_level: "custom", notification_title: "Custom" } }
- %strong.dropdown-menu-inner-title Custom
- %span.dropdown-menu-inner-content= notification_description("custom")