Project

General

Profile

Maintenance #1959

Updated by liaham about 1 year ago

Affected plugins: 

 + project:redmine-project-types-relations 
 + project:redmine-project-types 
 + project:redmine-table-calculation 
 + project:redmine-issue-sync 
 + project:redmine-periodic-task project:redmine-periodic-tasks 


 ```diff 
 diff --git a/app/models/project.rb b/app/models/project.rb 
 index 3799e7ef2..11f4a953d 100644 
 --- a/app/models/project.rb 
 +++ b/app/models/project.rb 
 @@ -25,6 +25,7 @@ class Project < ActiveRecord::Base 
    STATUS_ACTIVE       = 1 
    STATUS_CLOSED       = 5 
    STATUS_ARCHIVED     = 9 
 +    STATUS_SCHEDULED_FOR_DELETION = 10 
 
    # Maximum length for project identifiers 
    IDENTIFIER_MAX_LENGTH = 100 
 @@ -182,7 +183,7 @@ class Project < ActiveRecord::Base 
      perm = Redmine::AccessControl.permission(permission) 
      base_statement = 
        if perm && perm.read? 
 -          "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}" 
 +          "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED} AND #{Project.table_name}.status <> #{Project::STATUS_SCHEDULED_FOR_DELETION}" 
        else 
          "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" 
        end 
 @@ -328,15 +329,17 @@ class Project < ActiveRecord::Base 
    # Returns a :conditions SQL string that can be used to find the issues associated with this project. 
    # 
    # Examples: 
 -    #     project.project_condition(true)    => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))" 
 +    #     project.project_condition(true)    => "(projects.lft >= 1 AND projects.rgt <= 10)" 
    #     project.project_condition(false) => "projects.id = 1" 
    def project_condition(with_subprojects) 
 -      cond = "#{Project.table_name}.id = #{id}" 
      if with_subprojects 
 -        cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND " \ 
 -                 "#{Project.table_name}.rgt < #{rgt}))" 
 +        "(" \ 
 +          "#{Project.table_name}.lft >= #{lft} AND " \ 
 +          "#{Project.table_name}.rgt <= #{rgt}" \ 
 +        ")" 
 +      else 
 +        "#{Project.table_name}.id = #{id}" 
      end 
 -      cond 
    end 
 
    def self.find(*args) 
 @@ -399,6 +402,10 @@ class Project < ActiveRecord::Base 
      self.status == STATUS_ARCHIVED 
    end 
 
 +    def scheduled_for_deletion? 
 +      self.status == STATUS_SCHEDULED_FOR_DELETION 
 +    end 
 + 
    # Archives the project and its descendants 
    def archive 
      # Check that there is no issue of a non descendant project that is assigned 
 @@ -664,6 +671,8 @@ class Project < ActiveRecord::Base 
    end 
 
    def <=>(project) 
 +      return nil unless project.is_a?(Project) 
 + 
      name.casecmp(project.name) 
    end 
 
 @@ -818,7 +827,6 @@ class Project < ActiveRecord::Base 
      'name', 
      'description', 
      'homepage', 
 -      'is_public', 
      'identifier', 
      'custom_field_values', 
      'custom_fields', 
 @@ -829,6 +837,22 @@ class Project < ActiveRecord::Base 
      'default_issue_query_id', 
      'default_assigned_to_id') 
 
 +    safe_attributes( 
 +      'is_public', 
 +      :if => 
 +        lambda do |project, user| 
 +          if project.new_record? 
 +            if user.admin? 
 +              true 
 +            else 
 +              default_member_role&.has_permission?(:select_project_publicity) 
 +            end 
 +          else 
 +            user.allowed_to?(:select_project_publicity, project) 
 +          end 
 +        end 
 +    ) 
 + 
    safe_attributes( 
      'enabled_module_names', 
      :if => 
 @@ -906,7 +930,7 @@ class Project < ActiveRecord::Base 
    #     project.copy(1, :only => 'members')                  # => copies members only 
    #     project.copy(1, :only => ['members', 'versions'])    # => copies members and versions 
    def copy(project, options={}) 
 -      project = project.is_a?(Project) ? project : Project.find(project) 
 +      project = Project.find(project) unless project.is_a?(Project) 
 
      to_be_copied = %w(members wiki versions issue_categories issues queries boards documents) 
      to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? 
 @@ -934,7 +958,7 @@ class Project < ActiveRecord::Base 
 
    # Returns a new unsaved Project instance with attributes copied from +project+ 
    def self.copy_from(project) 
 -      project = project.is_a?(Project) ? project : Project.find(project) 
 +      project = Project.find(project) unless project.is_a?(Project) 
      # clear unique attributes 
      attributes = 
        project.attributes.dup.except('id', 'name', 'identifier', 
 ```

Back