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
f774939b
Commit
f774939b
authored
Oct 23, 2019
by
Shinya Maeda
Committed by
Michael Kozono
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract with release presenter
This commit abstracts FE specific code with release presenter
parent
35011d7e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
34 deletions
+139
-34
app/models/release.rb
app/models/release.rb
+1
-0
app/presenters/release_presenter.rb
app/presenters/release_presenter.rb
+47
-0
lib/api/entities.rb
lib/api/entities.rb
+6
-34
spec/presenters/release_presenter_spec.rb
spec/presenters/release_presenter_spec.rb
+85
-0
No files found.
app/models/release.rb
View file @
f774939b
# frozen_string_literal: true
class
Release
<
ApplicationRecord
include
Presentable
include
CacheMarkdownField
include
Gitlab
::
Utils
::
StrongMemoize
...
...
app/presenters/release_presenter.rb
0 → 100644
View file @
f774939b
# frozen_string_literal: true
class
ReleasePresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
include
ActionView
::
Helpers
::
UrlHelper
presents
:release
delegate
:project
,
:tag
,
to: :release
def
commit_path
return
unless
release
.
commit
&&
can_download_code?
project_commit_path
(
project
,
release
.
commit
.
id
)
end
def
tag_path
return
unless
can_download_code?
project_tag_path
(
project
,
release
.
tag
)
end
def
merge_requests_url
return
unless
release_mr_issue_urls_available?
project_merge_requests_url
(
project
,
params_for_issues_and_mrs
)
end
def
issues_url
return
unless
release_mr_issue_urls_available?
project_issues_url
(
project
,
params_for_issues_and_mrs
)
end
private
def
can_download_code?
can?
(
current_user
,
:download_code
,
project
)
end
def
params_for_issues_and_mrs
{
scope:
'all'
,
state:
'opened'
,
release_tag:
release
.
tag
}
end
def
release_mr_issue_urls_available?
::
Feature
.
enabled?
(
:release_mr_issue_urls
,
project
)
end
end
lib/api/entities.rb
View file @
f774939b
...
...
@@ -1291,6 +1291,8 @@ module API
end
class
Release
<
Grape
::
Entity
include
::
API
::
Helpers
::
Presentable
expose
:name
expose
:tag
,
as: :tag_name
,
if:
->
(
_
,
_
)
{
can_download_code?
}
expose
:description
...
...
@@ -1303,8 +1305,8 @@ module API
expose
:commit
,
using:
Entities
::
Commit
,
if:
->
(
_
,
_
)
{
can_download_code?
}
expose
:upcoming_release?
,
as: :upcoming_release
expose
:milestones
,
using:
Entities
::
Milestone
,
if:
->
(
release
,
_
)
{
release
.
milestones
.
present?
}
expose
:commit_path
,
if:
->
(
_
,
_
)
{
can_download_code?
}
expose
:tag_path
,
if:
->
(
_
,
_
)
{
can_download_code?
}
expose
:commit_path
,
expose_nil:
false
expose
:tag_path
,
expose_nil:
false
expose
:assets
do
expose
:assets_count
,
as: :count
do
|
release
,
_
|
assets_to_exclude
=
can_download_code?
?
[]
:
[
:sources
]
...
...
@@ -1316,8 +1318,8 @@ module API
end
end
expose
:_links
do
expose
:merge_requests_url
,
if:
->
(
_
)
{
release_mr_issue_urls_available?
}
expose
:issues_url
,
if:
->
(
_
)
{
release_mr_issue_urls_available?
}
expose
:merge_requests_url
,
expose_nil:
false
expose
:issues_url
,
expose_nil:
false
end
private
...
...
@@ -1325,36 +1327,6 @@ module API
def
can_download_code?
Ability
.
allowed?
(
options
[
:current_user
],
:download_code
,
object
.
project
)
end
def
commit_path
return
unless
object
.
commit
Gitlab
::
Routing
.
url_helpers
.
project_commit_path
(
project
,
object
.
commit
.
id
)
end
def
tag_path
Gitlab
::
Routing
.
url_helpers
.
project_tag_path
(
project
,
object
.
tag
)
end
def
merge_requests_url
Gitlab
::
Routing
.
url_helpers
.
project_merge_requests_url
(
project
,
params_for_issues_and_mrs
)
end
def
issues_url
Gitlab
::
Routing
.
url_helpers
.
project_issues_url
(
project
,
params_for_issues_and_mrs
)
end
def
params_for_issues_and_mrs
{
scope:
'all'
,
state:
'opened'
,
release_tag:
object
.
tag
}
end
def
release_mr_issue_urls_available?
::
Feature
.
enabled?
(
:release_mr_issue_urls
,
project
)
end
def
project
@project
||=
object
.
project
end
end
class
Tag
<
Grape
::
Entity
...
...
spec/presenters/release_presenter_spec.rb
0 → 100644
View file @
f774939b
# frozen_string_literal: true
require
'spec_helper'
describe
ReleasePresenter
do
include
Gitlab
::
Routing
.
url_helpers
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:developer
)
{
create
(
:user
)
}
let
(
:guest
)
{
create
(
:user
)
}
let
(
:user
)
{
developer
}
let
(
:release
)
{
create
(
:release
,
project:
project
)
}
let
(
:presenter
)
{
described_class
.
new
(
release
,
current_user:
user
)
}
before
do
project
.
add_developer
(
developer
)
project
.
add_guest
(
guest
)
end
describe
'#commit_path'
do
subject
{
presenter
.
commit_path
}
it
'returns commit path'
do
is_expected
.
to
eq
(
project_commit_path
(
project
,
release
.
commit
.
id
))
end
context
'when commit is not found'
do
let
(
:release
)
{
create
(
:release
,
project:
project
,
sha:
'not-found'
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when user is guest'
do
let
(
:user
)
{
guest
}
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#tag_path'
do
subject
{
presenter
.
tag_path
}
it
'returns tag path'
do
is_expected
.
to
eq
(
project_tag_path
(
project
,
release
.
tag
))
end
context
'when user is guest'
do
let
(
:user
)
{
guest
}
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#merge_requests_url'
do
subject
{
presenter
.
merge_requests_url
}
it
'returns merge requests url'
do
is_expected
.
to
match
/
#{
project_merge_requests_url
(
project
)
}
/
end
context
'when release_mr_issue_urls feature flag is disabled'
do
before
do
stub_feature_flags
(
release_mr_issue_urls:
false
)
end
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#issues_url'
do
subject
{
presenter
.
issues_url
}
it
'returns merge requests url'
do
is_expected
.
to
match
/
#{
project_issues_url
(
project
)
}
/
end
context
'when release_mr_issue_urls feature flag is disabled'
do
before
do
stub_feature_flags
(
release_mr_issue_urls:
false
)
end
it
{
is_expected
.
to
be_nil
}
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