summaryrefslogtreecommitdiff
path: root/app/controllers/projects/application_controller.rb
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-05-07 15:00:58 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-05-07 15:00:58 +0100
commit842918602dbe622dc20593c0abea5293e304ac62 (patch)
treec748164aab8cfa43fe3332640c60e3308b4e9c29 /app/controllers/projects/application_controller.rb
parent214d7880c3d651b367eb73651a6e0e3046868287 (diff)
parent6ad3814e1b31bfacfae7a2aabb4e4607b12ca66f (diff)
downloadgitlab-ce-remove-old-isobject.tar.gz
Merge branch 'master' into remove-old-isobjectremove-old-isobject
* master: (226 commits) Real time pipeline show action Fix `Routable.find_by_full_path` on MySQL add CHANGELOG.md entry for !11138 add tooltips to user contrib graph key Use an absolute path for locale path in FastGettext config Colorize labels in issue search field Fix Karma failures for jQuery deferreds Reduce risk of deadlocks Fix failing spec and eslint Resolve discussions Resolve discussions Dry up routable lookups. Fixes #30317 Add “project moved” flash message on redirect Resolve discussions Fix Rubocop failures Index redirect_routes path for LIKE Add index for source association and for path Fix or workaround spec failure Refactor Delete conflicting redirects ...
Diffstat (limited to 'app/controllers/projects/application_controller.rb')
-rw-r--r--app/controllers/projects/application_controller.rb57
1 files changed, 22 insertions, 35 deletions
diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb
index 89f1128ec36..12e4a6999ae 100644
--- a/app/controllers/projects/application_controller.rb
+++ b/app/controllers/projects/application_controller.rb
@@ -1,5 +1,8 @@
class Projects::ApplicationController < ApplicationController
+ include RoutableActions
+
skip_before_action :authenticate_user!
+ before_action :redirect_git_extension
before_action :project
before_action :repository
layout 'project'
@@ -8,40 +11,22 @@ class Projects::ApplicationController < ApplicationController
private
+ def redirect_git_extension
+ # Redirect from
+ # localhost/group/project.git
+ # to
+ # localhost/group/project
+ #
+ redirect_to url_for(params.merge(format: nil)) if params[:format] == 'git'
+ end
+
def project
- unless @project
- namespace = params[:namespace_id]
- id = params[:project_id] || params[:id]
-
- # Redirect from
- # localhost/group/project.git
- # to
- # localhost/group/project
- #
- if params[:format] == 'git'
- redirect_to request.original_url.gsub(/\.git\/?\Z/, '')
- return
- end
-
- project_path = "#{namespace}/#{id}"
- @project = Project.find_by_full_path(project_path)
-
- if can?(current_user, :read_project, @project) && !@project.pending_delete?
- if @project.path_with_namespace != project_path
- redirect_to request.original_url.gsub(project_path, @project.path_with_namespace)
- end
- else
- @project = nil
-
- if current_user.nil?
- authenticate_user!
- else
- render_404
- end
- end
- end
+ return @project if @project
+
+ path = File.join(params[:namespace_id], params[:project_id] || params[:id])
+ auth_proc = ->(project) { !project.pending_delete? }
- @project
+ @project = find_routable!(Project, path, extra_authorization_proc: auth_proc)
end
def repository
@@ -55,13 +40,15 @@ class Projects::ApplicationController < ApplicationController
(current_user && current_user.already_forked?(project))
end
- def authorize_project!(action)
- return access_denied! unless can?(current_user, action, project)
+ def authorize_action!(action)
+ unless can?(current_user, action, project)
+ return access_denied!
+ end
end
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s =~ /\Aauthorize_(.*)!\z/
- authorize_project!($1.to_sym)
+ authorize_action!($1.to_sym)
else
super
end