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
bee837d7
Commit
bee837d7
authored
Feb 15, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some initial refactoring
parent
f1360966
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
17 deletions
+25
-17
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+17
-9
app/views/projects/blob/_header.html.haml
app/views/projects/blob/_header.html.haml
+2
-2
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+1
-1
spec/helpers/blob_helper_spec.rb
spec/helpers/blob_helper_spec.rb
+5
-5
No files found.
app/helpers/blob_helper.rb
View file @
bee837d7
...
...
@@ -16,7 +16,7 @@ module BlobHelper
options
[
:link_opts
])
end
def
edit_blob_
link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
def
edit_blob_
element
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
return
unless
blob
=
readable_blob
(
options
,
path
,
project
,
ref
)
common_classes
=
"btn js-edit-blob
#{
options
[
:extra_class
]
}
"
...
...
@@ -24,13 +24,17 @@ module BlobHelper
if
!
on_top_of_branch?
(
project
,
ref
)
edit_button_tag
(
edit_text
,
common_classes
)
# This condition applies to anonymous or users who can edit directly
elsif
!
current_user
||
(
current_user
&&
can_modify_blob?
(
blob
,
project
,
ref
)
)
elsif
!
current_user
||
user_can_modify_blob
(
blob
,
project
,
ref
)
edit_link_tag
(
edit_text
,
edit_blob_path
(
project
,
ref
,
path
,
options
),
common_classes
)
elsif
current_user
&&
can?
(
current_user
,
:fork_project
,
project
)
elsif
user_can_fork_project
(
project
)
edit_blob_fork
(
common_classes
,
edit_blob_path
(
project
,
ref
,
path
,
options
),
project
)
end
end
def
user_can_fork_project
(
project
)
current_user
&&
can?
(
current_user
,
:fork_project
,
project
)
end
def
ide_edit_path
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
"
#{
ide_path
}
/project
#{
edit_blob_path
(
project
,
ref
,
path
,
options
)
}
"
end
...
...
@@ -43,7 +47,7 @@ module BlobHelper
_
(
'Web IDE'
)
end
def
ide_
blob_link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
def
ide_
edit_element
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
options
=
{})
return
unless
show_new_ide?
return
unless
blob
=
readable_blob
(
options
,
path
,
project
,
ref
)
...
...
@@ -53,14 +57,18 @@ module BlobHelper
edit_button_tag
(
ide_edit_text
,
common_classes
)
# This condition only applies to users who are logged in
# Web IDE (Beta) requires the user to have this feature enabled
elsif
current_user
&&
can_modify_blob?
(
blob
,
project
,
ref
)
elsif
user_can_modify_blob
(
blob
,
project
,
ref
)
edit_link_tag
(
ide_edit_text
,
ide_edit_path
(
project
,
ref
,
path
,
options
),
common_classes
)
elsif
current_user
&&
can?
(
current_user
,
:fork_project
,
project
)
elsif
user_can_fork_project
(
project
)
edit_blob_fork
(
common_classes
,
edit_blob_path
(
project
,
ref
,
path
,
options
),
project
)
end
end
def
modify_file_link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
label
:,
action
:,
btn_class
:,
modal_type
:)
def
user_can_modify_blob
(
blob
,
project
,
ref
)
current_user
&&
can_modify_blob?
(
blob
,
project
,
ref
)
end
def
modify_file_element
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
,
label
:,
action
:,
btn_class
:,
modal_type
:)
return
unless
current_user
blob
=
project
.
repository
.
blob_at
(
ref
,
path
)
rescue
nil
...
...
@@ -81,7 +89,7 @@ module BlobHelper
end
def
replace_blob_link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
)
modify_file_
link
(
modify_file_
element
(
project
,
ref
,
path
,
...
...
@@ -93,7 +101,7 @@ module BlobHelper
end
def
delete_blob_link
(
project
=
@project
,
ref
=
@ref
,
path
=
@path
)
modify_file_
link
(
modify_file_
element
(
project
,
ref
,
path
,
...
...
app/views/projects/blob/_header.html.haml
View file @
bee837d7
...
...
@@ -11,8 +11,8 @@
=
view_on_environment_button
(
@commit
.
sha
,
@path
,
@environment
)
if
@environment
.btn-group
{
role:
"group"
}
<
=
edit_blob_
link
=
ide_
blob_link
=
edit_blob_
element
=
ide_
edit_element
-
if
current_user
=
replace_blob_link
=
delete_blob_link
...
...
app/views/projects/diffs/_file.html.haml
View file @
bee837d7
...
...
@@ -17,7 +17,7 @@
\
-
if
editable_diff?
(
diff_file
)
-
link_opts
=
@merge_request
.
persisted?
?
{
from_merge_request_iid:
@merge_request
.
iid
}
:
{}
=
edit_blob_
link
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
=
edit_blob_
element
(
@merge_request
.
source_project
,
@merge_request
.
source_branch
,
diff_file
.
new_path
,
blob:
blob
,
link_opts:
link_opts
)
-
if
image_diff
&&
image_replaced
...
...
spec/helpers/blob_helper_spec.rb
View file @
bee837d7
...
...
@@ -74,7 +74,7 @@ describe BlobHelper do
end
end
describe
"#edit_blob_
link
"
do
describe
"#edit_blob_
element
"
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'gitlab'
)}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
namespace
)
}
...
...
@@ -86,7 +86,7 @@ describe BlobHelper do
it
'verifies blob is text'
do
expect
(
helper
).
not_to
receive
(
:blob_text_viewable?
)
button
=
edit_blob_
link
(
project
,
'refs/heads/master'
,
'README.md'
)
button
=
edit_blob_
element
(
project
,
'refs/heads/master'
,
'README.md'
)
expect
(
button
).
to
start_with
(
'<button'
)
end
...
...
@@ -96,17 +96,17 @@ describe BlobHelper do
expect
(
project
.
repository
).
not_to
receive
(
:blob_at
)
edit_blob_
link
(
project
,
'refs/heads/master'
,
'README.md'
,
blob:
blob
)
edit_blob_
element
(
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'
)
link
=
edit_blob_
element
(
project
,
'master'
,
'README.md'
)
expect
(
Capybara
.
string
(
link
).
find_link
(
'Edit'
)[
:href
]).
to
eq
(
"/
#{
project
.
full_path
}
/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
})
link
=
edit_blob_
element
(
project
,
'master'
,
'README.md'
,
link_opts:
{
mr_id:
10
})
expect
(
Capybara
.
string
(
link
).
find_link
(
'Edit'
)[
:href
]).
to
eq
(
"/
#{
project
.
full_path
}
/edit/master/README.md?mr_id=10"
)
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