summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/notifications_controller.rb11
-rw-r--r--app/helpers/notifications_helper.rb2
-rw-r--r--app/models/notification.rb30
-rw-r--r--app/models/user.rb14
-rw-r--r--app/views/layouts/profile.html.haml2
-rw-r--r--app/views/notifications/show.html.haml26
-rw-r--r--config/routes.rb2
-rw-r--r--spec/helpers/notifications_helper_spec.rb15
-rw-r--r--spec/requests/notifications_spec.rb11
-rw-r--r--spec/routing/notifications_routing_spec.rb13
10 files changed, 119 insertions, 7 deletions
diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
new file mode 100644
index 00000000000..d2edb6a69e8
--- /dev/null
+++ b/app/controllers/notifications_controller.rb
@@ -0,0 +1,11 @@
+class NotificationsController < ApplicationController
+ layout 'profile'
+
+ def show
+ @notification = current_user.notification
+ end
+
+ def update
+ @notification = current_user.notification
+ end
+end
diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb
new file mode 100644
index 00000000000..7342393a707
--- /dev/null
+++ b/app/helpers/notifications_helper.rb
@@ -0,0 +1,2 @@
+module NotificationsHelper
+end
diff --git a/app/models/notification.rb b/app/models/notification.rb
new file mode 100644
index 00000000000..bfd1e2cff56
--- /dev/null
+++ b/app/models/notification.rb
@@ -0,0 +1,30 @@
+class Notification
+ #
+ # Notification levels
+ #
+ N_DISABLED = 0
+ N_PARTICIPATING = 1
+ N_WATCH = 2
+
+ attr_accessor :user
+
+ def self.notification_levels
+ [N_DISABLED, N_PARTICIPATING, N_WATCH]
+ end
+
+ def initialize(user)
+ @user = user
+ end
+
+ def disabled?
+ user.notification_level == N_DISABLED
+ end
+
+ def participating?
+ user.notification_level == N_PARTICIPATING
+ end
+
+ def watch?
+ user.notification_level == N_WATCH
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 4718e24d272..dcbf58123fe 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -55,13 +55,6 @@ class User < ActiveRecord::Base
#
- # Notification levels
- #
- N_DISABLED = 0
- N_PARTICIPATING = 1
- N_WATCH = 2
-
- #
# Relations
#
@@ -116,6 +109,9 @@ class User < ActiveRecord::Base
format: { with: Gitlab::Regex.username_regex,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
+ validates :notification_level,
+ inclusion: { in: Notification.notification_levels },
+ presence: true
validate :namespace_uniq, if: ->(user) { user.username_changed? }
@@ -216,6 +212,10 @@ class User < ActiveRecord::Base
username
end
+ def notification
+ @notification ||= Notification.new(self)
+ end
+
def generate_password
if self.force_random_password
self.password = self.password_confirmation = Devise.friendly_token.first(8)
diff --git a/app/views/layouts/profile.html.haml b/app/views/layouts/profile.html.haml
index 611063e8c99..a7225baa9e4 100644
--- a/app/views/layouts/profile.html.haml
+++ b/app/views/layouts/profile.html.haml
@@ -11,6 +11,8 @@
%i.icon-home
= nav_link(path: 'profiles#account') do
= link_to "Account", account_profile_path
+ = nav_link(controller: :notifications) do
+ = link_to "Notifications", profile_notifications_path
= nav_link(controller: :keys) do
= link_to keys_path do
SSH Keys
diff --git a/app/views/notifications/show.html.haml b/app/views/notifications/show.html.haml
new file mode 100644
index 00000000000..7ceb1926f1d
--- /dev/null
+++ b/app/views/notifications/show.html.haml
@@ -0,0 +1,26 @@
+%h3.page_title Setup your notification level
+%hr
+
+
+= form_tag profile_notifications_path do
+
+ %ul.unstyled
+ %li
+ .row
+ .span3
+ %h5 Global
+ .span9
+ = label_tag do
+ = radio_button_tag :notification_level, Notification::N_DISABLED, @notification.disabled?
+ %span Disabled
+
+ = label_tag do
+ = radio_button_tag :notification_level, Notification::N_PARTICIPATING, @notification.participating?
+ %span Participating
+
+ = label_tag do
+ = radio_button_tag :notification_level, Notification::N_WATCH, @notification.watch?
+ %span Watch
+
+ .form-actions
+ = submit_tag 'Save', class: 'btn btn-save'
diff --git a/config/routes.rb b/config/routes.rb
index 25eb75a11fc..61a604b954f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -110,6 +110,8 @@ Gitlab::Application.routes.draw do
put :reset_private_token
put :update_username
end
+
+ resource :notifications
end
resources :keys
diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb
new file mode 100644
index 00000000000..f97959ee8f4
--- /dev/null
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the NotificationsHelper. For example:
+#
+# describe NotificationsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe NotificationsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/requests/notifications_spec.rb b/spec/requests/notifications_spec.rb
new file mode 100644
index 00000000000..07db7c05987
--- /dev/null
+++ b/spec/requests/notifications_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Notifications" do
+ describe "GET /notifications" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get notifications_path
+ response.status.should be(200)
+ end
+ end
+end
diff --git a/spec/routing/notifications_routing_spec.rb b/spec/routing/notifications_routing_spec.rb
new file mode 100644
index 00000000000..6880d2819d1
--- /dev/null
+++ b/spec/routing/notifications_routing_spec.rb
@@ -0,0 +1,13 @@
+require "spec_helper"
+
+describe NotificationsController do
+ describe "routing" do
+ it "routes to #show" do
+ get("/profile/notifications").should route_to("notifications#show")
+ end
+
+ it "routes to #update" do
+ put("/profile/notifications").should route_to("notifications#update")
+ end
+ end
+end