Project

General

Profile

Actions

Defect #20159

closed

Disallow users to delete a version referenced by a custom field

Added by Noya B over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Category:
Project settings
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Redmine disallows users to delete a version targeted on an issue. However, verification is not done if the version is referenced throw a custom field. It results on a crash trying to show an issue that "uses" the deleted target.

  • Bug seen in version 2.5.1.
  • Patch applied on:
    commit 0cac2b85b325e00c861b2c9a0e94407ed0bb077b
    Author: Toshi MARUYAMA <marutosijp2@yahoo.co.jp>
    Date:   Sun Jun 21 09:51:52 2015 +0000
    
        Merged r14360 from trunk to 2.6-stable (#20142)
    
        update Gemfile to require rbpdf ~>1.18.6.
    
        git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14362 e93f8b46-1217-0410-a6f0-8f06a7374b81
    
  • diff:
    diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
    index bc3852f..b8056ec 100644
    --- a/app/controllers/versions_controller.rb
    +++ b/app/controllers/versions_controller.rb
    @@ -146,7 +146,7 @@ class VersionsController < ApplicationController
       end
    
       def destroy
    -    if @version.fixed_issues.empty?
    +    if @version.fixed_issues.empty? and !@version.referenced_by_a_custom_field?
           @version.destroy
           respond_to do |format|
             format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
    diff --git a/app/models/version.rb b/app/models/version.rb
    index ed5b628..3df4caa 100644
    --- a/app/models/version.rb
    +++ b/app/models/version.rb
    @@ -168,6 +168,13 @@ class Version < ActiveRecord::Base
         @closed_issues_count
       end
    
    +  def referenced_by_a_custom_field?
    +    !CustomValue.where("custom_field_id IN (SELECT id
    +                                            FROM #{CustomField.table_name}
    +                                            WHERE field_format='version')
    +                        AND value = ?", id).empty?
    +  end
    +
       def wiki_page
         if project.wiki && !wiki_page_title.blank?
           @wiki_page ||= project.wiki.find_page(wiki_page_title)
    

Files

Actions #1

Updated by Jean-Philippe Lang over 9 years ago

  • Tracker changed from Patch to Defect
  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.1.0
  • Resolution set to Fixed

Fixed in r14376. The patch was refactored a bit and tests were added.
Thanks for pointing this out.

Actions

Also available in: Atom PDF