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
71e7b398
Commit
71e7b398
authored
Mar 29, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor creating notification setting with defaults
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
630c86a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
projects_controller.rb
app/controllers/projects_controller.rb
+1
-6
member.rb
app/models/member.rb
+1
-6
notification_setting.rb
app/models/notification_setting.rb
+11
-0
No files found.
app/controllers/projects_controller.rb
View file @
71e7b398
...
...
@@ -102,12 +102,7 @@ class ProjectsController < Projects::ApplicationController
@membership
=
@project
.
team
.
find_member
(
current_user
.
id
)
if
@membership
@notification_setting
=
current_user
.
notification_settings
.
find_or_initialize_by
(
source:
@project
)
unless
@notification_setting
.
persisted?
@notification_setting
.
set_defaults
@notification_setting
.
save
end
@notification_setting
=
current_user
.
notification_settings
.
find_or_create_for
(
@project
)
end
end
...
...
app/models/member.rb
View file @
71e7b398
...
...
@@ -163,12 +163,7 @@ class Member < ActiveRecord::Base
end
def
create_notification_setting
notification_setting
=
user
.
notification_settings
.
find_or_initialize_by
(
source:
source
)
unless
notification_setting
.
persisted?
notification_setting
.
set_defaults
notification_setting
.
save
end
user
.
notification_setting
.
find_or_create_for
(
source
)
end
def
notification_setting
...
...
app/models/notification_setting.rb
View file @
71e7b398
...
...
@@ -15,6 +15,17 @@ class NotificationSetting < ActiveRecord::Base
scope
:for_groups
,
->
{
where
(
source_type:
'Namespace'
)
}
scope
:for_projects
,
->
{
where
(
source_type:
'Project'
)
}
def
self
.
find_or_create_for
(
source
)
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
...
...
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