From d6fe167d2d1d71afb5a467400c4f61e2477f002e Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Thu, 8 May 2014 18:07:35 +0400 Subject: [PATCH] Initial commit --- README.rdoc | 3 + app/controllers/delete_project_controller.rb | 68 +++++++++++++++++++ app/views/delete_project/index.html.erb | 26 +++++++ app/views/delete_project/submit.html.erb | 1 + app/views/settings/_delete_project.html.erb | 29 ++++++++ config/locales/en.yml | 31 +++++++++ config/locales/ja.yml | 31 +++++++++ config/routes.rb | 4 ++ init.rb | 28 ++++++++ procedure.sql | 25 +++++++ .../delete_project_controller_test0000644 | 8 +++ test/test_helper.rb | 5 ++ 12 files changed, 259 insertions(+) create mode 100644 README.rdoc create mode 100644 app/controllers/delete_project_controller.rb create mode 100644 app/views/delete_project/index.html.erb create mode 100644 app/views/delete_project/submit.html.erb create mode 100644 app/views/settings/_delete_project.html.erb create mode 100644 config/locales/en.yml create mode 100644 config/locales/ja.yml create mode 100644 config/routes.rb create mode 100644 init.rb create mode 100644 procedure.sql create mode 100644 test/functional/delete_project_controller_test0000644 create mode 100644 test/test_helper.rb diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..c67d8c6 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += supprime_projet + +Description goes here diff --git a/app/controllers/delete_project_controller.rb b/app/controllers/delete_project_controller.rb new file mode 100644 index 0000000..408dbee --- /dev/null +++ b/app/controllers/delete_project_controller.rb @@ -0,0 +1,68 @@ +class DeleteProjectController < ApplicationController + + # For the authorizations, applies filter and the function to define the current project (in the bottom of this file) + before_filter :find_project, :authorize, :only => [:index, :valider] + + + def index + @dead_project = Project.find(params[:project_id]) + + res= Array.new + + # The project ID + project_id= @dead_project["id"] + + # Check if there are sub-projects + # (which have not been already marked as deleted - thanks to Luis Serrano Aranda for the feedback) + status_number= Setting['plugin_redmine_delete_project']['status_number'].to_i + res= Project.find_by_sql("SELECT * FROM projects WHERE ( parent_id=#{project_id} AND status!=#{status_number} )") + @subprojects= res.length + + # String to type for confirmation + @ok= I18n.t("global.confirm_string") + end + + + def submit + ok= I18n.t("global.confirm_string") + # Get the settings + status_number= Setting['plugin_redmine_delete_project']['status_number'].to_i + chmod= Setting['plugin_redmine_delete_project']['chmod'] + destroy= Setting['plugin_redmine_delete_project']['destroy'] + repos_path= Setting['plugin_redmine_delete_project']['repos_path'] + "/" + + if params[:confirm][0] == ok + dead_project= Project.find_by_identifier(params[:dead_project]) + if destroy == "yes" + res= dead_project.destroy + else + dead_project.status= status_number + res= dead_project.save + end + + if res + flash[:notice]= I18n.t("project_delete.done") + if chmod == "yes" + File.chmod 0000, repos_path + dead_project.identifier + end + else + flash[:error]= I18n.t("project_delete.error") + end + + else + flash[:notice]= I18n.t("project_delete.unconfirmed", :ok => ok) + end + end + + + private + def find_project + # @project variable must be set before calling the authorize filter + @project = Project.find(params[:project_id]) + end + +end + + + + diff --git a/app/views/delete_project/index.html.erb b/app/views/delete_project/index.html.erb new file mode 100644 index 0000000..e960c71 --- /dev/null +++ b/app/views/delete_project/index.html.erb @@ -0,0 +1,26 @@ +

<%= I18n.t("index.title") %>

+ +<% if @subprojects != 0 %> +<%= I18n.t("index.subprojects_exist") %> +<% else %> +<%= I18n.t("index.attention") %>: +<%= I18n.t("index.warning", :dead_project => @dead_project, :ok => @ok).html_safe %> + + +<%= form_tag :controller=>'delete_project', :action=>'submit' do %> + + + +
<%= I18n.t("index.are_you_sure") %> + <%= text_field :confirm, params[:confirm], :size => 20 %> + <%= hidden_field :dead_project, params[:dead_project], :value => params[:project_id] %>
+ + +<%= submit_tag I18n.t("index.submit_button") %> + +<% end %> + + +<% end # End du IF @subprojects %> + + diff --git a/app/views/delete_project/submit.html.erb b/app/views/delete_project/submit.html.erb new file mode 100644 index 0000000..52abe62 --- /dev/null +++ b/app/views/delete_project/submit.html.erb @@ -0,0 +1 @@ +

DeleteProject#submit

diff --git a/app/views/settings/_delete_project.html.erb b/app/views/settings/_delete_project.html.erb new file mode 100644 index 0000000..69e2b70 --- /dev/null +++ b/app/views/settings/_delete_project.html.erb @@ -0,0 +1,29 @@ + +<%=I18n.t "settings.destroy" %>: +<%= select_tag 'settings[destroy]', options_for_select([ + [t("settings.affirmative"), "yes"], + [t("settings.negative"), "no"] + ], @settings['destroy'])%> + +

+ +<%= I18n.t "settings.status_number" %>: +<%= text_field_tag("settings[status_number]", @settings["status_number"]) %> + + +

+ + +<%=I18n.t "settings.chmod" %>: +<%= select_tag 'settings[chmod]', options_for_select([ + [t("settings.affirmative"), "yes"], + [t("settings.negative"), "no"] + ], @settings['chmod'])%> + +

+ +<%= I18n.t "settings.repos_path" %>: +<%= text_field_tag("settings[repos_path]", @settings["repos_path"]) %> + + + diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..e79e4f0 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,31 @@ +# English strings go here for Rails i18n +en: + label_feature_name: "Delete Project" + + project_module_delete_project: "Delete Project" + + permission_delete_project: "Delete Project" + + global: + confirm_string: "yes" + + project_delete: + error: "An error occured, the project has not been deleted" + unconfirmed: "Project deletion cancelled (you didn't confirm by saying '%{ok}')" + done: "The project has been deleted" + + index: + title: "Delete a project" + subprojects_exist: "Sub-projects are linked with this project. Delete them first." + attention: "Attention" + warning: "You are going to delete the project %{dead_project}.
This will be definitive. Please answer '%{ok}' to confirm." + are_you_sure: "Are you sure?" + submit_button: "Confirm" + + settings: + affirmative: "Yes" + negative: "No" + destroy: "Really delete the project from the database" + status_number: "(If no delete:) Which value should be assigned to the status DELETED" + chmod: "Apply a 'chmod 000' on the repository" + repos_path: "(If chmod is executed:) Path of the repositories" diff --git a/config/locales/ja.yml b/config/locales/ja.yml new file mode 100644 index 0000000..032df0c --- /dev/null +++ b/config/locales/ja.yml @@ -0,0 +1,31 @@ +# Japanese strings go here for Rails i18n +ja: + label_feature_name: "プロジェクト消去" + + project_module_delete_project: "プロジェクト消去" + + permission_delete_project: "プロジェクト消去" + + global: + confirm_string: "はい" + + project_delete: + error: "エラーが発生したので、プロジェクトは消去されませんでした" + unconfirmed: "プロジェクト消去はキャンセルされました ('%{ok}'と入力されませんでした)" + done: "プロジェクトは消去されました" + + index: + title: "プロジェクト消去" + subprojects_exist: "サブプロジェクトが存在しますので、先にそれらを消去してから実行してください" + attention: "警告" + warning: "このプロジェクトを消去しようとしています %{dead_project}.
この操作は元にもどせません、確認の為 '%{ok}'と入力してください." + are_you_sure: "よろしいですか?" + submit_button: "確認" + + settings: + affirmative: "Yes" + negative: "No" + destroy: "Really delete the project from the database" + status_number: "(If no delete:) Which value should be assigned to the status DELETED" + chmod: "Apply a 'chmod 000' on the repository" + repos_path: "(If chmod is executed:) Path of the repositories" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..8c43daf --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,4 @@ +RedmineApp::Application.routes.draw do + #map.connect 'projects/:id/code_review/:action', :controller => 'code_review' + match 'projects/:id/delete_project/:action', :controller => 'delete_project', :via => [:get, :post] +end diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..fd2624f --- /dev/null +++ b/init.rb @@ -0,0 +1,28 @@ +require 'redmine' + +Redmine::Plugin.register :redmine_delete_project do + name 'Redmine Delete Project plugin' + author 'Anthony Paul' + description 'Adds an ACL to allow project deletion by non-admin users' + version '0.0.4' + + project_module :delete_project do + permission :delete_project, {:delete_project => [:index, :submit]} + end + menu :project_menu, :delete_project, { :controller => 'delete_project', :action => 'index' }, + :caption => :label_feature_name, + :after => :activity, + :param => :project_id + + +# Configure options +settings_defaults = { + 'destroy' => "no", + 'chmod' => "no", + 'repos_path' => "/var/svn", + 'status_number' => "1001" +} +settings :default => settings_defaults, :partial => 'settings/delete_project' + +end + diff --git a/procedure.sql b/procedure.sql new file mode 100644 index 0000000..fed715b --- /dev/null +++ b/procedure.sql @@ -0,0 +1,25 @@ +DROP PROCEDURE IF EXISTS update_project_enable_module; +DELIMITER | +CREATE PROCEDURE update_project_enable_module() +BEGIN + DECLARE c_project_id INT(11); + + DECLARE curs_project_id CURSOR + FOR SELECT id + FROM projects + WHERE id NOT IN ( + SELECT project_id + FROM enabled_modules + WHERE name LIKE 'delete_project' ); + + OPEN curs_project_id; + + LOOP + FETCH curs_project_id INTO c_project_id; + -- SELECT GROUP_CONCAT(name) FROM enabled_modules WHERE project_id=c_project_id; + INSERT INTO enabled_modules VALUES ( NULL, c_project_id, 'delete_project'); + END LOOP; + + CLOSE curs_project_id; +END| +DELIMITER ; diff --git a/test/functional/delete_project_controller_test0000644 b/test/functional/delete_project_controller_test0000644 new file mode 100644 index 0000000..7bc2507 --- /dev/null +++ b/test/functional/delete_project_controller_test0000644 @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class DeleteProjectControllerTest < ActionController::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..bd1ed0c --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,5 @@ +# Load the normal Rails helper +require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') + +# Ensure that we are using the temporary fixture path +Engines::Testing.set_fixture_path