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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
29b0ac48
Commit
29b0ac48
authored
Mar 24, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move edit to separate controller. This fixes #3265
parent
b6641d69
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
41 deletions
+51
-41
app/controllers/edit_tree_controller.rb
app/controllers/edit_tree_controller.rb
+47
-0
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+0
-38
app/views/edit_tree/show.html.haml
app/views/edit_tree/show.html.haml
+1
-1
app/views/tree/_blob_actions.html.haml
app/views/tree/_blob_actions.html.haml
+1
-1
config/routes.rb
config/routes.rb
+2
-1
No files found.
app/controllers/edit_tree_controller.rb
0 → 100644
View file @
29b0ac48
# Controller for edit a repository's file
class
EditTreeController
<
ProjectResourceController
include
ExtractsPath
# Authorize
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:edit_requirements
,
only:
[
:edit
,
:update
]
def
show
@last_commit
=
@project
.
repository
.
last_commit_for
(
@ref
,
@path
).
sha
end
def
update
edit_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
@project
,
@ref
,
@path
)
updated_successfully
=
edit_file_action
.
commit!
(
params
[
:content
],
params
[
:commit_message
],
params
[
:last_commit
]
)
if
updated_successfully
redirect_to
project_tree_path
(
@project
,
@id
),
notice:
"Your changes have been successfully commited"
else
flash
[
:notice
]
=
"Your changes could not be commited, because the file has been changed"
render
:edit
end
end
private
def
edit_requirements
unless
@tree
.
is_blob?
&&
@tree
.
text?
redirect_to
project_tree_path
(
@project
,
@id
),
notice:
"You can only edit text files"
end
allowed
=
if
project
.
protected_branch?
@ref
can?
(
current_user
,
:push_code_to_protected_branches
,
project
)
else
can?
(
current_user
,
:push_code
,
project
)
end
return
access_denied!
unless
allowed
end
end
app/controllers/tree_controller.rb
View file @
29b0ac48
...
@@ -7,8 +7,6 @@ class TreeController < ProjectResourceController
...
@@ -7,8 +7,6 @@ class TreeController < ProjectResourceController
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
before_filter
:edit_requirements
,
only:
[
:edit
,
:update
]
def
show
def
show
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
...
@@ -19,40 +17,4 @@ class TreeController < ProjectResourceController
...
@@ -19,40 +17,4 @@ class TreeController < ProjectResourceController
format
.
js
{
no_cache_headers
}
format
.
js
{
no_cache_headers
}
end
end
end
end
def
edit
@last_commit
=
@project
.
repository
.
last_commit_for
(
@ref
,
@path
).
sha
end
def
update
edit_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
@project
,
@ref
,
@path
)
updated_successfully
=
edit_file_action
.
commit!
(
params
[
:content
],
params
[
:commit_message
],
params
[
:last_commit
]
)
if
updated_successfully
redirect_to
project_tree_path
(
@project
,
@id
),
notice:
"Your changes have been successfully commited"
else
flash
[
:notice
]
=
"Your changes could not be commited, because the file has been changed"
render
:edit
end
end
private
def
edit_requirements
unless
@tree
.
is_blob?
&&
@tree
.
text?
redirect_to
project_tree_path
(
@project
,
@id
),
notice:
"You can only edit text files"
end
allowed
=
if
project
.
protected_branch?
@ref
can?
(
current_user
,
:push_code_to_protected_branches
,
project
)
else
can?
(
current_user
,
:push_code
,
project
)
end
return
access_denied!
unless
allowed
end
end
end
app/views/
tree/edit
.html.haml
→
app/views/
edit_tree/show
.html.haml
View file @
29b0ac48
.file-editor
.file-editor
=
form_tag
(
project_tree_path
(
@project
,
@id
),
method: :put
,
class:
"form-horizontal"
)
do
=
form_tag
(
project_
edit_
tree_path
(
@project
,
@id
),
method: :put
,
class:
"form-horizontal"
)
do
.file_holder
.file_holder
.file_title
.file_title
%i
.icon-file
%i
.icon-file
...
...
app/views/tree/_blob_actions.html.haml
View file @
29b0ac48
.btn-group.tree-btn-group
.btn-group.tree-btn-group
-# only show edit link for text files
-# only show edit link for text files
-
if
@tree
.
text?
-
if
@tree
.
text?
=
link_to
"edit"
,
edit_projec
t_tree_path
(
@project
,
@id
),
class:
"btn btn-tiny"
,
disabled:
!
allowed_tree_edit?
=
link_to
"edit"
,
project_edi
t_tree_path
(
@project
,
@id
),
class:
"btn btn-tiny"
,
disabled:
!
allowed_tree_edit?
=
link_to
"raw"
,
project_blob_path
(
@project
,
@id
),
class:
"btn btn-tiny"
,
target:
"_blank"
=
link_to
"raw"
,
project_blob_path
(
@project
,
@id
),
class:
"btn btn-tiny"
,
target:
"_blank"
-# only show normal/blame view links for text files
-# only show normal/blame view links for text files
-
if
@tree
.
text?
-
if
@tree
.
text?
...
...
config/routes.rb
View file @
29b0ac48
...
@@ -168,7 +168,8 @@ Gitlab::Application.routes.draw do
...
@@ -168,7 +168,8 @@ Gitlab::Application.routes.draw do
#
#
resources
:projects
,
constraints:
{
id:
/(?:[a-zA-Z.0-9_\-]+\/)?[a-zA-Z.0-9_\-]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
resources
:projects
,
constraints:
{
id:
/(?:[a-zA-Z.0-9_\-]+\/)?[a-zA-Z.0-9_\-]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
resources
:blob
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:blob
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:tree
,
only:
[
:show
,
:edit
,
:update
],
constraints:
{
id:
/.+/
}
resources
:tree
,
only:
[
:show
],
constraints:
{
id:
/.+/
,
format:
/(html|js)/
}
resources
:edit_tree
,
only:
[
:show
,
:update
],
constraints:
{
id:
/.+/
},
path:
'edit'
resources
:commit
,
only:
[
:show
],
constraints:
{
id:
/[[:alnum:]]{6,40}/
}
resources
:commit
,
only:
[
:show
],
constraints:
{
id:
/[[:alnum:]]{6,40}/
}
resources
:commits
,
only:
[
:show
],
constraints:
{
id:
/(?:[^.]|\.(?!atom$))+/
,
format:
/atom/
}
resources
:commits
,
only:
[
:show
],
constraints:
{
id:
/(?:[^.]|\.(?!atom$))+/
,
format:
/atom/
}
resources
:compare
,
only:
[
:index
,
:create
]
resources
:compare
,
only:
[
:index
,
:create
]
...
...
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