From dbad26c87db8247c0d635c993981d4277e165978 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 31 Aug 2008 12:59:57 +0000 Subject: [PATCH] Adds an option to generate sequential project identifiers. Disabled by default, it can be enabled on the 'Projects' tab in application settings. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1777 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 1 + app/helpers/settings_helper.rb | 1 + app/models/project.rb | 6 ++++++ app/views/settings/_general.rhtml | 3 --- app/views/settings/_projects.rhtml | 12 ++++++++++++ config/settings.yml | 2 ++ lang/bg.yml | 1 + lang/cs.yml | 1 + lang/da.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fi.yml | 1 + lang/fr.yml | 1 + lang/he.yml | 1 + lang/hu.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/lt.yml | 1 + lang/nl.yml | 1 + lang/no.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/ru.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/th.yml | 1 + lang/uk.yml | 1 + lang/zh-tw.yml | 1 + lang/zh.yml | 1 + test/unit/project_test.rb | 11 +++++++++++ 34 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 app/views/settings/_projects.rhtml diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 43d35cf4..0d83d81b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -69,6 +69,7 @@ class ProjectsController < ApplicationController :order => 'name') @project = Project.new(params[:project]) if request.get? + @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? @project.trackers = Tracker.all @project.is_public = Setting.default_projects_public? @project.enabled_module_names = Redmine::AccessControl.available_project_modules diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index d88269f7..47e69133 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -19,6 +19,7 @@ module SettingsHelper def administration_settings_tabs tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general}, {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication}, + {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural}, {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking}, {:name => 'notifications', :partial => 'settings/notifications', :label => l(:field_mail_notification)}, {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => l(:label_incoming_emails)}, diff --git a/app/models/project.rb b/app/models/project.rb index 9e4bd697..adc70c64 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -238,6 +238,12 @@ class Project < ActiveRecord::Base enabled_modules << EnabledModule.new(:name => name.to_s) end end + + # Returns an auto-generated project identifier based on the last identifier used + def self.next_identifier + p = Project.find(:first, :order => 'created_on DESC') + p.nil? ? nil : p.identifier.to_s.succ + end protected def validate diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml index 1d17a003..bb56c43d 100644 --- a/app/views/settings/_general.rhtml +++ b/app/views/settings/_general.rhtml @@ -46,9 +46,6 @@

<%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %>

- -

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

<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_projects.rhtml b/app/views/settings/_projects.rhtml new file mode 100644 index 00000000..1cd4f6e9 --- /dev/null +++ b/app/views/settings/_projects.rhtml @@ -0,0 +1,12 @@ +<% form_tag({:action => 'edit', :tab => 'projects'}) do %> + +
+

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

+ +

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

+
+ +<%= submit_tag l(:button_save) %> +<% end %> diff --git a/config/settings.yml b/config/settings.yml index ac79edb8..e1ad341d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -118,6 +118,8 @@ display_subprojects_issues: default: 1 default_projects_public: default: 1 +sequential_project_identifiers: + default: 0 # encodings used to convert repository files content to UTF-8 # multiple values accepted, comma separated repositories_encodings: diff --git a/lang/bg.yml b/lang/bg.yml index 1f174e29..ddc3368e 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/cs.yml b/lang/cs.yml index 609e9547..767fcdbd 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -641,3 +641,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/da.yml b/lang/da.yml index a76e7ea5..8f8905f3 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -638,3 +638,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/de.yml b/lang/de.yml index e309dfb5..1f6c6291 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/en.yml b/lang/en.yml index 5f552774..c9dddf9c 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -219,6 +219,7 @@ setting_display_subprojects_issues: Display subprojects issues on main projects setting_enabled_scm: Enabled SCM setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +setting_sequential_project_identifiers: Generate sequential project identifiers project_module_issue_tracking: Issue tracking project_module_time_tracking: Time tracking diff --git a/lang/es.yml b/lang/es.yml index fc9540a0..e4b4f066 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -639,3 +639,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/fi.yml b/lang/fi.yml index 6eb16bfa..3ec7a6b5 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/fr.yml b/lang/fr.yml index 81e44949..f40a3f3d 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -220,6 +220,7 @@ setting_display_subprojects_issues: Afficher par défaut les demandes des sous-p setting_enabled_scm: SCM activés setting_mail_handler_api_enabled: "Activer le WS pour la réception d'emails" setting_mail_handler_api_key: Clé de protection de l'API +setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels 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 77fe32e5..e89e65c6 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/hu.yml b/lang/hu.yml index 208b6fe1..f8bfb93e 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/it.yml b/lang/it.yml index d123e913..e1ef6f8f 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/ja.yml b/lang/ja.yml index 5a728fb0..dda73dc2 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/ko.yml b/lang/ko.yml index 16bd6536..be7eab1f 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/lt.yml b/lang/lt.yml index 2a75a95e..da581d67 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -639,3 +639,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/nl.yml b/lang/nl.yml index f79e7899..b1c5756b 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/no.yml b/lang/no.yml index 6643f9c8..7113b416 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/pl.yml b/lang/pl.yml index 2df921b7..e9ffcda2 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 8cd171b7..b4064bf5 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/pt.yml b/lang/pt.yml index 5562ca4a..1d4d043f 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/ro.yml b/lang/ro.yml index 5bb49ece..acb5ff8e 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -636,3 +636,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/ru.yml b/lang/ru.yml index 01cdcd47..b0e137aa 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -640,3 +640,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/sr.yml b/lang/sr.yml index 566a46d9..4e262369 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/sv.yml b/lang/sv.yml index 4cb1f073..3bb337e3 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/th.yml b/lang/th.yml index 2c3977de..a9708716 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -639,3 +639,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/uk.yml b/lang/uk.yml index 7ba15241..cb4e1738 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -638,3 +638,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 6a144136..b91bef8f 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -637,3 +637,4 @@ field_parent_title: Parent page label_issue_watchers: Watchers setting_commit_logs_encoding: Commit messages encoding button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/lang/zh.yml b/lang/zh.yml index bfe55109..dbc53111 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -637,3 +637,4 @@ enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) button_quote: Quote +setting_sequential_project_identifiers: Generate sequential project identifiers diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 91fab820..6e32c02e 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -130,4 +130,15 @@ class ProjectTest < Test::Unit::TestCase assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) end + + def test_next_identifier + ProjectCustomField.delete_all + Project.create!(:name => 'last', :identifier => 'p2008040') + assert_equal 'p2008041', Project.next_identifier + end + + def test_next_identifier_first_project + Project.delete_all + assert_nil Project.next_identifier + end end