Project

General

Profile

Actions

Defect #36581

open

Clicking the "New repository" button causes a 404 error

Added by Go MAEDA over 2 years ago. Updated over 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
SCM
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

When you attempt to create a new repository setting by clicking the "New repository" button in the Repositories tab of the project settings, you may encounter a 404 error.

The error occurs when no SCM is enabled in Administration > Settings > Repositories > Enabled SCM, at RepositoriesController::build_new_repository_from_params.

  def build_new_repository_from_params
    scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
    unless @repository = Repository.factory(scm)
      render_404
      return
    end

With a 404 error, it is difficult for users to know how to resolve it. I think Redmine should output a more informative error message.

Actions #1

Updated by Mizuki ISHIKAWA over 2 years ago

If there is no enabled SCM, how about show the message instead of the "New repository" link?
I think it would be even better if, in addition to this, it returns error_enabled_scm_not_exist instead of render_404.

diff --git a/app/views/projects/settings/_repositories.html.erb b/app/views/projects/settings/_repositories.html.erb
index 8ae2ba25bf..5005e96971 100644
--- a/app/views/projects/settings/_repositories.html.erb
+++ b/app/views/projects/settings/_repositories.html.erb
@@ -1,5 +1,9 @@
 <% if User.current.allowed_to?(:manage_repository, @project) %>
-  <p><%= link_to l(:label_repository_new), new_project_repository_path(@project), :class => 'icon icon-add' %></p>
+  <% if (Redmine::Scm::Base.all & Setting.enabled_scm).present? %>
+    <p><%= link_to l(:label_repository_new), new_project_repository_path(@project), :class => 'icon icon-add' %></p>
+  <% else %>
+    <div class="flash warning"><%= l(:error_enabled_scm_not_exist) %></div>
+  <% end %>
 <% end %>

 <% if @project.repositories.any? %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2378e56d5b..69ec6b27a0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -196,6 +196,7 @@ en:
   notice_invalid_watcher: "Invalid watcher: User will not receive any notifications because it does not have access to view this object." 

   error_can_t_load_default_data: "Default configuration could not be loaded: %{value}" 
+  error_enabled_scm_not_exist: Enabled SCM does not exist.
   error_scm_not_found: "The entry or revision was not found in the repository." 
   error_scm_command_failed: "An error occurred when trying to access the repository: %{value}" 
   error_scm_annotate: "The entry does not exist or cannot be annotated." 
Actions #2

Updated by Go MAEDA over 2 years ago

Mizuki ISHIKAWA wrote:

If there is no enabled SCM, how about show the message instead of the "New repository" link?
I think it would be even better if, in addition to this, it returns error_enabled_scm_not_exist instead of render_404.

[...]

Thank you for your suggestion. But I see a minor problem in the patch that you will see "The page you were trying to access doesn't exist or has been removed" even after applying the patch by directly accessing /projects/ecookbook/repositories/new. In order to avoid this, I think it is better to check if any SCM is enabled in a controller than a view like this. Also, the message in the original patch is obvious and a bit obtrusive for me.

The following is my suggestion.

diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index fe55e1770..dce923cab 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -312,7 +312,11 @@ class RepositoriesController < ApplicationController
   private

   def build_new_repository_from_params
-    scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
+    if (available_scms = Redmine::Scm::Base.all & Setting.enabled_scm).empty?
+      render_error :message => :error_scm_not_enabled, :status => 403
+      return
+    end
+    scm = params[:repository_scm] || available_scms.first
     unless @repository = Repository.factory(scm)
       render_404
       return
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2378e56d5..7eaac9c9b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -197,6 +197,7 @@ en:

   error_can_t_load_default_data: "Default configuration could not be loaded: %{value}" 
   error_scm_not_found: "The entry or revision was not found in the repository." 
+  error_scm_not_enabled: "There is no enabled SCM." 
   error_scm_command_failed: "An error occurred when trying to access the repository: %{value}" 
   error_scm_annotate: "The entry does not exist or cannot be annotated." 
   error_scm_annotate_big_text_file: "The entry cannot be annotated, as it exceeds the maximum text file size." 
Actions

Also available in: Atom PDF