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 @@ |
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 | 55 | |
56 | 56 | |
57 | 57 | # |
58 | - # Notification levels | |
59 | - # | |
60 | - N_DISABLED = 0 | |
61 | - N_PARTICIPATING = 1 | |
62 | - N_WATCH = 2 | |
63 | - | |
64 | - # | |
65 | 58 | # Relations |
66 | 59 | # |
67 | 60 | |
... | ... | @@ -116,6 +109,9 @@ class User < ActiveRecord::Base |
116 | 109 | format: { with: Gitlab::Regex.username_regex, |
117 | 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 | 116 | validate :namespace_uniq, if: ->(user) { user.username_changed? } |
121 | 117 | |
... | ... | @@ -216,6 +212,10 @@ class User < ActiveRecord::Base |
216 | 212 | username |
217 | 213 | end |
218 | 214 | |
215 | + def notification | |
216 | + @notification ||= Notification.new(self) | |
217 | + end | |
218 | + | |
219 | 219 | def generate_password |
220 | 220 | if self.force_random_password |
221 | 221 | self.password = self.password_confirmation = Devise.friendly_token.first(8) | ... | ... |
app/views/layouts/profile.html.haml
... | ... | @@ -11,6 +11,8 @@ |
11 | 11 | %i.icon-home |
12 | 12 | = nav_link(path: 'profiles#account') do |
13 | 13 | = link_to "Account", account_profile_path |
14 | + = nav_link(controller: :notifications) do | |
15 | + = link_to "Notifications", profile_notifications_path | |
14 | 16 | = nav_link(controller: :keys) do |
15 | 17 | = link_to keys_path do |
16 | 18 | SSH Keys | ... | ... |
... | ... | @@ -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
... | ... | @@ -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 @@ |
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 @@ |
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 | ... | ... |