From ac56c0c99ccd14c7229145fc22d6e9eb13ee0af0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 25 Jun 2012 17:49:35 +0000 Subject: [PATCH] Ability to close projects (read-only) (#3640). A new permission (Close/reopen project) is available to give non-admin users the ability to close their projects. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9883 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/application_controller.rb | 2 +- app/controllers/projects_controller.rb | 16 ++++++- app/helpers/admin_helper.rb | 4 +- app/helpers/application_helper.rb | 8 ++-- app/models/principal.rb | 2 +- app/models/project.rb | 35 ++++++++++----- app/models/user.rb | 6 ++- app/views/admin/projects.html.erb | 6 +-- app/views/projects/index.html.erb | 8 ++++ app/views/projects/show.html.erb | 13 ++++++ config/locales/en.yml | 9 ++++ config/locales/fr.yml | 9 ++++ config/routes.rb | 2 + lib/redmine.rb | 34 +++++++------- lib/redmine/access_control.rb | 15 +++++++ lib/redmine/plugin.rb | 8 ++-- test/fixtures/roles.yml | 1 + test/functional/projects_controller_test.rb | 47 ++++++++++++++++++++ test/integration/routing/projects_test.rb | 8 ++++ test/unit/lib/redmine/access_control_test.rb | 10 +++++ test/unit/user_test.rb | 12 +++++ 21 files changed, 213 insertions(+), 42 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 17968bf79..645e8389b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -276,7 +276,7 @@ class ApplicationController < ActionController::Base # make sure that the user is a member of the project (or admin) if project is private # used as a before_filter for actions that do not require any particular permission on the project def check_project_privacy - if @project && @project.active? + if @project && !@project.archived? if @project.visible? true else diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c89167aa3..492e31795 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -48,7 +48,11 @@ class ProjectsController < ApplicationController def index respond_to do |format| format.html { - @projects = Project.visible.find(:all, :order => 'lft') + scope = Project + unless params[:closed] + scope = scope.active + end + @projects = scope.visible.order('lft').all } format.api { @offset, @limit = api_offset_and_limit @@ -224,6 +228,16 @@ class ProjectsController < ApplicationController redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) end + def close + @project.close + redirect_to project_path(@project) + end + + def reopen + @project.reopen + redirect_to project_path(@project) + end + # Delete @project def destroy @project_to_destroy = @project diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 01f394dd1..bacc7b8ea 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -20,6 +20,8 @@ module AdminHelper def project_status_options_for_select(selected) options_for_select([[l(:label_all), ''], - [l(:status_active), '1']], selected.to_s) + [l(:project_status_active), '1'], + [l(:project_status_closed), '5'], + [l(:project_status_archived), '9']], selected.to_s) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 794cc6f54..8c328326f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -145,11 +145,11 @@ module ApplicationHelper # link_to_project(project, {}, :class => "project") # => html options with default url (project overview) # def link_to_project(project, options={}, html_options = nil) - if project.active? + if project.archived? + h(project) + else url = {:controller => 'projects', :action => 'show', :id => project}.merge(options) link_to(h(project), url, html_options) - else - h(project) end end @@ -237,7 +237,7 @@ module ApplicationHelper # Renders the project quick-jump box def render_project_jump_box return unless User.current.logged? - projects = User.current.memberships.collect(&:project).compact.uniq + projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq if projects.any? s = '