Merge branch 'master' into simplify_controllers2
Conflicts: app/controllers/commits_controller.rb app/controllers/refs_controller.rb
This commit is contained in:
commit
e563e948bb
108 changed files with 1762 additions and 652 deletions
|
@ -2,7 +2,6 @@ class ApplicationController < ActionController::Base
|
|||
before_filter :authenticate_user!
|
||||
before_filter :reject_blocked!
|
||||
before_filter :set_current_user_for_mailer
|
||||
before_filter :check_token_auth
|
||||
before_filter :set_current_user_for_observers
|
||||
before_filter :dev_tools if Rails.env == 'development'
|
||||
|
||||
|
@ -24,13 +23,6 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
protected
|
||||
|
||||
def check_token_auth
|
||||
# Redirect to login page if not atom feed
|
||||
if params[:private_token].present? && params[:format] != 'atom'
|
||||
redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
|
||||
def reject_blocked!
|
||||
if current_user && current_user.blocked
|
||||
sign_out current_user
|
||||
|
@ -103,7 +95,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def render_404
|
||||
render file: File.join(Rails.root, "public", "404"), layout: false, status: "404"
|
||||
render file: Rails.root.join("public", "404"), layout: false, status: "404"
|
||||
end
|
||||
|
||||
def require_non_empty_project
|
||||
|
@ -116,10 +108,6 @@ class ApplicationController < ActionController::Base
|
|||
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
|
||||
end
|
||||
|
||||
def render_full_content
|
||||
@full_content = true
|
||||
end
|
||||
|
||||
def dev_tools
|
||||
Rack::MiniProfiler.authorize_request
|
||||
end
|
||||
|
|
21
app/controllers/blame_controller.rb
Normal file
21
app/controllers/blame_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Controller for viewing a file's blame
|
||||
class BlameController < ApplicationController
|
||||
include ExtractsPath
|
||||
|
||||
layout "project"
|
||||
|
||||
before_filter :project
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :assign_ref_vars
|
||||
|
||||
def show
|
||||
@repo = @project.repo
|
||||
@blame = Grit::Blob.blame(@repo, @commit.id, @path)
|
||||
end
|
||||
end
|
37
app/controllers/blob_controller.rb
Normal file
37
app/controllers/blob_controller.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# Controller for viewing a file's blame
|
||||
class BlobController < ApplicationController
|
||||
include ExtractsPath
|
||||
include Gitlab::Encode
|
||||
|
||||
layout "project"
|
||||
|
||||
before_filter :project
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :assign_ref_vars
|
||||
|
||||
def show
|
||||
if @tree.is_blob?
|
||||
if @tree.text?
|
||||
encoding = detect_encoding(@tree.data)
|
||||
mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
|
||||
else
|
||||
mime_type = @tree.mime_type
|
||||
end
|
||||
|
||||
send_data(
|
||||
@tree.data,
|
||||
type: mime_type,
|
||||
disposition: 'inline',
|
||||
filename: @tree.name
|
||||
)
|
||||
else
|
||||
not_found!
|
||||
end
|
||||
end
|
||||
end
|
36
app/controllers/commit_controller.rb
Normal file
36
app/controllers/commit_controller.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Controller for a specific Commit
|
||||
#
|
||||
# Not to be confused with CommitsController, plural.
|
||||
class CommitController < ApplicationController
|
||||
before_filter :project
|
||||
layout "project"
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
def show
|
||||
result = CommitLoad.new(project, current_user, params).execute
|
||||
|
||||
@commit = result[:commit]
|
||||
git_not_found! unless @commit
|
||||
|
||||
@suppress_diff = result[:suppress_diff]
|
||||
@note = result[:note]
|
||||
@line_notes = result[:line_notes]
|
||||
@notes_count = result[:notes_count]
|
||||
@comments_allowed = true
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if result[:status] == :huge_commit
|
||||
render "huge_commit" and return
|
||||
end
|
||||
end
|
||||
|
||||
format.patch
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +1,18 @@
|
|||
require "base64"
|
||||
|
||||
class CommitsController < ProjectController
|
||||
include ExtractsPath
|
||||
|
||||
# Authorize
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
before_filter :load_refs, only: :index # load @branch, @tag & @ref
|
||||
before_filter :render_full_content
|
||||
|
||||
def index
|
||||
@repo = project.repo
|
||||
def show
|
||||
@repo = @project.repo
|
||||
@limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
|
||||
|
||||
@commits = @project.commits(@ref, params[:path], @limit, @offset)
|
||||
@commits = @project.commits(@ref, @path, @limit, @offset)
|
||||
@commits = CommitDecorator.decorate(@commits)
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -21,54 +21,4 @@ class CommitsController < ProjectController
|
|||
format.atom { render layout: false }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
result = CommitLoad.new(project, current_user, params).execute
|
||||
|
||||
@commit = result[:commit]
|
||||
|
||||
if @commit
|
||||
@suppress_diff = result[:suppress_diff]
|
||||
@note = result[:note]
|
||||
@line_notes = result[:line_notes]
|
||||
@notes_count = result[:notes_count]
|
||||
@comments_allowed = true
|
||||
else
|
||||
return git_not_found!
|
||||
end
|
||||
|
||||
if result[:status] == :huge_commit
|
||||
render "huge_commit" and return
|
||||
end
|
||||
end
|
||||
|
||||
def compare
|
||||
result = Commit.compare(project, params[:from], params[:to])
|
||||
|
||||
@commits = result[:commits]
|
||||
@commit = result[:commit]
|
||||
@diffs = result[:diffs]
|
||||
@refs_are_same = result[:same]
|
||||
@line_notes = []
|
||||
|
||||
@commits = CommitDecorator.decorate(@commits)
|
||||
end
|
||||
|
||||
def patch
|
||||
@commit = project.commit(params[:id])
|
||||
|
||||
send_data(
|
||||
@commit.to_patch,
|
||||
type: "text/plain",
|
||||
disposition: 'attachment',
|
||||
filename: "#{@commit.id}.patch"
|
||||
)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def load_refs
|
||||
@ref ||= params[:ref].presence || params[:branch].presence || params[:tag].presence
|
||||
@ref ||= @ref || @project.try(:default_branch) || 'master'
|
||||
end
|
||||
end
|
||||
|
|
29
app/controllers/compare_controller.rb
Normal file
29
app/controllers/compare_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class CompareController < ApplicationController
|
||||
before_filter :project
|
||||
layout "project"
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
result = Commit.compare(project, params[:from], params[:to])
|
||||
|
||||
@commits = result[:commits]
|
||||
@commit = result[:commit]
|
||||
@diffs = result[:diffs]
|
||||
@refs_are_same = result[:same]
|
||||
@line_notes = []
|
||||
|
||||
@commits = CommitDecorator.decorate(@commits)
|
||||
end
|
||||
|
||||
def create
|
||||
redirect_to project_compare_path(@project, params[:from], params[:to])
|
||||
end
|
||||
end
|
|
@ -4,7 +4,6 @@ class ProtectedBranchesController < ProjectController
|
|||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :authorize_admin_project!, only: [:destroy, :create]
|
||||
before_filter :render_full_content
|
||||
|
||||
def index
|
||||
@branches = @project.protected_branches.all
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'github/markup'
|
||||
|
||||
class RefsController < ProjectController
|
||||
include Gitlab::Encode
|
||||
|
||||
|
@ -9,21 +7,20 @@ class RefsController < ProjectController
|
|||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :ref
|
||||
before_filter :define_tree_vars, only: [:tree, :blob, :blame, :logs_tree]
|
||||
before_filter :render_full_content
|
||||
before_filter :define_tree_vars, only: [:blob, :logs_tree]
|
||||
|
||||
def switch
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
new_path = if params[:destination] == "tree"
|
||||
tree_project_ref_path(@project, params[:ref])
|
||||
project_tree_path(@project, @ref)
|
||||
else
|
||||
project_commits_path(@project, ref: params[:ref])
|
||||
project_commits_path(@project, @ref)
|
||||
end
|
||||
|
||||
redirect_to new_path
|
||||
redirect_to new_path
|
||||
end
|
||||
format.js do
|
||||
format.js do
|
||||
@ref = params[:ref]
|
||||
define_tree_vars
|
||||
render "tree"
|
||||
|
@ -31,19 +28,6 @@ class RefsController < ProjectController
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Repository preview
|
||||
#
|
||||
def tree
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js do
|
||||
# disable cache to allow back button works
|
||||
no_cache_headers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def logs_tree
|
||||
contents = @tree.contents
|
||||
@logs = contents.map do |content|
|
||||
|
@ -51,36 +35,12 @@ class RefsController < ProjectController
|
|||
last_commit = @project.commits(@commit.id, file, 1).last
|
||||
last_commit = CommitDecorator.decorate(last_commit)
|
||||
{
|
||||
file_name: content.name,
|
||||
file_name: content.name,
|
||||
commit: last_commit
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def blob
|
||||
if @tree.is_blob?
|
||||
if @tree.text?
|
||||
encoding = detect_encoding(@tree.data)
|
||||
mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
|
||||
else
|
||||
mime_type = @tree.mime_type
|
||||
end
|
||||
|
||||
send_data(
|
||||
@tree.data,
|
||||
type: mime_type,
|
||||
disposition: 'inline',
|
||||
filename: @tree.name
|
||||
)
|
||||
else
|
||||
head(404)
|
||||
end
|
||||
end
|
||||
|
||||
def blame
|
||||
@blame = Grit::Blob.blame(@repo, @commit.id, params[:path])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def define_tree_vars
|
||||
|
@ -91,20 +51,20 @@ class RefsController < ProjectController
|
|||
@commit = CommitDecorator.decorate(@commit)
|
||||
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
|
||||
@tree = TreeDecorator.new(@tree)
|
||||
@hex_path = Digest::SHA1.hexdigest(params[:path] || "/")
|
||||
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
|
||||
|
||||
if params[:path]
|
||||
@history_path = tree_file_project_ref_path(@project, @ref, params[:path])
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
|
||||
@history_path = project_tree_path(@project, File.join(@ref, params[:path]))
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
|
||||
else
|
||||
@history_path = tree_project_ref_path(@project, @ref)
|
||||
@logs_path = logs_tree_project_ref_path(@project, @ref)
|
||||
@history_path = project_tree_path(@project, @ref)
|
||||
@logs_path = logs_tree_project_ref_path(@project, @ref)
|
||||
end
|
||||
rescue
|
||||
return render_404
|
||||
end
|
||||
|
||||
|
||||
def ref
|
||||
@ref = params[:id]
|
||||
@ref = params[:id] || params[:ref]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,18 +3,17 @@ class RepositoriesController < ProjectController
|
|||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
before_filter :render_full_content
|
||||
|
||||
def show
|
||||
@activities = @project.commits_with_refs(20)
|
||||
end
|
||||
|
||||
def branches
|
||||
@branches = @project.repo.heads.sort_by(&:name)
|
||||
@branches = @project.branches
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags = @project.repo.tags.sort_by(&:name).reverse
|
||||
@tags = @project.tags
|
||||
end
|
||||
|
||||
def archive
|
||||
|
|
|
@ -50,7 +50,6 @@ class SnippetsController < ProjectController
|
|||
|
||||
def show
|
||||
@note = @project.notes.new(noteable: @snippet)
|
||||
render_full_content
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
29
app/controllers/tree_controller.rb
Normal file
29
app/controllers/tree_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Controller for viewing a repository's file structure
|
||||
class TreeController < ApplicationController
|
||||
include ExtractsPath
|
||||
|
||||
layout "project"
|
||||
|
||||
before_filter :project
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :assign_ref_vars
|
||||
|
||||
def show
|
||||
@hex_path = Digest::SHA1.hexdigest(@path)
|
||||
|
||||
@history_path = project_tree_path(@project, @id)
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
# Disable cache so browser history works
|
||||
format.js { no_cache_headers }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue