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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0e331206
Commit
0e331206
authored
Sep 18, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BlocksJsonSerialization model concern and include it in User
parent
4d9f353a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
0 deletions
+33
-0
app/models/concerns/blocks_json_serialization.rb
app/models/concerns/blocks_json_serialization.rb
+14
-0
app/models/user.rb
app/models/user.rb
+1
-0
spec/models/concerns/blocks_json_serialization_spec.rb
spec/models/concerns/blocks_json_serialization_spec.rb
+17
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-0
No files found.
app/models/concerns/blocks_json_serialization.rb
0 → 100644
View file @
0e331206
# Overrides `as_json` and `to_json` to raise an exception when called in order
# to prevent accidentally exposing attributes
#
# Not that that would ever happen... but just in case.
module
BlocksJsonSerialization
extend
ActiveSupport
::
Concern
def
to_json
raise
SecurityError
,
"JSON serialization has been disabled on
#{
self
.
class
.
name
}
"
end
alias_method
:as_json
,
:to_json
end
app/models/user.rb
View file @
0e331206
...
...
@@ -18,6 +18,7 @@ class User < ActiveRecord::Base
include
CreatedAtFilterable
include
IgnorableColumn
include
BulkMemberAccessLoad
include
BlocksJsonSerialization
prepend
EE
::
GeoAwareAvatar
prepend
EE
::
User
...
...
spec/models/concerns/blocks_json_serialization_spec.rb
0 → 100644
View file @
0e331206
require
'rails_helper'
describe
BlocksJsonSerialization
do
DummyModel
=
Class
.
new
do
include
BlocksJsonSerialization
end
it
'blocks as_json'
do
expect
{
DummyModel
.
new
.
to_json
}
.
to
raise_error
(
SecurityError
,
"JSON serialization has been disabled on DummyModel"
)
end
it
'blocks to_json'
do
expect
{
DummyModel
.
new
.
to_json
}
.
to
raise_error
(
SecurityError
,
"JSON serialization has been disabled on DummyModel"
)
end
end
spec/models/user_spec.rb
View file @
0e331206
...
...
@@ -12,6 +12,7 @@ describe User do
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Sortable
)
}
it
{
is_expected
.
to
include_module
(
TokenAuthenticatable
)
}
it
{
is_expected
.
to
include_module
(
BlocksJsonSerialization
)
}
end
describe
'delegations'
do
...
...
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