Project

General

Profile

Feature #5358 » 5358-first.working.version.diff

Daniel Neis Araujo, 2011-02-18 00:38

View differences:

app/controllers/issue_categories_controller.rb
verify :method => :post, :only => :destroy
helper :projects
def new
@category = @project.issue_categories.build(params[:category])
if request.post?
app/helpers/projects_helper.rb
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}")
end
def format_category_sharing(sharing)
sharing = 'none' unless IssueCategory::SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}")
end
end
app/models/issue.rb
unless new_project.shared_versions.include?(issue.fixed_version)
issue.fixed_version = nil
end
# Keep the category if it's still valid in the new_project
unless new_project.shared_categories.include?(issue.category)
issue.category = nil
end
issue.project = new_project
if issue.parent && issue.parent.project_id != issue.project_id
issue.parent_issue_id = nil
......
errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version)
end
end
if category
if !assignable_categories.include?(category)
errors.add :category_id, :inclusion
end
end
# Checks that the issue can not be added/moved to a disabled tracker
if project && (tracker_id_changed? || project_id_changed?)
......
def assignable_versions
@assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort
end
# Categories that the issue can be assigned to
def assignable_categories
@assignable_categories ||= (project.shared_categories + [IssueCategory.find_by_id(category_id_was)]).compact.uniq.sort
end
# Returns true if this issue is blocked by another issue that is still open
def blocked?
......
# Update issues assigned to the version
update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
end
# Unassigns issues from +category+ if it's no longer shared with issue's project
def self.update_categories_from_sharing_change(category)
# Update issues assigned to the category
update_categories(["#{Issue.table_name}.category_id = ?", category.id])
end
# Unassigns issues from versions that are no longer shared
# after +project+ was moved
......
end
end
end
# Update issues so their categories are not pointing to a
# fixed_version that is not shared with the issue's project
def self.update_categories(conditions=nil)
# Only need to update issues with a fixed_version from
# a different project and that is not systemwide shared
Issue.all(:conditions => merge_conditions("#{Issue.table_name}.category_id IS NOT NULL" +
" AND #{Issue.table_name}.project_id <> #{IssueCategory.table_name}.project_id" +
" AND #{IssueCategory.table_name}.sharing <> 'system'",
conditions),
:include => [:project, :category]
).each do |issue|
next if issue.project.nil? || issue.category.nil?
unless issue.project.shared_categories.include?(issue.category)
issue.init_journal(User.current)
issue.category = nil
issue.save
end
end
end
# Callback on attachment deletion
def attachment_removed(obj)
app/models/issue_category.rb
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueCategory < ActiveRecord::Base
after_update :update_issues_from_sharing_change
belongs_to :project
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
SHARINGS = %w(none descendants hierarchy tree system)
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
validates_length_of :name, :maximum => 30
validates_inclusion_of :sharing, :in => SHARINGS
alias :destroy_without_reassign :destroy
......
end
def to_s; name end
# Returns the sharings that +user+ can set the category to
def allowed_sharings(user = User.current)
SHARINGS.select do |s|
if sharing == s
true
else
case s
when 'system'
# Only admin users can set a systemwide sharing
user.admin?
when 'hierarchy', 'tree'
# Only users allowed to manage versions of the root project can
# set sharing to hierarchy or tree
project.nil? || user.allowed_to?(:manage_versions, project.root)
else
true
end
end
end
end
# Update the issue's fixed versions. Used if a version's sharing changes.
def update_issues_from_sharing_change
if sharing_changed?
if SHARINGS.index(sharing_was).nil? ||
SHARINGS.index(sharing).nil? ||
SHARINGS.index(sharing_was) > SHARINGS.index(sharing)
Issue.update_categories_from_sharing_change self
end
end
end
end
app/models/project.rb
"))")
end
# Returns a scope of the Versions used by the project
def shared_categories
@shared_categories ||=
IssueCategory.find(:all, :include => :project,
:conditions => "#{Project.table_name}.id = #{id}" +
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
" #{IssueCategory.table_name}.sharing = 'system'" +
" OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{IssueCategory.table_name}.sharing = 'tree')" +
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{IssueCategory.table_name}.sharing IN ('hierarchy', 'descendants'))" +
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{IssueCategory.table_name}.sharing = 'hierarchy')" +
"))")
end
# Returns a hash of project users grouped by role
def users_by_role
members.find(:all, :include => [:user, :roles]).inject({}) do |h, m|
app/views/issue_categories/_form.rhtml
<div class="box">
<p><%= f.text_field :name, :size => 30, :required => true %></p>
<p><%= f.select :assigned_to_id, @project.users.sort.collect{|u| [u.name, u.id]}, :include_blank => true %></p>
<p><%= f.select :sharing, @category.allowed_sharings.collect{|c| [format_category_sharing(c), c]} %></p>
</div>
app/views/issues/_attributes.rhtml
<p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %></p>
<p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
<% unless @project.issue_categories.empty? %>
<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
<% unless @issue.assignable_categories.empty? %>
<p><%= f.select :category_id, (@issue.assignable_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
l(:label_issue_category_new),
'category[name]',
db/migrate/20110216000000_add_issue_category_sharing.rb
class AddIssueCategorySharing < ActiveRecord::Migration
def self.up
add_column :issue_categories, :sharing, :string, :default => 'none', :null => false
add_index :issue_categories, :sharing
end
def self.down
remove_column :issue_categories, :sharing
end
end
(2-2/10)