BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
9 deletions
+6
-9
projects_controller.rb
app/controllers/projects_controller.rb
+0
-1
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
...
@@ -106,7 +106,6 @@ class ProjectsController < Projects::ApplicationController
if
@membership
if
@membership
@notification_setting
=
current_user
.
notification_settings
.
find_or_initialize_by
(
source:
@project
)
@notification_setting
=
current_user
.
notification_settings
.
find_or_initialize_by
(
source:
@project
)
@notification_setting
.
set_defaults
unless
@notification_setting
.
persisted?
end
end
end
end
...
...
app/models/notification_setting.rb
View file @
ee497599
class
NotificationSetting
<
ActiveRecord
::
Base
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
:user
belongs_to
:source
,
polymorphic:
true
belongs_to
:source
,
polymorphic:
true
...
@@ -8,9 +14,6 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -8,9 +14,6 @@ class NotificationSetting < ActiveRecord::Base
validates
:user_id
,
uniqueness:
{
scope:
[
:source_type
,
:source_id
],
validates
:user_id
,
uniqueness:
{
scope:
[
:source_type
,
:source_id
],
message:
"already exists in source"
,
message:
"already exists in source"
,
allow_nil:
true
}
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_groups
,
->
{
where
(
source_type:
'Namespace'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
...
@@ -19,14 +22,9 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -19,14 +22,9 @@ class NotificationSetting < ActiveRecord::Base
setting
=
find_or_initialize_by
(
source:
source
)
setting
=
find_or_initialize_by
(
source:
source
)
unless
setting
.
persisted?
unless
setting
.
persisted?
setting
.
set_defaults
setting
.
save
setting
.
save
end
end
setting
setting
end
end
def
set_defaults
self
.
level
=
:global
end
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