Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
ee497599
Commit
ee497599
authored
Apr 08, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use default_value_for to set default NotificationSetting#level
parent
069724ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
9 deletions
+6
-9
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+0
-1
app/models/notification_setting.rb
app/models/notification_setting.rb
+6
-8
No files found.
app/controllers/projects_controller.rb
View file @
ee497599
...
...
@@ -106,7 +106,6 @@ class ProjectsController < Projects::ApplicationController
if
@membership
@notification_setting
=
current_user
.
notification_settings
.
find_or_initialize_by
(
source:
@project
)
@notification_setting
.
set_defaults
unless
@notification_setting
.
persisted?
end
end
...
...
app/models/notification_setting.rb
View file @
ee497599
class
NotificationSetting
<
ActiveRecord
::
Base
# Notification level
# Note: When adding an option, it MUST go on the end of the array.
enum
level:
[
:disabled
,
:participating
,
:watch
,
:global
,
:mention
]
default_value_for
:level
,
NotificationSetting
.
levels
[
:global
]
belongs_to
:user
belongs_to
:source
,
polymorphic:
true
...
...
@@ -8,9 +14,6 @@ class NotificationSetting < ActiveRecord::Base
validates
:user_id
,
uniqueness:
{
scope:
[
:source_type
,
:source_id
],
message:
"already exists in source"
,
allow_nil:
true
}
# Notification level
# Note: When adding an option, it MUST go on the end of the array.
enum
level:
[
:disabled
,
:participating
,
:watch
,
:global
,
:mention
]
scope
:for_groups
,
->
{
where
(
source_type:
'Namespace'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
...
...
@@ -19,14 +22,9 @@ class NotificationSetting < ActiveRecord::Base
setting
=
find_or_initialize_by
(
source:
source
)
unless
setting
.
persisted?
setting
.
set_defaults
setting
.
save
end
setting
end
def
set_defaults
self
.
level
=
:global
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment