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
Jérome Perrin
gitlab-ce
Commits
82ddd738
Commit
82ddd738
authored
Dec 08, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show tooltip when trying to edit file when not on branch
parent
df6750d3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
32 deletions
+41
-32
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+18
-20
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+8
-5
app/services/files/base_service.rb
app/services/files/base_service.rb
+1
-1
app/views/projects/blob/_actions.html.haml
app/views/projects/blob/_actions.html.haml
+9
-5
app/views/projects/blob/show.html.haml
app/views/projects/blob/show.html.haml
+1
-1
app/views/projects/tree/_tree_header.html.haml
app/views/projects/tree/_tree_header.html.haml
+4
-0
No files found.
app/helpers/blob_helper.rb
View file @
82ddd738
...
@@ -30,26 +30,24 @@ module BlobHelper
...
@@ -30,26 +30,24 @@ module BlobHelper
nil
nil
end
end
if
blob_viewable?
(
blob
)
return
unless
blob
&&
blob_editable?
(
blob
)
text
=
'Edit'
text
=
'Edit'
after
=
options
[
:after
]
||
''
after
=
options
[
:after
]
||
''
from_mr
=
options
[
:from_merge_request_id
]
from_mr
=
options
[
:from_merge_request_id
]
link_opts
=
{}
link_opts
=
{}
link_opts
[
:from_merge_request_id
]
=
from_mr
if
from_mr
link_opts
[
:from_merge_request_id
]
=
from_mr
if
from_mr
cls
=
'btn btn-small'
cls
=
'btn btn-small'
if
allowed_tree_edit?
(
project
,
ref
)
link_to
(
text
,
link_to
(
text
,
namespace_project_edit_blob_path
(
project
.
namespace
,
project
,
namespace_project_edit_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
path
),
tree_join
(
ref
,
path
),
link_opts
),
link_opts
),
class:
cls
class:
cls
)
)
+
after
.
html_safe
else
content_tag
:span
,
text
,
class:
cls
+
' disabled'
end
+
after
.
html_safe
else
''
end
end
def
blob_editable?
(
blob
,
project
=
@project
,
ref
=
@ref
)
allowed_tree_edit?
(
project
,
ref
)
&&
!
blob
.
lfs_pointer?
end
end
def
leave_edit_message
def
leave_edit_message
...
...
app/helpers/tree_helper.rb
View file @
82ddd738
...
@@ -46,13 +46,20 @@ module TreeHelper
...
@@ -46,13 +46,20 @@ module TreeHelper
File
.
join
(
*
args
)
File
.
join
(
*
args
)
end
end
def
on_top_of_branch?
(
project
=
@project
,
ref
=
@ref
)
project
.
repository
.
branch_names
.
include?
(
ref
)
end
def
allowed_tree_edit?
(
project
=
nil
,
ref
=
nil
)
def
allowed_tree_edit?
(
project
=
nil
,
ref
=
nil
)
project
||=
@project
project
||=
@project
ref
||=
@ref
return
false
unless
on_top_of_branch?
(
project
,
ref
)
can?
(
current_user
,
:push_code
,
project
)
can?
(
current_user
,
:push_code
,
project
)
end
end
def
tree_edit_branch
(
project
=
@project
,
ref
=
@ref
)
def
tree_edit_branch
(
project
=
@project
,
ref
=
@ref
)
if
allowed_tree_edit?
if
allowed_tree_edit?
(
project
,
ref
)
if
can_push_branch?
(
project
,
ref
)
if
can_push_branch?
(
project
,
ref
)
ref
ref
else
else
...
@@ -61,10 +68,6 @@ module TreeHelper
...
@@ -61,10 +68,6 @@ module TreeHelper
end
end
end
end
def
can_delete_or_replace?
(
blob
)
allowed_tree_edit?
&&
!
blob
.
lfs_pointer?
end
def
tree_breadcrumbs
(
tree
,
max_links
=
2
)
def
tree_breadcrumbs
(
tree
,
max_links
=
2
)
if
@path
.
present?
if
@path
.
present?
part_path
=
""
part_path
=
""
...
...
app/services/files/base_service.rb
View file @
82ddd738
...
@@ -53,7 +53,7 @@ module Files
...
@@ -53,7 +53,7 @@ module Files
unless
project
.
empty_repo?
unless
project
.
empty_repo?
unless
repository
.
branch_names
.
include?
(
@current_branch
)
unless
repository
.
branch_names
.
include?
(
@current_branch
)
raise_error
(
"You can only create
files if
you are on top of a branch"
)
raise_error
(
"You can only create
or edit files when
you are on top of a branch"
)
end
end
if
@current_branch
!=
@target_branch
if
@current_branch
!=
@target_branch
...
...
app/views/projects/blob/_actions.html.haml
View file @
82ddd738
.btn-group.tree-btn-group
.btn-group.tree-btn-group
=
edit_blob_link
(
@project
,
@ref
,
@path
)
=
link_to
'Raw'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
=
link_to
'Raw'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
class:
'btn btn-sm'
,
target:
'_blank'
class:
'btn btn-sm'
,
target:
'_blank'
-# only show normal/blame view links for text files
-# only show normal/blame view links for text files
...
@@ -12,11 +11,16 @@
...
@@ -12,11 +11,16 @@
class:
'btn btn-sm'
unless
@blob
.
empty?
class:
'btn btn-sm'
unless
@blob
.
empty?
=
link_to
'History'
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@id
),
=
link_to
'History'
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@id
),
class:
'btn btn-sm'
class:
'btn btn-sm'
-
if
@ref
!=
@commit
.
sha
=
link_to
'Permalink'
,
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
=
link_to
'Permalink'
,
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
@commit
.
sha
,
@path
)),
class:
'btn btn-sm'
tree_join
(
@commit
.
sha
,
@path
)),
class:
'btn btn-sm'
-
if
can_delete_or_replac
e?
(
@blob
)
-
if
blob_editabl
e?
(
@blob
)
.btn-group
{
role:
"group"
}
.btn-group
{
role:
"group"
}
=
edit_blob_link
(
@project
,
@ref
,
@path
)
%button
.btn.btn-default
{
'data-target'
=>
'#modal-upload-blob'
,
'data-toggle'
=>
'modal'
}
Replace
%button
.btn.btn-default
{
'data-target'
=>
'#modal-upload-blob'
,
'data-toggle'
=>
'modal'
}
Replace
%button
.btn.btn-remove
{
'data-target'
=>
'#modal-remove-blob'
,
'data-toggle'
=>
'modal'
}
Delete
%button
.btn.btn-remove
{
'data-target'
=>
'#modal-remove-blob'
,
'data-toggle'
=>
'modal'
}
Delete
-
elsif
!
on_top_of_branch?
.btn-group
{
role:
"group"
}
%button
.btn.btn-default.disabled.has_tooltip
{
title:
"You can only edit files when you are on top of a branch."
,
data:
{
container:
'body'
}}
Edit
%button
.btn.btn-default.disabled.has_tooltip
{
title:
"You can only replace files when you are on top of a branch."
,
data:
{
container:
'body'
}}
Replace
%button
.btn.btn-remove.disabled.has_tooltip
{
title:
"You can only delete files when you are on top of a branch."
,
data:
{
container:
'body'
}}
Delete
app/views/projects/blob/show.html.haml
View file @
82ddd738
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
%div
#tree-holder
.tree-holder
%div
#tree-holder
.tree-holder
=
render
'blob'
,
blob:
@blob
=
render
'blob'
,
blob:
@blob
-
if
can_delete_or_replac
e?
(
@blob
)
-
if
blob_editabl
e?
(
@blob
)
=
render
'projects/blob/remove'
=
render
'projects/blob/remove'
-
title
=
"Replace
#{
@blob
.
name
}
"
-
title
=
"Replace
#{
@blob
.
name
}
"
...
...
app/views/projects/tree/_tree_header.html.haml
View file @
82ddd738
...
@@ -30,3 +30,7 @@
...
@@ -30,3 +30,7 @@
=
link_to
'#modal-create-new-dir'
,
{
'data-target'
=>
'#modal-create-new-dir'
,
'data-toggle'
=>
'modal'
}
do
=
link_to
'#modal-create-new-dir'
,
{
'data-target'
=>
'#modal-create-new-dir'
,
'data-toggle'
=>
'modal'
}
do
=
icon
(
'folder fw'
)
=
icon
(
'folder fw'
)
New directory
New directory
-
elsif
!
on_top_of_branch?
%li
%span
.btn.add-to-tree.disabled.has_tooltip
{
href:
'#'
,
title:
"You can only add files when you are on top of a branch."
,
data:
{
container:
'body'
}}
=
icon
(
'plus'
)
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