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
59b08942
Commit
59b08942
authored
Jan 26, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor blob controllers
parent
c9161241
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
92 deletions
+93
-92
app/controllers/projects/base_tree_controller.rb
app/controllers/projects/base_tree_controller.rb
+0
-7
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+93
-5
app/controllers/projects/edit_tree_controller.rb
app/controllers/projects/edit_tree_controller.rb
+0
-60
app/controllers/projects/new_tree_controller.rb
app/controllers/projects/new_tree_controller.rb
+0
-20
No files found.
app/controllers/projects/base_tree_controller.rb
deleted
100644 → 0
View file @
c9161241
class
Projects::BaseTreeController
<
Projects
::
ApplicationController
include
ExtractsPath
before_filter
:authorize_download_code!
before_filter
:require_non_empty_project
end
app/controllers/projects/blob_controller.rb
View file @
59b08942
...
...
@@ -2,16 +2,70 @@
class
Projects::BlobController
<
Projects
::
ApplicationController
include
ExtractsPath
# Authorize
# Raised when given an invalid file path
class
InvalidPathError
<
StandardError
;
end
before_filter
:authorize_download_code!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
,
except:
[
:new
,
:create
]
before_filter
:authorize_push_code!
,
only:
[
:destroy
]
before_filter
:assign_blob_vars
before_filter
:commit
,
except:
[
:new
,
:create
]
before_filter
:blob
,
except:
[
:new
,
:create
]
before_filter
:from_merge_request
,
only:
[
:edit
,
:update
]
before_filter
:after_edit_path
,
only:
[
:edit
,
:update
]
before_filter
:require_branch_head
,
only:
[
:edit
,
:update
]
def
new
commit
unless
@repository
.
empty?
end
before_filter
:blob
def
create
file_path
=
File
.
join
(
@path
,
File
.
basename
(
params
[
:file_name
]))
result
=
Files
::
CreateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
file_path
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
redirect_to
project_blob_path
(
@project
,
File
.
join
(
@ref
,
file_path
))
else
flash
[
:alert
]
=
result
[
:message
]
render
:show
end
end
def
show
end
def
edit
@last_commit
=
Gitlab
::
Git
::
Commit
.
last_for_path
(
@repository
,
@ref
,
@path
).
sha
end
def
update
result
=
Files
::
UpdateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
if
from_merge_request
from_merge_request
.
reload_code
end
redirect_to
after_edit_path
else
flash
[
:alert
]
=
result
[
:message
]
render
:show
end
end
def
preview
@content
=
params
[
:content
]
diffy
=
Diffy
::
Diff
.
new
(
@blob
.
data
,
@content
,
diff:
'-U 3'
,
include_diff_info:
true
)
@diff_lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diffy
.
diff
.
scan
(
/.*\n/
))
render
layout:
false
end
def
destroy
result
=
Files
::
DeleteService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
...
...
@@ -46,10 +100,44 @@ class Projects::BlobController < Projects::ApplicationController
if
@blob
@blob
elsif
tree
.
entries
.
any?
redirect_to
project_tree_path
(
@project
,
File
.
join
(
@ref
,
@path
))
and
return
else
if
tree
=
@repository
.
tree
(
@commit
.
id
,
@path
)
if
tree
.
entries
.
any?
redirect_to
project_tree_path
(
@project
,
File
.
join
(
@ref
,
@path
))
and
return
end
end
return
not_found!
end
end
def
commit
@commit
=
@repository
.
commit
(
@ref
)
return
not_found!
unless
@commit
end
def
assign_blob_vars
@id
=
params
[
:id
]
@ref
,
@path
=
extract_ref
(
@id
)
rescue
InvalidPathError
not_found!
end
def
after_edit_path
@after_edit_path
||=
if
from_merge_request
diffs_project_merge_request_path
(
from_merge_request
.
target_project
,
from_merge_request
)
+
"#file-path-
#{
hexdigest
(
@path
)
}
"
else
project_blob_path
(
@project
,
@id
)
end
end
def
from_merge_request
# If blob edit was initiated from merge request page
@from_merge_request
||=
MergeRequest
.
find_by
(
id:
params
[
:from_merge_request_id
])
end
end
app/controllers/projects/edit_tree_controller.rb
deleted
100644 → 0
View file @
c9161241
class
Projects::EditTreeController
<
Projects
::
BaseTreeController
before_filter
:require_branch_head
before_filter
:blob
before_filter
:authorize_push_code!
before_filter
:from_merge_request
before_filter
:after_edit_path
def
show
@last_commit
=
Gitlab
::
Git
::
Commit
.
last_for_path
(
@repository
,
@ref
,
@path
).
sha
end
def
update
result
=
Files
::
UpdateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
if
from_merge_request
from_merge_request
.
reload_code
end
redirect_to
after_edit_path
else
flash
[
:alert
]
=
result
[
:message
]
render
:show
end
end
def
preview
@content
=
params
[
:content
]
diffy
=
Diffy
::
Diff
.
new
(
@blob
.
data
,
@content
,
diff:
'-U 3'
,
include_diff_info:
true
)
@diff_lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diffy
.
diff
.
scan
(
/.*\n/
))
render
layout:
false
end
private
def
blob
@blob
||=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
end
def
after_edit_path
@after_edit_path
||=
if
from_merge_request
diffs_project_merge_request_path
(
from_merge_request
.
target_project
,
from_merge_request
)
+
"#file-path-
#{
hexdigest
(
@path
)
}
"
else
project_blob_path
(
@project
,
@id
)
end
end
def
from_merge_request
# If blob edit was initiated from merge request page
@from_merge_request
||=
MergeRequest
.
find_by
(
id:
params
[
:from_merge_request_id
])
end
end
app/controllers/projects/new_tree_controller.rb
deleted
100644 → 0
View file @
c9161241
class
Projects::NewTreeController
<
Projects
::
BaseTreeController
before_filter
:require_branch_head
before_filter
:authorize_push_code!
def
show
end
def
update
file_path
=
File
.
join
(
@path
,
File
.
basename
(
params
[
:file_name
]))
result
=
Files
::
CreateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
file_path
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
redirect_to
project_blob_path
(
@project
,
File
.
join
(
@ref
,
file_path
))
else
flash
[
:alert
]
=
result
[
:message
]
render
:show
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