From: Jean-Philippe Lang Date: Sun, 8 Jun 2008 14:59:26 +0000 (+0000) Subject: Ability to disable unused SCM adapters in application settings. X-Git-Tag: 0.8.0-RC1~474 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dfe62d7f51b4aadb1034e2e64de2524b30dfd17b;p=redmine.git Ability to disable unused SCM adapters in application settings. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1507 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 64eb05793..ea3b117d9 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,9 +34,9 @@ class RepositoriesController < ApplicationController @repository = @project.repository if !@repository @repository = Repository.factory(params[:repository_scm]) - @repository.project = @project + @repository.project = @project if @repository end - if request.post? + if request.post? && @repository @repository.attributes = params[:repository] @repository.save end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 22bdec9df..d2cc664e6 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -48,10 +48,13 @@ module RepositoriesHelper end def scm_select_tag(repository) - container = [[]] - REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]} + scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] + REDMINE_SUPPORTED_SCM.each do |scm| + scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) + end + select_tag('repository_scm', - options_for_select(container, repository.class.name.demodulize), + options_for_select(scm_options, repository.class.name.demodulize), :disabled => (repository && !repository.new_record?), :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") ) diff --git a/app/models/repository.rb b/app/models/repository.rb index 1ea77f24f..e6ed7da52 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -19,7 +19,10 @@ class Repository < ActiveRecord::Base belongs_to :project has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" has_many :changes, :through => :changesets - + + # Checks if the SCM is enabled when creating a repository + validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) } + # Removes leading and trailing whitespace def url=(arg) write_attribute(:url, arg ? arg.to_s.strip : nil) diff --git a/app/views/projects/settings/_repository.rhtml b/app/views/projects/settings/_repository.rhtml index 95830ab98..dcfabbbf0 100644 --- a/app/views/projects/settings/_repository.rhtml +++ b/app/views/projects/settings/_repository.rhtml @@ -17,5 +17,5 @@ :class => 'icon icon-del') if @repository && !@repository.new_record? %> -<%= submit_tag((@repository.nil? || @repository.new_record?) ? l(:button_create) : l(:button_save)) %> +<%= submit_tag((@repository.nil? || @repository.new_record?) ? l(:button_create) : l(:button_save), :disabled => @repository.nil?) %> <% end %> diff --git a/app/views/settings/_repositories.rhtml b/app/views/settings/_repositories.rhtml index 59b3b51de..127801be2 100644 --- a/app/views/settings/_repositories.rhtml +++ b/app/views/settings/_repositories.rhtml @@ -7,6 +7,13 @@

<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %>

+

+<% REDMINE_SUPPORTED_SCM.each do |scm| -%> +<%= check_box_tag 'settings[enabled_scm][]', scm, Setting.enabled_scm.include?(scm) %> <%= scm %> +<% end -%> +<%= hidden_field_tag 'settings[enabled_scm][]', '' %> +

+

<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>

diff --git a/config/settings.yml b/config/settings.yml index bb501823e..616665f23 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -59,6 +59,15 @@ protocol: feeds_limit: format: int default: 15 +enabled_scm: + serialized: true + default: + - Subversion + - Darcs + - Mercurial + - Cvs + - Bazaar + - Git autofetch_changesets: default: 1 sys_api_enabled: diff --git a/lang/bg.yml b/lang/bg.yml index 6ab6f26c6..5f3548684 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/cs.yml b/lang/cs.yml index 7413b79dd..26e0f5131 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -628,3 +628,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/da.yml b/lang/da.yml index 2107498ad..b2f18db4c 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -625,3 +625,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/de.yml b/lang/de.yml index 27d22fc54..1e4040f3d 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/en.yml b/lang/en.yml index 262570f1d..b7f217e6c 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -213,6 +213,7 @@ setting_per_page_options: Objects per page options setting_user_format: Users display format setting_activity_days_default: Days displayed on project activity setting_display_subprojects_issues: Display subprojects issues on main projects by default +setting_enabled_scm: Enabled SCM project_module_issue_tracking: Issue tracking project_module_time_tracking: Time tracking diff --git a/lang/es.yml b/lang/es.yml index 62528e688..c0ecb997b 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -626,3 +626,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/fi.yml b/lang/fi.yml index b32bbb259..6ac4aea7e 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/fr.yml b/lang/fr.yml index 8b040463f..4db2f8f3a 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -214,6 +214,7 @@ setting_per_page_options: Options d'objets affichés par page setting_user_format: Format d'affichage des utilisateurs setting_activity_days_default: Nombre de jours affichés sur l'activité des projets setting_display_subprojects_issues: Afficher par défaut les demandes des sous-projets sur les projets principaux +setting_enabled_scm: SCM activés project_module_issue_tracking: Suivi des demandes project_module_time_tracking: Suivi du temps passé diff --git a/lang/he.yml b/lang/he.yml index da31812cf..e23698d32 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/hu.yml b/lang/hu.yml index 2a399bc13..64518271c 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d neked kiosztott feladat határidős az elkövetkező %d mail_subject_reminder: "%d feladat határidős az elkövetkező napokban" text_user_wrote: '%s írta:' label_duplicated_by: duplikálta +setting_enabled_scm: Enabled SCM diff --git a/lang/it.yml b/lang/it.yml index e5557f915..5ab9ad310 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/ja.yml b/lang/ja.yml index 1ae9ab1b6..c693d68e5 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/ko.yml b/lang/ko.yml index c00a9e9a0..af1c768af 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/lt.yml b/lang/lt.yml index 140631fcf..ff8f6b695 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -625,3 +625,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/nl.yml b/lang/nl.yml index 62bbc1468..9ee913848 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/no.yml b/lang/no.yml index a31751da6..e3b88b110 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -624,3 +624,4 @@ default_activity_development: Utvikling enumeration_issue_priorities: Sakssprioriteringer enumeration_doc_categories: Dokument-kategorier enumeration_activities: Aktiviteter (tidssporing) +setting_enabled_scm: Enabled SCM diff --git a/lang/pl.yml b/lang/pl.yml index adf676210..75e04ecd4 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/pt-br.yml b/lang/pt-br.yml index ca9b9073b..dabab5bfe 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/pt.yml b/lang/pt.yml index f9472b7ea..2845f390c 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/ro.yml b/lang/ro.yml index 840fa7073..dd51e59be 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -623,3 +623,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/ru.yml b/lang/ru.yml index 37f2aef30..c3ec91897 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -627,3 +627,4 @@ mail_body_reminder: "%d назначенных на вас задач на сл mail_subject_reminder: "%d назначенных на вас задач в ближайшие дни" text_user_wrote: '%s написал:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/sr.yml b/lang/sr.yml index d507a1d97..92906760b 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/sv.yml b/lang/sv.yml index fbd7c5c40..f08e45eb0 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -624,3 +624,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/th.yml b/lang/th.yml index 9dfaf2865..85a1f8c01 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -626,3 +626,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/uk.yml b/lang/uk.yml index beabfd1f0..ae8c5cbc0 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -625,3 +625,4 @@ mail_body_reminder: "%d issue(s) that are assigned to you are due in the next %d mail_subject_reminder: "%d issue(s) due in the next days" text_user_wrote: '%s wrote:' label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index c3cd096a3..2ee595dcd 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -624,3 +624,4 @@ default_activity_development: 開發 enumeration_issue_priorities: 項目優先權 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) +setting_enabled_scm: Enabled SCM diff --git a/lang/zh.yml b/lang/zh.yml index 9e22e6874..d82363414 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -624,3 +624,4 @@ enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) label_duplicated_by: duplicated by +setting_enabled_scm: Enabled SCM diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 7764ee04a..270b0bea1 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -45,6 +45,14 @@ class RepositoryTest < Test::Unit::TestCase assert_equal repository, project.repository end + def test_should_not_create_with_disabled_scm + # disable Subversion + Setting.enabled_scm = ['Darcs', 'Git'] + repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") + assert !repository.save + assert_equal :activerecord_error_invalid, repository.errors.on(:type) + end + def test_scan_changesets_for_issue_ids # choosing a status to apply to fix issues Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id