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
116ca8ae
Commit
116ca8ae
authored
Oct 02, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow users to compare Git revisions on a read-only instance
Whitelist route to compare Git revisions
parent
38c88bbe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
14 deletions
+37
-14
app/views/projects/branches/_branch.html.haml
app/views/projects/branches/_branch.html.haml
+2
-1
lib/gitlab/middleware/read_only/controller.rb
lib/gitlab/middleware/read_only/controller.rb
+12
-1
spec/features/projects/branches_spec.rb
spec/features/projects/branches_spec.rb
+0
-1
spec/features/projects/compare_spec.rb
spec/features/projects/compare_spec.rb
+23
-11
No files found.
app/views/projects/branches/_branch.html.haml
View file @
116ca8ae
...
@@ -34,8 +34,9 @@
...
@@ -34,8 +34,9 @@
=
_
(
'Merge request'
)
=
_
(
'Merge request'
)
-
if
branch
.
name
!=
@repository
.
root_ref
-
if
branch
.
name
!=
@repository
.
root_ref
=
link_to
project_compare_
path
(
@project
,
@repository
.
root_ref
,
branch
.
name
),
=
link_to
project_compare_
index_path
(
@project
,
from:
@repository
.
root_ref
,
to:
branch
.
name
),
class:
"btn btn-default js-onboarding-compare-branches
#{
'prepend-left-10'
unless
merge_project
}
"
,
class:
"btn btn-default js-onboarding-compare-branches
#{
'prepend-left-10'
unless
merge_project
}
"
,
method: :post
,
title:
s_
(
'Branches|Compare'
)
do
title:
s_
(
'Branches|Compare'
)
do
=
s_
(
'Branches|Compare'
)
=
s_
(
'Branches|Compare'
)
...
...
lib/gitlab/middleware/read_only/controller.rb
View file @
116ca8ae
...
@@ -20,6 +20,10 @@ module Gitlab
...
@@ -20,6 +20,10 @@ module Gitlab
'projects/lfs_locks_api'
=>
%w{verify create unlock}
'projects/lfs_locks_api'
=>
%w{verify create unlock}
}.
freeze
}.
freeze
WHITELISTED_GIT_REVISION_ROUTES
=
{
'projects/compare'
=>
%w{create}
}.
freeze
GRAPHQL_URL
=
'/api/graphql'
GRAPHQL_URL
=
'/api/graphql'
def
initialize
(
app
,
env
)
def
initialize
(
app
,
env
)
...
@@ -81,7 +85,7 @@ module Gitlab
...
@@ -81,7 +85,7 @@ module Gitlab
# Overridden in EE module
# Overridden in EE module
def
whitelisted_routes
def
whitelisted_routes
grack_route?
||
internal_route?
||
lfs_route?
||
sidekiq_route?
||
graphql_query?
grack_route?
||
internal_route?
||
lfs_route?
||
compare_git_revisions_route?
||
sidekiq_route?
||
graphql_query?
end
end
def
grack_route?
def
grack_route?
...
@@ -96,6 +100,13 @@ module Gitlab
...
@@ -96,6 +100,13 @@ module Gitlab
ReadOnly
.
internal_routes
.
any?
{
|
path
|
request
.
path
.
include?
(
path
)
}
ReadOnly
.
internal_routes
.
any?
{
|
path
|
request
.
path
.
include?
(
path
)
}
end
end
def
compare_git_revisions_route?
# Calling route_hash may be expensive. Only do it if we think there's a possible match
return
false
unless
request
.
post?
&&
request
.
path
.
end_with?
(
'compare'
)
WHITELISTED_GIT_REVISION_ROUTES
[
route_hash
[
:controller
]]
&
.
include?
(
route_hash
[
:action
])
end
def
lfs_route?
def
lfs_route?
# Calling route_hash may be expensive. Only do it if we think there's a possible match
# Calling route_hash may be expensive. Only do it if we think there's a possible match
unless
request
.
path
.
end_with?
(
'/info/lfs/objects/batch'
,
unless
request
.
path
.
end_with?
(
'/info/lfs/objects/batch'
,
...
...
spec/features/projects/branches_spec.rb
View file @
116ca8ae
...
@@ -246,7 +246,6 @@ describe 'Branches' do
...
@@ -246,7 +246,6 @@ describe 'Branches' do
end
end
expect
(
page
).
to
have_content
'Commits'
expect
(
page
).
to
have_content
'Commits'
expect
(
page
).
to
have_link
'Create merge request'
end
end
end
end
...
...
spec/features/projects/compare_spec.rb
View file @
116ca8ae
...
@@ -12,6 +12,23 @@ describe "Compare", :js do
...
@@ -12,6 +12,23 @@ describe "Compare", :js do
end
end
describe
"branches"
do
describe
"branches"
do
shared_examples
'compares branches'
do
it
'compares branches'
do
visit
project_compare_index_path
(
project
,
from:
'master'
,
to:
'master'
)
select_using_dropdown
'from'
,
'feature'
expect
(
find
(
'.js-compare-from-dropdown .dropdown-toggle-text'
)).
to
have_content
(
'feature'
)
select_using_dropdown
'to'
,
'binary-encoding'
expect
(
find
(
'.js-compare-to-dropdown .dropdown-toggle-text'
)).
to
have_content
(
'binary-encoding'
)
click_button
'Compare'
expect
(
page
).
to
have_content
'Commits'
expect
(
page
).
to
have_link
'Create merge request'
end
end
it
"pre-populates fields"
do
it
"pre-populates fields"
do
visit
project_compare_index_path
(
project
,
from:
"master"
,
to:
"master"
)
visit
project_compare_index_path
(
project
,
from:
"master"
,
to:
"master"
)
...
@@ -19,19 +36,14 @@ describe "Compare", :js do
...
@@ -19,19 +36,14 @@ describe "Compare", :js do
expect
(
find
(
".js-compare-to-dropdown .dropdown-toggle-text"
)).
to
have_content
(
"master"
)
expect
(
find
(
".js-compare-to-dropdown .dropdown-toggle-text"
)).
to
have_content
(
"master"
)
end
end
it
"compares branches"
do
it_behaves_like
'compares branches'
visit
project_compare_index_path
(
project
,
from:
"master"
,
to:
"master"
)
select_using_dropdown
"from"
,
"feature"
expect
(
find
(
".js-compare-from-dropdown .dropdown-toggle-text"
)).
to
have_content
(
"feature"
)
select_using_dropdown
"to"
,
"binary-encoding"
expect
(
find
(
".js-compare-to-dropdown .dropdown-toggle-text"
)).
to
have_content
(
"binary-encoding"
)
click_button
"Compare"
context
'on a read-only instance'
do
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:read_only?
).
and_return
(
true
)
end
expect
(
page
).
to
have_content
"Commits"
it_behaves_like
'compares branches'
expect
(
page
).
to
have_link
'Create merge request'
end
end
it
'renders additions info when click unfold diff'
do
it
'renders additions info when click unfold diff'
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