diff --git a/app/controllers/issue_tags_controller.rb b/app/controllers/issue_tags_controller.rb index 82bcc2c20..3cb22b074 100644 --- a/app/controllers/issue_tags_controller.rb +++ b/app/controllers/issue_tags_controller.rb @@ -121,7 +121,7 @@ class IssueTagsController < ApplicationController private def set_project - @project = Project.find_by_id(params[:project_id]) + @project = Project.find_by_identifier! params[:id] @repository = @project.repository @user = @project.owner normal_status(-1, "项目不存在") unless @project.present? diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 33235b2ce..e7fabc949 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,6 +1,7 @@ class IssuesController < ApplicationController before_action :require_login, except: [:index, :show] - before_action :set_project + before_action :find_project + before_action :set_user before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] before_action :check_issue_permission, except: [:index, :show, :index_chosen] before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :index_chosen, :close_issue, :lock_issue] @@ -341,10 +342,8 @@ class IssuesController < ApplicationController end private - def set_project - @project = Project.find_by_id(params[:project_id]) + def set_user @user = @project.owner - normal_status(-1, "项目不存在") unless @project.present? normal_status(-1, "用户不存在") unless @user.present? end diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index 84821ba65..dcd2d4706 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -1,5 +1,5 @@ class ProjectTrendsController < ApplicationController - before_action :set_project + before_action :find_project before_action :check_project_public def index @@ -34,13 +34,6 @@ class ProjectTrendsController < ApplicationController private - def set_project - @project = Project.find_by_id(params[:project_id]) - unless @project.present? - normal_status(-1, "项目不存在") - end - end - def check_project_public unless @project.is_public || @project.member?(current_user) || current_user.admin? normal_status(-1, "您没有权限") diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 655a8cdfc..83b52c8d7 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -343,7 +343,7 @@ class PullRequestsController < ApplicationController private def set_project - @project = Project.find_by_id(params[:project_id]) + @project = Project.find_by_identifier! params[:id] @repository = @project.repository @user = @project.owner normal_status(-1, "项目不存在") unless @project.present? diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 2ea398f60..ffedc0aa3 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -1,6 +1,6 @@ class VersionsController < ApplicationController before_action :require_login - before_action :set_project + before_action :find_project before_action :check_issue_permission, except: [:show, :index] before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status] @@ -129,13 +129,6 @@ class VersionsController < ApplicationController private - def set_project - @project = Project.find_by_id(params[:project_id]) - unless @project.present? - normal_status(-1, "项目不存在") - end - end - def check_issue_permission unless @project.member?(current_user) || current_user.admin? normal_status(-1, "您没有权限")