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
938f3b2a
Commit
938f3b2a
authored
Aug 17, 2016
by
Paco Guzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit_blob_link can receive the blob to avoid access to the repository
parent
ac73de50
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
12 deletions
+31
-12
CHANGELOG
CHANGELOG
+1
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+3
-6
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+3
-4
spec/helpers/blob_helper_spec.rb
spec/helpers/blob_helper_spec.rb
+24
-2
No files found.
CHANGELOG
View file @
938f3b2a
...
...
@@ -103,6 +103,7 @@ v 8.11.0 (unreleased)
- Add commit stats in commit api. !5517 (dixpac)
- Add CI configuration button on project page
- Fix merge request new view not changing code view rendering style
- edit_blob_link will use blob passed onto the options parameter
- Make error pages responsive (Takuya Noguchi)
- The performance of the project dropdown used for moving issues has been improved
- Fix skip_repo parameter being ignored when destroying a namespace
...
...
app/helpers/blob_helper.rb
View file @
938f3b2a
...
...
@@ -11,17 +11,14 @@ module BlobHelper
def
edit_blob_link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
return
unless
current_user
blob
=
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
blob
=
options
.
delete
(
:blob
)
blob
||=
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
return
unless
blob
from_mr
=
options
[
:from_merge_request_id
]
link_opts
=
{}
link_opts
[
:from_merge_request_id
]
=
from_mr
if
from_mr
edit_path
=
namespace_project_edit_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
path
),
link_opts
)
options
[
:link_opts
]
)
if
!
on_top_of_branch?
(
project
,
ref
)
button_tag
"Edit"
,
class:
"btn disabled has-tooltip btn-file-option"
,
title:
"You can only edit files when you are on a branch"
,
data:
{
container:
'body'
}
...
...
app/views/projects/diffs/_file.html.haml
View file @
938f3b2a
...
...
@@ -10,10 +10,9 @@
\
-
if
editable_diff?
(
diff_file
)
=
edit_blob_link
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
from_merge_request_id:
@merge_request
.
id
,
skip_visible_check:
true
)
-
link_opts
=
@merge_request
.
id
?
{
from_merge_request_id:
@merge_request
.
id
}
:
{}
=
edit_blob_link
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
blob:
blob
,
link_opts:
link_opts
)
=
view_file_btn
(
diff_commit
.
id
,
diff_file
.
new_path
,
project
)
...
...
spec/helpers/blob_helper_spec.rb
View file @
938f3b2a
...
...
@@ -69,18 +69,40 @@ describe BlobHelper do
end
describe
"#edit_blob_link"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'gitlab'
)}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
before
do
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
double
)
allow
(
self
).
to
receive
(
:can_collaborate_with_project?
).
and_return
(
true
)
end
it
'verifies blob is text'
do
expect
(
self
).
not_to
receive
(
:blob_text_viewable?
)
expect
(
helper
).
not_to
receive
(
:blob_text_viewable?
)
button
=
edit_blob_link
(
project
,
'refs/heads/master'
,
'README.md'
)
expect
(
button
).
to
start_with
(
'<button'
)
end
it
'uses the passed blob instead retrieve from repository'
do
blob
=
project
.
repository
.
blob_at
(
'refs/heads/master'
,
'README.md'
)
expect
(
project
.
repository
).
not_to
receive
(
:blob_at
)
edit_blob_link
(
project
,
'refs/heads/master'
,
'README.md'
,
blob:
blob
)
end
it
'returns a link with the proper route'
do
link
=
edit_blob_link
(
project
,
'master'
,
'README.md'
)
expect
(
Capybara
.
string
(
link
).
find_link
(
'Edit'
)[
:href
]).
to
eq
(
'/gitlab/gitlabhq/edit/master/README.md'
)
end
it
'returns a link with the passed link_opts on the expected route'
do
link
=
edit_blob_link
(
project
,
'master'
,
'README.md'
,
link_opts:
{
mr_id:
10
})
expect
(
Capybara
.
string
(
link
).
find_link
(
'Edit'
)[
:href
]).
to
eq
(
'/gitlab/gitlabhq/edit/master/README.md?mr_id=10'
)
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