2012-09-17 13:49:57 -04:00
|
|
|
# Controller for viewing a file's blame
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::BlobController < Projects::ApplicationController
|
2012-09-20 13:55:14 -04:00
|
|
|
include ExtractsPath
|
2012-09-17 13:49:57 -04:00
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_filter :authorize_read_project!
|
2014-10-13 15:31:49 -04:00
|
|
|
before_filter :authorize_download_code!
|
2012-09-17 13:49:57 -04:00
|
|
|
before_filter :require_non_empty_project
|
2014-10-13 15:31:49 -04:00
|
|
|
before_filter :authorize_push_code!, only: [:destroy]
|
2012-09-17 13:49:57 -04:00
|
|
|
|
2013-11-19 09:14:48 -05:00
|
|
|
before_filter :blob
|
|
|
|
|
2012-09-17 13:49:57 -04:00
|
|
|
def show
|
2013-11-19 09:14:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2014-01-16 12:03:42 -05:00
|
|
|
result = Files::DeleteService.new(@project, current_user, params, @ref, @path).execute
|
2013-11-19 09:14:48 -05:00
|
|
|
|
|
|
|
if result[:status] == :success
|
2013-12-16 03:57:50 -05:00
|
|
|
flash[:notice] = "Your changes have been successfully committed"
|
2013-11-19 09:14:48 -05:00
|
|
|
redirect_to project_tree_path(@project, @ref)
|
|
|
|
else
|
2014-09-25 10:43:23 -04:00
|
|
|
flash[:alert] = result[:message]
|
2013-11-19 09:14:48 -05:00
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-02 11:12:01 -04:00
|
|
|
def diff
|
|
|
|
@form = UnfoldForm.new(params)
|
|
|
|
@lines = @blob.data.lines[@form.since - 1..@form.to - 1]
|
|
|
|
|
|
|
|
if @form.bottom?
|
|
|
|
@match_line = ''
|
|
|
|
else
|
|
|
|
lines_length = @lines.length - 1
|
|
|
|
line = [@form.since, lines_length].join(',')
|
|
|
|
@match_line = "@@ -#{line}+#{line} @@"
|
|
|
|
end
|
|
|
|
|
|
|
|
render layout: false
|
|
|
|
end
|
|
|
|
|
2013-11-19 09:14:48 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def blob
|
|
|
|
@blob ||= @repository.blob_at(@commit.id, @path)
|
|
|
|
|
2014-07-07 09:46:57 -04:00
|
|
|
if @blob
|
|
|
|
@blob
|
|
|
|
elsif tree.entries.any?
|
|
|
|
redirect_to project_tree_path(@project, File.join(@ref, @path)) and return
|
|
|
|
else
|
|
|
|
return not_found!
|
|
|
|
end
|
2012-09-17 13:49:57 -04:00
|
|
|
end
|
|
|
|
end
|