From 12463c9c052c8a862a9151632ec973bd92148be6 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 19 Mar 2020 16:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9repository=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=A1=B9=E7=9B=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index abb891c..e0d65a3 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,10 +1,11 @@ class RepositoriesController < ApplicationController include ApplicationHelper - before_action :find_user, :find_repository, :authorizate! + before_action :find_project_identifier + before_action :find_repository_with_project + before_action :find_user, :authorizate! before_action :require_login, only: %i[edit] def show - @project = @repo.project @branches_count = Gitea::Repository::BranchesService.new(@user, @repo.identifier).call&.size @commits_count = Gitea::Repository::Commits::ListService.new(@user, @repo.identifier).call[:total_count] @result = Gitea::Repository::GetService.new(@user, @repo.identifier).call @@ -14,7 +15,7 @@ class RepositoriesController < ApplicationController end def entries - @repo.project.increment!(:visits) + @project.increment!(:visits) @ref = params[:branch] || "master" @entries = Gitea::Repository::Entries::ListService.new(@user, @repo.identifier, ref:@ref).call @entries = @entries.sort_by{ |hash| hash['type'] } @@ -53,4 +54,14 @@ class RepositoriesController < ApplicationController render_forbidden end end + + def find_project_identifier + @project = Project.find_by(id: params[:repo_identifier]) + render_not_found("未找到’#{params[:repo_identifier]}’相关的项目") unless @project + end + + def find_repository_with_project + @repo = @project.repository + render_not_found("未找到’#{params[:repo_identifier]}’相关的仓库") unless @repo + end end