Commit d55ade16861d0700e302f50945560e8570eddcd7
1 parent
5f14a6bc
Exists in
master
and in
4 other branches
notification scaffold
Showing
10 changed files
with
119 additions
and
7 deletions
Show diff stats
| @@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
| 1 | +class Notification | ||
| 2 | + # | ||
| 3 | + # Notification levels | ||
| 4 | + # | ||
| 5 | + N_DISABLED = 0 | ||
| 6 | + N_PARTICIPATING = 1 | ||
| 7 | + N_WATCH = 2 | ||
| 8 | + | ||
| 9 | + attr_accessor :user | ||
| 10 | + | ||
| 11 | + def self.notification_levels | ||
| 12 | + [N_DISABLED, N_PARTICIPATING, N_WATCH] | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + def initialize(user) | ||
| 16 | + @user = user | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + def disabled? | ||
| 20 | + user.notification_level == N_DISABLED | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | + def participating? | ||
| 24 | + user.notification_level == N_PARTICIPATING | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def watch? | ||
| 28 | + user.notification_level == N_WATCH | ||
| 29 | + end | ||
| 30 | +end |
app/models/user.rb
| @@ -55,13 +55,6 @@ class User < ActiveRecord::Base | @@ -55,13 +55,6 @@ class User < ActiveRecord::Base | ||
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | # | 57 | # |
| 58 | - # Notification levels | ||
| 59 | - # | ||
| 60 | - N_DISABLED = 0 | ||
| 61 | - N_PARTICIPATING = 1 | ||
| 62 | - N_WATCH = 2 | ||
| 63 | - | ||
| 64 | - # | ||
| 65 | # Relations | 58 | # Relations |
| 66 | # | 59 | # |
| 67 | 60 | ||
| @@ -116,6 +109,9 @@ class User < ActiveRecord::Base | @@ -116,6 +109,9 @@ class User < ActiveRecord::Base | ||
| 116 | format: { with: Gitlab::Regex.username_regex, | 109 | format: { with: Gitlab::Regex.username_regex, |
| 117 | message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } | 110 | message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } |
| 118 | 111 | ||
| 112 | + validates :notification_level, | ||
| 113 | + inclusion: { in: Notification.notification_levels }, | ||
| 114 | + presence: true | ||
| 119 | 115 | ||
| 120 | validate :namespace_uniq, if: ->(user) { user.username_changed? } | 116 | validate :namespace_uniq, if: ->(user) { user.username_changed? } |
| 121 | 117 | ||
| @@ -216,6 +212,10 @@ class User < ActiveRecord::Base | @@ -216,6 +212,10 @@ class User < ActiveRecord::Base | ||
| 216 | username | 212 | username |
| 217 | end | 213 | end |
| 218 | 214 | ||
| 215 | + def notification | ||
| 216 | + @notification ||= Notification.new(self) | ||
| 217 | + end | ||
| 218 | + | ||
| 219 | def generate_password | 219 | def generate_password |
| 220 | if self.force_random_password | 220 | if self.force_random_password |
| 221 | self.password = self.password_confirmation = Devise.friendly_token.first(8) | 221 | self.password = self.password_confirmation = Devise.friendly_token.first(8) |
app/views/layouts/profile.html.haml
| @@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
| 11 | %i.icon-home | 11 | %i.icon-home |
| 12 | = nav_link(path: 'profiles#account') do | 12 | = nav_link(path: 'profiles#account') do |
| 13 | = link_to "Account", account_profile_path | 13 | = link_to "Account", account_profile_path |
| 14 | + = nav_link(controller: :notifications) do | ||
| 15 | + = link_to "Notifications", profile_notifications_path | ||
| 14 | = nav_link(controller: :keys) do | 16 | = nav_link(controller: :keys) do |
| 15 | = link_to keys_path do | 17 | = link_to keys_path do |
| 16 | SSH Keys | 18 | SSH Keys |
| @@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
| 1 | +%h3.page_title Setup your notification level | ||
| 2 | +%hr | ||
| 3 | + | ||
| 4 | + | ||
| 5 | += form_tag profile_notifications_path do | ||
| 6 | + | ||
| 7 | + %ul.unstyled | ||
| 8 | + %li | ||
| 9 | + .row | ||
| 10 | + .span3 | ||
| 11 | + %h5 Global | ||
| 12 | + .span9 | ||
| 13 | + = label_tag do | ||
| 14 | + = radio_button_tag :notification_level, Notification::N_DISABLED, @notification.disabled? | ||
| 15 | + %span Disabled | ||
| 16 | + | ||
| 17 | + = label_tag do | ||
| 18 | + = radio_button_tag :notification_level, Notification::N_PARTICIPATING, @notification.participating? | ||
| 19 | + %span Participating | ||
| 20 | + | ||
| 21 | + = label_tag do | ||
| 22 | + = radio_button_tag :notification_level, Notification::N_WATCH, @notification.watch? | ||
| 23 | + %span Watch | ||
| 24 | + | ||
| 25 | + .form-actions | ||
| 26 | + = submit_tag 'Save', class: 'btn btn-save' |
config/routes.rb
| @@ -110,6 +110,8 @@ Gitlab::Application.routes.draw do | @@ -110,6 +110,8 @@ Gitlab::Application.routes.draw do | ||
| 110 | put :reset_private_token | 110 | put :reset_private_token |
| 111 | put :update_username | 111 | put :update_username |
| 112 | end | 112 | end |
| 113 | + | ||
| 114 | + resource :notifications | ||
| 113 | end | 115 | end |
| 114 | 116 | ||
| 115 | resources :keys | 117 | resources :keys |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +# Specs in this file have access to a helper object that includes | ||
| 4 | +# the NotificationsHelper. For example: | ||
| 5 | +# | ||
| 6 | +# describe NotificationsHelper do | ||
| 7 | +# describe "string concat" do | ||
| 8 | +# it "concats two strings with spaces" do | ||
| 9 | +# helper.concat_strings("this","that").should == "this that" | ||
| 10 | +# end | ||
| 11 | +# end | ||
| 12 | +# end | ||
| 13 | +describe NotificationsHelper do | ||
| 14 | + pending "add some examples to (or delete) #{__FILE__}" | ||
| 15 | +end |
| @@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe "Notifications" do | ||
| 4 | + describe "GET /notifications" do | ||
| 5 | + it "works! (now write some real specs)" do | ||
| 6 | + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers | ||
| 7 | + get notifications_path | ||
| 8 | + response.status.should be(200) | ||
| 9 | + end | ||
| 10 | + end | ||
| 11 | +end |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +require "spec_helper" | ||
| 2 | + | ||
| 3 | +describe NotificationsController do | ||
| 4 | + describe "routing" do | ||
| 5 | + it "routes to #show" do | ||
| 6 | + get("/profile/notifications").should route_to("notifications#show") | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + it "routes to #update" do | ||
| 10 | + put("/profile/notifications").should route_to("notifications#update") | ||
| 11 | + end | ||
| 12 | + end | ||
| 13 | +end |