Project

General

Profile

Feature #465 » 465-shared-versions-work-in-progress.patch

Shared versions patch, check Github for the latest - Eric Davis, 2009-09-03 23:46

View differences:

app/controllers/issues_controller.rb
priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.inherited_versions.find {|v| v.id.to_s == params[:fixed_version_id] }
custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
unsaved_issue_ids = []
app/controllers/projects_controller.rb
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
@containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
# Need get the ids separately in order to add the finder options
version_ids = @project.inherited_versions_visible_to_user.collect(&:id)
@containers += Version.find_all_by_id(version_ids, :include => :attachments, :order => sort_clause).sort.reverse
render :layout => !request.xhr?
end
......
def changelog
@trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
retrieve_selected_tracker_ids(@trackers)
@versions = @project.versions.sort
if params[:inherited_versions]
@versions = @project.inherited_versions_visible_to_user.sort
else
@versions = @project.versions.sort
end
end
def roadmap
@trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
retrieve_selected_tracker_ids(@trackers)
@versions = @project.versions.sort
if params[:inherited_versions]
@versions = @project.inherited_versions_visible_to_user.sort
else
@versions = @project.versions.sort
end
@versions = @versions.select {|v| !v.completed? } unless params[:completed]
end
app/helpers/application_helper.rb
h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
end
def format_version_name(version)
if User.current.allowed_to?(:view_issues, version.project)
"#{h(version.project.name)} - #{h(version.name)}"
else
"#{l(:text_not_authorized)}"
end
end
# Given an Array of emails (+recipients+), do they all have
# +permission+ on +project+ ?
def recipients_all_allowed_to?(recipients, permission, project)
recipients.uniq.all? do |recipient|
user = User.find_by_mail(recipient)
user && user.allowed_to?(permission, project)
end
end
# Given an Array of +versions+, are all the email addresses
# (+recipients+) allowed to view all of the versions?
def recipients_all_allowed_to_see_versions?(recipients, versions)
versions.uniq.all? do |version|
if version.nil?
true
else
recipients_all_allowed_to?(recipients, :view_issues, version.project)
end
end
end
def due_date_distance_in_words(date)
if date
l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
app/helpers/issues_helper.rb
@sidebar_queries
end
def inherited_version_options(project)
project.inherited_versions.sort.collect {|v| [format_version_name(v), v.id] }
end
def show_detail(detail, no_html=false)
case detail.property
when 'attr'
......
c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
when 'fixed_version_id'
v = Version.find_by_id(detail.value) and value = v.name if detail.value
v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
v = Version.find_by_id(detail.value) and value = format_version_name(v) if detail.value
v = Version.find_by_id(detail.old_value) and old_value = format_version_name(v) if detail.old_value
when 'estimated_hours'
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
app/helpers/mailer_helper.rb
# redMine - project management software
# Copyright (C) 2006-2009 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module MailerHelper
def unauthorized_version?(journal_detail, recipients)
return false unless journal_detail.prop_key == "fixed_version_id"
!recipients_all_allowed_to_see_versions?(recipients,
Version.find_all_by_id([journal_detail.value, journal_detail.old_value]))
end
end
app/helpers/projects_helper.rb
module ProjectsHelper
def link_to_version(version, options = {})
return '' unless version && version.is_a?(Version)
link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options
if User.current.allowed_to?(:view_issues, version.project)
link_to format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
else
format_version_name(version)
end
end
def project_settings_tabs
app/models/mailer.rb
helper :application
helper :issues
helper :custom_fields
helper :mailer
include ActionController::UrlWriter
include Redmine::I18n
app/models/project.rb
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
:order => "#{Tracker.table_name}.position")
end
# Returns an array of the Versions used by the project, its active
# sub projects, and its active parent projects
def inherited_versions
@inherited_versions ||= self.root.self_and_descendants.
delete_if {|p| !p.active? }.
collect(&:versions).
flatten.
sort
yield @inherited_versions if block_given?
@inherited_versions
end
# Returns the inherited_versions that are visible to +user+
def inherited_versions_visible_to_user(user=User.current)
return inherited_versions do |versions|
versions.delete_if {|v| !user.allowed_to?(:view_issues, v.project) }
end
end
# Returns a hash of project users grouped by role
def users_by_role
app/models/query.rb
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
end
unless @project.versions.empty?
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.inherited_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
end
unless @project.descendants.active.empty?
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.descendants.visible.collect{|s| [s.name, s.id.to_s] } }
app/views/issues/_form.rhtml
:class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p>
<% end %>
<%= content_tag('p', f.select(:fixed_version_id,
(@project.versions.sort.collect {|v| [v.name, v.id]}),
{ :include_blank => true })) unless @project.versions.empty? %>
(inherited_version_options(@project)),
{ :include_blank => true })) unless @project.inherited_versions.empty? %>
</div>
<div class="splitcontentright">
app/views/issues/bulk_edit.rhtml
<label><%= l(:field_fixed_version) %>:
<%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') +
content_tag('option', l(:label_none), :value => 'none') +
options_from_collection_for_select(@project.versions.sort, :id, :name)) %></label>
options_for_select(inherited_version_options(@project))) %></label>
</p>
<p>
app/views/issues/context_menu.rhtml
<% end -%>
</ul>
</li>
<% unless @project.nil? || @project.versions.empty? -%>
<% unless @project.nil? || @project.inherited_versions.empty? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
<ul>
<% @project.versions.sort.each do |v| -%>
<li><%= context_menu_link v.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => v, :back_to => @back}, :method => :post,
<% @project.inherited_versions.sort.each do |v| -%>
<li><%= context_menu_link format_version_name(v), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => v, :back_to => @back}, :method => :post,
:selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
<% end -%>
<li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => 'none', :back_to => @back}, :method => :post,
app/views/mailer/issue_edit.text.html.rhtml
<ul>
<% for detail in @journal.details %>
<% if unauthorized_version?(detail, @recipients + @cc) %>
<li><%= l(:field_fixed_version) %> <%= l(:text_journal_set_to, l(:text_not_authorized)) %></li>
<% else %>
<li><%= show_detail(detail, true) %></li>
<% end %>
<% end %>
</ul>
app/views/mailer/issue_edit.text.plain.rhtml
<%= l(:text_issue_updated, :id => "##{@issue.id}", :author => @journal.user) %>
<% for detail in @journal.details -%>
<% if unauthorized_version?(detail, @recipients + @cc) %>
<%= l(:field_fixed_version) %> <%= l(:text_journal_set_to, l(:text_not_authorized)) %>
<% else %>
<%= show_detail(detail, true) %>
<% end %>
<% end -%>
<%= @journal.notes if @journal.notes? %>
app/views/projects/changelog.rhtml
<label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
<%= tracker.name %></label><br />
<% end %>
<br />
<label for="inherited_versions"><%= check_box_tag "inherited_versions", 1, params[:inherited_versions] %> <%= l(:label_show_inherited_versions) %></label>
<p><%= submit_tag l(:button_apply), :class => 'button-small' %></p>
<% end %>
app/views/projects/list_files.rhtml
<% if container.is_a?(Version) -%>
<tr>
<th colspan="6" align="left">
<%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %>
<%= link_to(h(container.project.name) + ' - ' + h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %>
</th>
</tr>
<% end -%>
app/views/projects/roadmap.rhtml
<div id="roadmap">
<% @versions.each do |version| %>
<%= tag 'a', :name => version.name %>
<h3 class="icon22 icon22-package"><%= link_to h(version.name), :controller => 'versions', :action => 'show', :id => version %></h3>
<h3 class="icon22 icon22-package"><%= link_to h(version.project.name) + " - " + h(version.name), :controller => 'versions', :action => 'show', :id => version %></h3>
<%= render :partial => 'versions/overview', :locals => {:version => version} %>
<%= render(:partial => "wiki/content", :locals => {:content => version.wiki_page.content}) if version.wiki_page %>
......
<% end %>
<br />
<label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label>
<br />
<label for="inherited_versions"><%= check_box_tag "inherited_versions", 1, params[:inherited_versions] %> <%= l(:label_show_inherited_versions) %></label>
<p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p>
<% end %>
config/locales/en.yml
label_stay_logged_in: Stay logged in
label_disabled: disabled
label_show_completed_versions: Show completed versions
label_show_inherited_versions: Show inherited versions
label_me: me
label_board: Forum
label_board_new: New forum
......
text_wiki_page_nullify_children: "Keep child pages as root pages"
text_wiki_page_destroy_children: "Delete child pages and all their descendants"
text_wiki_page_reassign_children: "Reassign child pages to this parent page"
text_not_authorized: You are not authorized to view this.
default_role_manager: Manager
default_role_developper: Developer
test/fixtures/attachments.yml
filename: picture.jpg
author_id: 2
content_type: image/jpeg
attachments_011:
created_on: 2006-07-19 21:07:27 +02:00
container_type: Version
container_id: 1
downloads: 0
disk_filename: 060719210727_version_file.zip
digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
id: 11
filesize: 452
filename: version_file.zip
author_id: 2
content_type: application/octet-stream
test/fixtures/journal_details.yml
value: "30"
prop_key: done_ratio
journal_id: 1
journal_details_003:
old_value: nil
property: attr
id: 3
value: "6"
prop_key: fixed_version_id
journal_id: 4
test/fixtures/journals.yml
journalized_type: Issue
user_id: 2
journalized_id: 2
journals_004:
created_on: <%= 1.days.ago.to_date.to_s(:db) %>
notes: "A comment with a private version."
id: 4
journalized_type: Issue
user_id: 1
journalized_id: 6
test/fixtures/members.yml
project_id: 5
user_id: 2
mail_notification: true
members_006:
created_on: 2006-07-19 19:35:33 +02:00
project_id: 5
id: 6
user_id: 1
mail_notification: true
test/fixtures/versions.yml
id: 3
description: Future version
effective_date:
versions_004:
created_on: 2006-07-19 21:00:33 +02:00
name: "2.0"
project_id: 3
updated_on: 2006-07-19 21:00:33 +02:00
id: 4
description: Future version on subproject
effective_date:
versions_005:
created_on: 2006-07-19 21:00:07 +02:00
name: "Alpha"
project_id: 2
updated_on: 2006-07-19 21:00:07 +02:00
id: 5
description: Private Alpha
effective_date: 2006-07-01
versions_006:
created_on: 2006-07-19 21:00:07 +02:00
name: "Private Version of public subproject"
project_id: 5
updated_on: 2006-07-19 21:00:07 +02:00
id: 6
description: "Should be done any day now..."
effective_date:
test/functional/issues_controller_test.rb
assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
end
def test_post_edit_should_allow_fixed_version_to_be_set_to_a_subproject
issue = Issue.find(2)
@request.session[:user_id] = 2
post :edit,
:id => issue.id,
:issue => {
:fixed_version_id => 4
}
assert_response :redirect
issue.reload
assert_equal 4, issue.fixed_version_id
assert_not_equal issue.project_id, issue.fixed_version.project_id
end
def test_get_bulk_edit
@request.session[:user_id] = 2
get :bulk_edit, :ids => [1, 2]
......
assert_nil Issue.find(2).assigned_to
end
def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject
@request.session[:user_id] = 2
post :bulk_edit,
:ids => [1,2],
:fixed_version_id => 4
assert_response :redirect
issues = Issue.find([1,2])
issues.each do |issue|
assert_equal 4, issue.fixed_version_id
assert_not_equal issue.project_id, issue.fixed_version.project_id
end
end
def test_move_routing
assert_routing(
{:method => :get, :path => '/issues/1/move'},
......
assert_tag :tag => 'a', :content => 'Immediate',
:attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
:class => '' }
# Versions
assert_tag :tag => 'a', :content => 'eCookbook - 0.1',
:attributes => { :href => '/issues/bulk_edit?fixed_version_id=1&amp;ids%5B%5D=1',
:class => '' }
assert_tag :tag => 'a', :content => 'eCookbook - 1.0',
:attributes => { :href => '/issues/bulk_edit?fixed_version_id=2&amp;ids%5B%5D=1',
:class => '' }
assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
:attributes => { :href => '/issues/bulk_edit?fixed_version_id=4&amp;ids%5B%5D=1',
:class => '' }
assert_tag :tag => 'a', :content => 'Dave Lopper',
:attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
:class => '' }
test/functional/projects_controller_test.rb
:attributes => { :href => '/attachments/download/9/version_file.zip' }
end
def test_list_files_with_inherited_versions
get :list_files, :id => 1
assert_response :success
assert_not_nil assigns(:containers)
# file attached to a subproject's version
assert_tag :a, :content => 'version_file.zip',
:attributes => { :href => '/attachments/download/11/version_file.zip' }
end
def test_list_files_routing
assert_routing(
{:method => :get, :path => '/projects/33/files'},
......
assert_not_nil assigns(:versions)
end
def test_changelog_showing_inherited_versions
get :changelog, :id => 1, :inherited_versions => 1
assert_response :success
assert_template 'changelog'
assert_not_nil assigns(:versions)
# Version on subproject appears
assert assigns(:versions).include?(Version.find(4))
end
def test_roadmap_routing
assert_routing(
{:method => :get, :path => 'projects/33/roadmap'},
......
# Completed version appears
assert assigns(:versions).include?(Version.find(1))
end
def test_roadmap_showing_inherited_versions
get :roadmap, :id => 1, :inherited_versions => 1
assert_response :success
assert_template 'roadmap'
assert_not_nil assigns(:versions)
# Version on subproject appears
assert assigns(:versions).include?(Version.find(4))
end
def test_project_activity_routing
assert_routing(
test/unit/helpers/application_helper_test.rb
def setup
super
end
def test_format_version_name_is_authorized
User.current = User.find(1)
assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
end
def test_format_version_name_is_unauthorized
User.current = User.find(3)
assert_equal "You are not authorized to view this.", format_version_name(Version.find(5))
end
def test_auto_links
to_test = {
test/unit/helpers/projects_helper_test.rb
# Redmine - project management software
# Copyright (C) 2006-2009 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../../test_helper'
class ProjectsHelperTest < HelperTestCase
include ApplicationHelper
include ProjectsHelper
fixtures :all
def setup
super
set_language_if_valid('en')
end
def test_link_to_version
User.current = User.find(1)
assert_equal '<a href="/versions/show/1">eCookbook - 0.1</a>', link_to_version(Version.find(1))
end
def test_link_to_version_invalid_version
assert_equal '', link_to_version(Object)
end
def test_link_to_version_unauthorized
User.current = User.find(3)
assert_equal "You are not authorized to view this.", link_to_version(Version.find(5))
end
end
test/unit/mailer_test.rb
assert mail.bcc.include?('dlopper@somenet.foo')
assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
end
def test_issue_edit_should_not_show_private_version_changes_if_any_recipients_are_unauthorized
Setting.default_language = 'en'
# Move issue to a public project but with a Journal showing a
# Private Version
issue = Issue.find(6)
issue.update_attribute(:project_id, 1)
# User is allowed to see the Private Version
User.current = User.find(1)
# but another Member of Project #1 is not (dlopper@somenet.foo)
journal = Journal.find(4)
Mailer.deliver_issue_edit(journal)
mail = ActionMailer::Base.deliveries.last
assert !mail.body.include?('Private Version of public subproject'), "Private version exposed to unauthorized user"
assert mail.body.include?('You are not authorized to view this.'), "Unauthorized message not displayed"
end
end
test/unit/project_test.rb
fixtures :projects, :enabled_modules,
:issues, :issue_statuses, :journals, :journal_details,
:users, :members, :member_roles, :roles, :projects_trackers, :trackers, :boards,
:queries
:queries, :versions
def setup
@ecookbook = Project.find(1)
......
assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
end
def test_inherited_versions
parent = Project.find(1)
child = parent.children.find(3)
assert [1,2,3], parent.version_ids
assert [4], child.version_ids
assert_equal 5, parent.inherited_versions.size
parent.inherited_versions.each do |version|
assert_kind_of Version, version
end
assert_equal [1,2,3,4,6], parent.inherited_versions.collect(&:id)
end
def test_inherited_versions_should_ignore_archived_subprojects
parent = Project.find(1)
child = parent.children.find(3)
child.archive
parent.reload
assert [1,2,3], parent.version_ids
assert [4], child.version_ids
assert !parent.inherited_versions.collect(&:id).include?(4)
end
def test_inherited_versions_visible_to_user
user = User.find(3)
parent = Project.find(1)
child = parent.children.find(5)
assert [1,2,3], parent.version_ids
assert [6], child.version_ids
versions = parent.inherited_versions_visible_to_user(user)
assert_equal 4, versions.size
versions.each do |version|
assert_kind_of Version, version
end
assert !versions.collect(&:id).include?(6)
end
def test_next_identifier
ProjectCustomField.delete_all
Project.create!(:name => 'last', :identifier => 'p2008040')
test/unit/query_test.rb
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
:conditions => query.statement
end
def test_query_should_allow_inherited_versions_for_a_project_query
subproject_version = Version.find(4)
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('fixed_version_id', '=', [subproject_version.id.to_s])
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IN ('4')")
end
def test_query_with_multiple_custom_fields
query = Query.find(1)
(3-3/4)