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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
03dba012
Commit
03dba012
authored
Nov 09, 2018
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Extract code into IssueBoardEntity"
This reverts commit
8c126525
.
parent
ab61bee3
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
34 additions
and
118 deletions
+34
-118
app/controllers/boards/issues_controller.rb
app/controllers/boards/issues_controller.rb
+11
-5
app/models/issue.rb
app/models/issue.rb
+14
-0
app/serializers/README.md
app/serializers/README.md
+2
-2
app/serializers/issue_board_entity.rb
app/serializers/issue_board_entity.rb
+0
-52
app/serializers/issue_serializer.rb
app/serializers/issue_serializer.rb
+2
-4
app/serializers/label_entity.rb
app/serializers/label_entity.rb
+0
-4
spec/controllers/boards/issues_controller_spec.rb
spec/controllers/boards/issues_controller_spec.rb
+3
-3
spec/fixtures/api/schemas/entities/issue_boards.json
spec/fixtures/api/schemas/entities/issue_boards.json
+0
-15
spec/models/concerns/awardable_spec.rb
spec/models/concerns/awardable_spec.rb
+2
-2
spec/serializers/issue_board_entity_spec.rb
spec/serializers/issue_board_entity_spec.rb
+0
-23
spec/serializers/issue_serializer_spec.rb
spec/serializers/issue_serializer_spec.rb
+0
-8
No files found.
app/controllers/boards/issues_controller.rb
View file @
03dba012
...
@@ -100,12 +100,18 @@ module Boards
...
@@ -100,12 +100,18 @@ module Boards
.
merge
(
board_id:
params
[
:board_id
],
list_id:
params
[
:list_id
],
request:
request
)
.
merge
(
board_id:
params
[
:board_id
],
list_id:
params
[
:list_id
],
request:
request
)
end
end
def
serializer
IssueSerializer
.
new
(
current_user:
current_user
)
end
def
serialize_as_json
(
resource
)
def
serialize_as_json
(
resource
)
serializer
.
represent
(
resource
,
serializer:
'board'
,
include_full_project_path:
board
.
group_board?
)
resource
.
as_json
(
only:
[
:id
,
:iid
,
:project_id
,
:title
,
:confidential
,
:due_date
,
:relative_position
,
:weight
],
labels:
true
,
issue_endpoints:
true
,
include_full_project_path:
board
.
group_board?
,
include:
{
project:
{
only:
[
:id
,
:path
]
},
assignees:
{
only:
[
:id
,
:name
,
:username
],
methods:
[
:avatar_url
]
},
milestone:
{
only:
[
:id
,
:title
]
}
}
)
end
end
def
whitelist_query_limiting
def
whitelist_query_limiting
...
...
app/models/issue.rb
View file @
03dba012
...
@@ -231,6 +231,20 @@ class Issue < ActiveRecord::Base
...
@@ -231,6 +231,20 @@ class Issue < ActiveRecord::Base
def
as_json
(
options
=
{})
def
as_json
(
options
=
{})
super
(
options
).
tap
do
|
json
|
super
(
options
).
tap
do
|
json
|
if
options
.
key?
(
:issue_endpoints
)
&&
project
url_helper
=
Gitlab
::
Routing
.
url_helpers
issue_reference
=
options
[
:include_full_project_path
]
?
to_reference
(
full:
true
)
:
to_reference
json
.
merge!
(
reference_path:
issue_reference
,
real_path:
url_helper
.
project_issue_path
(
project
,
self
),
issue_sidebar_endpoint:
url_helper
.
project_issue_path
(
project
,
self
,
format: :json
,
serializer:
'sidebar'
),
toggle_subscription_endpoint:
url_helper
.
toggle_subscription_project_issue_path
(
project
,
self
),
assignable_labels_endpoint:
url_helper
.
project_labels_path
(
project
,
format: :json
,
include_ancestor_groups:
true
)
)
end
if
options
.
key?
(
:labels
)
if
options
.
key?
(
:labels
)
json
[
:labels
]
=
labels
.
as_json
(
json
[
:labels
]
=
labels
.
as_json
(
project:
project
,
project:
project
,
...
...
app/serializers/README.md
View file @
03dba012
...
@@ -180,7 +180,7 @@ def index
...
@@ -180,7 +180,7 @@ def index
render
json:
MyResourceSerializer
render
json:
MyResourceSerializer
.
new
(
current_user:
@current_user
)
.
new
(
current_user:
@current_user
)
.
represent_details
(
@project
.
resources
)
.
represent_details
(
@project
.
resources
)
e
nd
nd
end
end
```
```
...
@@ -196,7 +196,7 @@ def index
...
@@ -196,7 +196,7 @@ def index
.
represent_details
(
@project
.
resources
),
.
represent_details
(
@project
.
resources
),
count:
@project
.
resources
.
count
count:
@project
.
resources
.
count
}
}
e
nd
nd
end
end
```
```
...
...
app/serializers/issue_board_entity.rb
deleted
100644 → 0
View file @
ab61bee3
# frozen_string_literal: true
class
IssueBoardEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:iid
expose
:title
expose
:confidential
expose
:due_date
expose
:project_id
expose
:relative_position
expose
:weight
,
if:
->
(
*
)
{
respond_to?
(
:weight
)
}
expose
:time_estimate
expose
:project
do
|
issue
|
API
::
Entities
::
Project
.
represent
issue
.
project
,
only:
[
:id
,
:path
]
end
expose
:milestone
,
expose_nil:
false
do
|
issue
|
API
::
Entities
::
Project
.
represent
issue
.
milestone
,
only:
[
:id
,
:title
]
end
expose
:assignees
do
|
issue
|
API
::
Entities
::
UserBasic
.
represent
issue
.
assignees
,
only:
[
:id
,
:name
,
:username
,
:avatar_url
]
end
expose
:labels
do
|
issue
|
LabelEntity
.
represent
issue
.
labels
,
project:
issue
.
project
,
only:
[
:id
,
:title
,
:description
,
:color
,
:priority
,
:text_color
]
end
expose
:reference_path
,
if:
->
(
issue
)
{
issue
.
project
}
do
|
issue
,
options
|
options
[
:include_full_project_path
]
?
issue
.
to_reference
(
full:
true
)
:
issue
.
to_reference
end
expose
:real_path
,
if:
->
(
issue
)
{
issue
.
project
}
do
|
issue
|
project_issue_path
(
issue
.
project
,
issue
)
end
expose
:issue_sidebar_endpoint
,
if:
->
(
issue
)
{
issue
.
project
}
do
|
issue
|
project_issue_path
(
issue
.
project
,
issue
,
format: :json
,
serializer:
'sidebar'
)
end
expose
:toggle_subscription_endpoint
,
if:
->
(
issue
)
{
issue
.
project
}
do
|
issue
|
toggle_subscription_project_issue_path
(
issue
.
project
,
issue
)
end
expose
:assignable_labels_endpoint
,
if:
->
(
issue
)
{
issue
.
project
}
do
|
issue
|
project_labels_path
(
issue
.
project
,
format: :json
,
include_ancestor_groups:
true
)
end
end
app/serializers/issue_serializer.rb
View file @
03dba012
...
@@ -4,17 +4,15 @@ class IssueSerializer < BaseSerializer
...
@@ -4,17 +4,15 @@ class IssueSerializer < BaseSerializer
# This overrided method takes care of which entity should be used
# This overrided method takes care of which entity should be used
# to serialize the `issue` based on `basic` key in `opts` param.
# to serialize the `issue` based on `basic` key in `opts` param.
# Hence, `entity` doesn't need to be declared on the class scope.
# Hence, `entity` doesn't need to be declared on the class scope.
def
represent
(
issue
,
opts
=
{})
def
represent
(
merge_request
,
opts
=
{})
entity
=
entity
=
case
opts
[
:serializer
]
case
opts
[
:serializer
]
when
'sidebar'
when
'sidebar'
IssueSidebarEntity
IssueSidebarEntity
when
'board'
IssueBoardEntity
else
else
IssueEntity
IssueEntity
end
end
super
(
issue
,
opts
,
entity
)
super
(
merge_request
,
opts
,
entity
)
end
end
end
end
app/serializers/label_entity.rb
View file @
03dba012
...
@@ -12,8 +12,4 @@ class LabelEntity < Grape::Entity
...
@@ -12,8 +12,4 @@ class LabelEntity < Grape::Entity
expose
:text_color
expose
:text_color
expose
:created_at
expose
:created_at
expose
:updated_at
expose
:updated_at
expose
:priority
,
if:
->
(
*
)
{
options
.
key?
(
:project
)
}
do
|
label
|
label
.
priority
(
options
[
:project
])
end
end
end
spec/controllers/boards/issues_controller_spec.rb
View file @
03dba012
...
@@ -50,7 +50,7 @@ describe Boards::IssuesController do
...
@@ -50,7 +50,7 @@ describe Boards::IssuesController do
parsed_response
=
JSON
.
parse
(
response
.
body
)
parsed_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
).
to
match_response_schema
(
'
entities/issue_board
s'
)
expect
(
response
).
to
match_response_schema
(
'
issue
s'
)
expect
(
parsed_response
[
'issues'
].
length
).
to
eq
2
expect
(
parsed_response
[
'issues'
].
length
).
to
eq
2
expect
(
development
.
issues
.
map
(
&
:relative_position
)).
not_to
include
(
nil
)
expect
(
development
.
issues
.
map
(
&
:relative_position
)).
not_to
include
(
nil
)
end
end
...
@@ -121,7 +121,7 @@ describe Boards::IssuesController do
...
@@ -121,7 +121,7 @@ describe Boards::IssuesController do
parsed_response
=
JSON
.
parse
(
response
.
body
)
parsed_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
).
to
match_response_schema
(
'
entities/issue_board
s'
)
expect
(
response
).
to
match_response_schema
(
'
issue
s'
)
expect
(
parsed_response
[
'issues'
].
length
).
to
eq
2
expect
(
parsed_response
[
'issues'
].
length
).
to
eq
2
end
end
end
end
...
@@ -168,7 +168,7 @@ describe Boards::IssuesController do
...
@@ -168,7 +168,7 @@ describe Boards::IssuesController do
it
'returns the created issue'
do
it
'returns the created issue'
do
create_issue
user:
user
,
board:
board
,
list:
list1
,
title:
'New issue'
create_issue
user:
user
,
board:
board
,
list:
list1
,
title:
'New issue'
expect
(
response
).
to
match_response_schema
(
'
entities/issue_board
'
)
expect
(
response
).
to
match_response_schema
(
'
issue
'
)
end
end
end
end
...
...
spec/fixtures/api/schemas/entities/issue_boards.json
deleted
100644 → 0
View file @
ab61bee3
{
"type"
:
"object"
,
"required"
:
[
"issues"
,
"size"
],
"properties"
:
{
"issues"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"issue_board.json"
}
},
"size"
:
{
"type"
:
"integer"
}
},
"additionalProperties"
:
false
}
spec/models/concerns/awardable_spec.rb
View file @
03dba012
...
@@ -37,8 +37,8 @@ describe Awardable do
...
@@ -37,8 +37,8 @@ describe Awardable do
create
(
:award_emoji
,
awardable:
issue3
,
name:
"star"
,
user:
award_emoji
.
user
)
create
(
:award_emoji
,
awardable:
issue3
,
name:
"star"
,
user:
award_emoji
.
user
)
create
(
:award_emoji
,
awardable:
issue3
,
name:
"star"
,
user:
award_emoji2
.
user
)
create
(
:award_emoji
,
awardable:
issue3
,
name:
"star"
,
user:
award_emoji2
.
user
)
expect
(
Issue
.
awarded
(
award_emoji
.
user
)).
to
contain_exactly
(
issue
,
issue3
)
expect
(
Issue
.
awarded
(
award_emoji
.
user
)).
to
eq
[
issue
,
issue3
]
expect
(
Issue
.
awarded
(
award_emoji2
.
user
)).
to
contain_exactly
(
issue2
,
issue3
)
expect
(
Issue
.
awarded
(
award_emoji2
.
user
)).
to
eq
[
issue2
,
issue3
]
end
end
end
end
...
...
spec/serializers/issue_board_entity_spec.rb
deleted
100644 → 0
View file @
ab61bee3
# frozen_string_literal: true
require
'spec_helper'
describe
IssueBoardEntity
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
double
(
'request'
,
current_user:
user
)
}
subject
{
described_class
.
new
(
resource
,
request:
request
).
as_json
}
it
'has basic attributes'
do
expect
(
subject
).
to
include
(
:id
,
:iid
,
:title
,
:confidential
,
:due_date
,
:project_id
,
:relative_position
,
:project
,
:labels
)
end
it
'has path and endpoints'
do
expect
(
subject
).
to
include
(
:reference_path
,
:real_path
,
:issue_sidebar_endpoint
,
:toggle_subscription_endpoint
,
:assignable_labels_endpoint
)
end
end
spec/serializers/issue_serializer_spec.rb
View file @
03dba012
...
@@ -24,12 +24,4 @@ describe IssueSerializer do
...
@@ -24,12 +24,4 @@ describe IssueSerializer do
expect
(
json_entity
).
to
match_schema
(
'entities/issue_sidebar'
)
expect
(
json_entity
).
to
match_schema
(
'entities/issue_sidebar'
)
end
end
end
end
context
'board issue serialization'
do
let
(
:serializer
)
{
'board'
}
it
'matches board issue json schema'
do
expect
(
json_entity
).
to
match_schema
(
'entities/issue_board'
)
end
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