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
57a5544f
Commit
57a5544f
authored
Jul 28, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove events column from notification settings
This was migrated to separate columns in 9.4, and now just needs to be removed for real.
parent
4c89929f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
42 deletions
+29
-42
notification_setting.rb
app/models/notification_setting.rb
+5
-29
33620-remove-events-from-notification_settings.yml
...leased/33620-remove-events-from-notification_settings.yml
+4
-0
20170728101014_remove_events_from_notification_settings.rb
...0170728101014_remove_events_from_notification_settings.rb
+9
-0
schema.rb
db/schema.rb
+1
-2
notification_settings.rb
spec/factories/notification_settings.rb
+0
-1
notification_setting_spec.rb
spec/models/notification_setting_spec.rb
+4
-8
notification_settings_spec.rb
spec/requests/api/notification_settings_spec.rb
+2
-2
spec_helper.rb
spec/spec_helper.rb
+4
-0
No files found.
app/models/notification_setting.rb
View file @
57a5544f
class
NotificationSetting
<
ActiveRecord
::
Base
class
NotificationSetting
<
ActiveRecord
::
Base
include
IgnorableColumn
ignore_column
:events
enum
level:
{
global:
3
,
watch:
2
,
mention:
4
,
participating:
1
,
disabled:
0
,
custom:
5
}
enum
level:
{
global:
3
,
watch:
2
,
mention:
4
,
participating:
1
,
disabled:
0
,
custom:
5
}
default_value_for
:level
,
NotificationSetting
.
levels
[
:global
]
default_value_for
:level
,
NotificationSetting
.
levels
[
:global
]
...
@@ -41,9 +45,6 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -41,9 +45,6 @@ class NotificationSetting < ActiveRecord::Base
:success_pipeline
:success_pipeline
].
freeze
].
freeze
store
:events
,
coder:
JSON
before_save
:convert_events
def
self
.
find_or_create_for
(
source
)
def
self
.
find_or_create_for
(
source
)
setting
=
find_or_initialize_by
(
source:
source
)
setting
=
find_or_initialize_by
(
source:
source
)
...
@@ -54,42 +55,17 @@ class NotificationSetting < ActiveRecord::Base
...
@@ -54,42 +55,17 @@ class NotificationSetting < ActiveRecord::Base
setting
setting
end
end
# 1. Check if this event has a value stored in its database column.
# 2. If it does, return that value.
# 3. If it doesn't (the value is nil), return the value from the serialized
# JSON hash in `events`.
(
EMAIL_EVENTS
-
[
:failed_pipeline
]).
each
do
|
event
|
define_method
(
event
)
do
bool
=
super
()
bool
.
nil?
?
!!
events
[
event
]
:
bool
end
alias_method
:"
#{
event
}
?"
,
event
end
# Allow people to receive failed pipeline notifications if they already have
# Allow people to receive failed pipeline notifications if they already have
# custom notifications enabled, as these are more like mentions than the other
# custom notifications enabled, as these are more like mentions than the other
# custom settings.
# custom settings.
def
failed_pipeline
def
failed_pipeline
bool
=
super
bool
=
super
bool
=
events
[
:failed_pipeline
]
if
bool
.
nil?
bool
.
nil?
||
bool
bool
.
nil?
||
bool
end
end
alias_method
:failed_pipeline?
,
:failed_pipeline
alias_method
:failed_pipeline?
,
:failed_pipeline
def
event_enabled?
(
event
)
def
event_enabled?
(
event
)
respond_to?
(
event
)
&&
public_send
(
event
)
respond_to?
(
event
)
&&
!!
public_send
(
event
)
end
def
convert_events
return
if
events_before_type_cast
.
nil?
EMAIL_EVENTS
.
each
do
|
event
|
write_attribute
(
event
,
public_send
(
event
))
end
write_attribute
(
:events
,
nil
)
end
end
end
end
changelogs/unreleased/33620-remove-events-from-notification_settings.yml
0 → 100644
View file @
57a5544f
---
title
:
Remove events column from notification settings table
merge_request
:
author
:
db/post_migrate/20170728101014_remove_events_from_notification_settings.rb
0 → 100644
View file @
57a5544f
class
RemoveEventsFromNotificationSettings
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
remove_column
:notification_settings
,
:events
,
:text
end
end
db/schema.rb
View file @
57a5544f
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017072
5145659
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017072
8101014
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -981,7 +981,6 @@ ActiveRecord::Schema.define(version: 20170725145659) do
...
@@ -981,7 +981,6 @@ ActiveRecord::Schema.define(version: 20170725145659) do
t
.
integer
"level"
,
default:
0
,
null:
false
t
.
integer
"level"
,
default:
0
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
text
"events"
t
.
boolean
"new_note"
t
.
boolean
"new_note"
t
.
boolean
"new_issue"
t
.
boolean
"new_issue"
t
.
boolean
"reopen_issue"
t
.
boolean
"reopen_issue"
...
...
spec/factories/notification_settings.rb
View file @
57a5544f
...
@@ -3,6 +3,5 @@ FactoryGirl.define do
...
@@ -3,6 +3,5 @@ FactoryGirl.define do
source
factory: :empty_project
source
factory: :empty_project
user
user
level
3
level
3
events
[]
end
end
end
end
spec/models/notification_setting_spec.rb
View file @
57a5544f
...
@@ -63,24 +63,20 @@ RSpec.describe NotificationSetting do
...
@@ -63,24 +63,20 @@ RSpec.describe NotificationSetting do
end
end
end
end
describe
'event_enabled?'
do
describe
'
#
event_enabled?'
do
before
do
before
do
subject
.
update!
(
user:
create
(
:user
))
subject
.
update!
(
user:
create
(
:user
))
end
end
context
'for an event with a matching column name'
do
context
'for an event with a matching column name'
do
before
do
subject
.
update!
(
events:
{
new_note:
true
}.
to_json
)
end
it
'returns the value of the column'
do
it
'returns the value of the column'
do
subject
.
update!
(
new_note:
fals
e
)
subject
.
update!
(
new_note:
tru
e
)
expect
(
subject
.
event_enabled?
(
:new_note
)).
to
be
(
fals
e
)
expect
(
subject
.
event_enabled?
(
:new_note
)).
to
be
(
tru
e
)
end
end
context
'when the column has a nil value'
do
context
'when the column has a nil value'
do
it
'returns
the value from the events hash
'
do
it
'returns
false
'
do
expect
(
subject
.
event_enabled?
(
:new_note
)).
to
be
(
false
)
expect
(
subject
.
event_enabled?
(
:new_note
)).
to
be
(
false
)
end
end
end
end
...
...
spec/requests/api/notification_settings_spec.rb
View file @
57a5544f
...
@@ -72,8 +72,8 @@ describe API::NotificationSettings do
...
@@ -72,8 +72,8 @@ describe API::NotificationSettings do
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'level'
]).
to
eq
(
user
.
reload
.
notification_settings_for
(
project
).
level
)
expect
(
json_response
[
'level'
]).
to
eq
(
user
.
reload
.
notification_settings_for
(
project
).
level
)
expect
(
json_response
[
'events'
][
'new_note'
]).
to
eq
(
true
)
expect
(
json_response
[
'events'
][
'new_note'
]).
to
be_truthy
expect
(
json_response
[
'events'
][
'new_issue'
]).
to
eq
(
false
)
expect
(
json_response
[
'events'
][
'new_issue'
]).
to
be_falsey
end
end
end
end
...
...
spec/spec_helper.rb
View file @
57a5544f
...
@@ -129,10 +129,14 @@ RSpec.configure do |config|
...
@@ -129,10 +129,14 @@ RSpec.configure do |config|
config
.
before
(
:example
,
:migration
)
do
config
.
before
(
:example
,
:migration
)
do
ActiveRecord
::
Migrator
ActiveRecord
::
Migrator
.
migrate
(
migrations_paths
,
previous_migration
.
version
)
.
migrate
(
migrations_paths
,
previous_migration
.
version
)
ActiveRecord
::
Base
.
descendants
.
each
(
&
:reset_column_information
)
end
end
config
.
after
(
:example
,
:migration
)
do
config
.
after
(
:example
,
:migration
)
do
ActiveRecord
::
Migrator
.
migrate
(
migrations_paths
)
ActiveRecord
::
Migrator
.
migrate
(
migrations_paths
)
ActiveRecord
::
Base
.
descendants
.
each
(
&
:reset_column_information
)
end
end
config
.
around
(
:each
,
:nested_groups
)
do
|
example
|
config
.
around
(
:each
,
:nested_groups
)
do
|
example
|
...
...
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