Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Migrate context menus controller tests #460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,36 @@
# See doc/COPYRIGHT.rdoc for more details.
#++

class Issues::ContextMenusController < ApplicationController
class WorkPackages::ContextMenusController < ApplicationController

def issues
@issues = WorkPackage.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
def index
@work_packages = WorkPackage.visible.all(order: "#{WorkPackage.table_name}.id",
conditions: {id: params[:ids]},
include: :project)

if (@issues.size == 1)
@issue = @issues.first
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
if (@work_packages.size == 1)
@work_package = @work_packages.first
@allowed_statuses = @work_package.new_statuses_allowed_to(User.current)
else
@allowed_statuses = @issues.map do |i|
@allowed_statuses = @work_packages.map do |i|
i.new_statuses_allowed_to(User.current)
end.inject do |memo,s|
memo & s
end
end
@projects = @issues.collect(&:project).compact.uniq
@projects = @work_packages.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1

@can = {:edit => User.current.allowed_to?(:edit_work_packages, @projects),
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
:update => (User.current.allowed_to?(:edit_work_packages, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
:move => (@project && User.current.allowed_to?(:move_work_packages, @project)),
:copy => (@issue && @project.types.include?(@issue.type) && User.current.allowed_to?(:add_work_packages, @project)),
:copy => (@work_package && @project.types.include?(@work_package.type) && User.current.allowed_to?(:add_work_packages, @project)),
:delete => User.current.allowed_to?(:delete_work_packages, @projects)
}
if @project
@assignables = @project.assignable_users
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
@assignables << @work_package.assigned_to if @work_package && @work_package.assigned_to && !@assignables.include?(@work_package.assigned_to)
@types = @project.types
else
#when multiple projects, we only keep the intersection of each set
Expand Down
2 changes: 1 addition & 1 deletion app/views/versions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ See doc/COPYRIGHT.rdoc for more details.

<% html_title(l(:label_roadmap)) %>

<%= context_menu issues_context_menu_path %>
<%= context_menu work_packages_context_menu_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ See doc/COPYRIGHT.rdoc for more details.
++#%>

<ul class="menu">
<%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
<%= call_hook(:view_issues_context_menu_start, {:issues => @work_packages, :can => @can, :back => @back }) %>

<% if !@issue.nil? -%>
<% if !@work_package.nil? -%>
<li class="edit">
<%= context_menu_link l(:button_edit), edit_work_package_path(@issue),
<%= context_menu_link l(:button_edit), edit_work_package_path(@work_package),
:class => 'icon-edit',
:disabled => !@can[:edit] %>
</li>
<% else %>
<li class="edit">
<%= context_menu_link l(:button_edit), bulk_edit_issues_path(:ids => @issues.collect(&:id)),
<%= context_menu_link l(:button_edit), bulk_edit_issues_path(:ids => @work_packages.collect(&:id)),
:class => 'icon-edit',
:disabled => !@can[:edit] %>
</li>
<% end %>

<% updated_issues = @issues.collect(&:id) %>
<% updated_issues = @work_packages.collect(&:id) %>
<% default_params = { :back_url => @back,
:updated_object_ids => updated_issues } %>

<% if @allowed_statuses.present? %>
<% params = default_params.merge(:collection => @statuses,
:attribute => 'status',
:title => WorkPackage.human_attribute_name(:status),
:selected => lambda { |status| (@issue && status == @issue.status) },
:selected => lambda { |status| (@work_package && status == @work_package.status) },
:disabled => lambda { |status| !(@can[:update] && @allowed_statuses.include?(status)) }) %>
<%= context_menu_entry(params) %>
<% end %>
Expand All @@ -61,24 +61,24 @@ See doc/COPYRIGHT.rdoc for more details.
<% params = default_params.merge(:collection => @types,
:attribute => 'type',
:title => WorkPackage.human_attribute_name(:type),
:selected => lambda { |type| (@issue && type == @issue.type) },
:selected => lambda { |type| (@work_package && type == @work_package.type) },
:disabled => lambda { |type| !@can[:edit] }) %>
<%= context_menu_entry(params) %>
<% end %>

<% params = default_params.merge(:collection => @priorities,
:attribute => 'priority',
:title => WorkPackage.human_attribute_name(:priority),
:selected => lambda { |priority| (@issue && priority == @issue.priority) },
:disabled => lambda { |priority| !@can[:edit] || @issues.detect { |i| !i.leaf? } }) %>
:selected => lambda { |priority| (@work_package && priority == @work_package.priority) },
:disabled => lambda { |priority| !@can[:edit] || @work_packages.detect { |i| !i.leaf? } }) %>
<%= context_menu_entry(params) %>

<% #TODO: allow editing versions when multiple projects %>
<% unless @project.nil? || (versions = @project.shared_versions.open.sort).empty? -%>
<% versions = versions.map{ |v| [v, format_version_name(v)] } << [nil, l(:label_none)]%>
<% params = default_params.merge(:collection => versions,
:attribute => 'fixed_version',
:selected => lambda { |version| (@issue && version == @issue.fixed_version) },
:selected => lambda { |version| (@work_package && version == @work_package.fixed_version) },
:disabled => lambda { |version| !@can[:update] }) %>
<%= context_menu_entry(params) %>
<% end %>
Expand All @@ -88,7 +88,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% params = default_params.merge(:collection => assignables,
:attribute => 'assigned_to',
:title => WorkPackage.human_attribute_name(:assigned_to),
:selected => lambda { |user| @issue && user == @issue.assigned_to },
:selected => lambda { |user| @work_package && user == @work_package.assigned_to },
:disabled => lambda { |user| !@can[:update] }) %>
<%= context_menu_entry(params) %>
<% end %>
Expand All @@ -98,7 +98,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% params = default_params.merge(:collection => categories,
:attribute => 'category',
:title => WorkPackage.human_attribute_name(:category),
:selected => lambda { |category| @issue && category == @issue.category },
:selected => lambda { |category| @work_package && category == @work_package.category },
:disabled => lambda { |category| !@can[:update] }) %>
<%= context_menu_entry(params) %>
<% end -%>
Expand All @@ -108,55 +108,55 @@ See doc/COPYRIGHT.rdoc for more details.
:attribute => 'done_ratio',
:title => WorkPackage.human_attribute_name(:done_ratio),
:db_attribute => 'done_ratio',
:selected => lambda { |ratio| @issue && ratio == @issue.done_ratio },
:disabled => lambda { |ratio| !@can[:edit] || @issues.detect { |i| !i.leaf? } }) %>
:selected => lambda { |ratio| @work_package && ratio == @work_package.done_ratio },
:disabled => lambda { |ratio| !@can[:edit] || @work_packages.detect { |i| !i.leaf? } }) %>
<%= context_menu_entry(params) %>
<% end -%>

<% if !@issue.nil? %>
<% if !@work_package.nil? %>
<% if @can[:log_time] -%>
<li class="log_time">
<%= context_menu_link l(:button_log_time),
new_work_package_time_entry_path(@issue),
new_work_package_time_entry_path(@work_package),
:class => 'context_item' %>
</li>
<% end %>

<% if User.current.logged? %>
<li class="watch">
<%= watcher_link(@issue, User.current) %>
<%= watcher_link(@work_package, User.current) %>
</li>
<% end %>
<% end %>

<% if @issue.present? %>
<% if @work_package.present? %>
<li>
<%= context_menu_link l(:button_duplicate), new_project_work_package_path({ :project_id => @project,
:copy_from => @issue }),
:copy_from => @work_package }),
:class => 'icon-duplicate',
:disabled => !@can[:copy] %>
</li>
<% end %>

<li class="move">
<%= context_menu_link l(:button_move), new_move_work_packages_path(:ids => @issues.collect(&:id)),
<%= context_menu_link l(:button_move), new_move_work_packages_path(:ids => @work_packages.collect(&:id)),
:class => 'context_item',
:disabled => !@can[:move] %>
</li>

<li class="copy">
<%= context_menu_link l(:button_copy), new_move_work_packages_path(:ids => @issues.collect(&:id),
<%= context_menu_link l(:button_copy), new_move_work_packages_path(:ids => @work_packages.collect(&:id),
:copy_options => { :copy => 't' }),
:class => 'context_item' %>
</li>

<li class="delete">
<%= context_menu_link l(:button_delete), work_packages_path(:ids => @issues.collect(&:id)),
<%= context_menu_link l(:button_delete), work_packages_path(:ids => @work_packages.collect(&:id)),
:method => :delete,
:confirm => l(:text_work_packages_destroy_confirmation),
:class => 'context_item',
:disabled => !@can[:delete] %>
</li>

<%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
<%= call_hook(:view_issues_context_menu_end, {:issues => @work_packages, :can => @can, :back => @back }) %>
</ul>
2 changes: 1 addition & 1 deletion app/views/work_packages/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ See doc/COPYRIGHT.rdoc for more details.
<%= auto_discovery_link_tag(:atom, {:controller => '/journals', :action => 'index', :query_id => query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_changes_details)) %>
<% end %>

<%= context_menu issues_context_menu_path %>
<%= context_menu work_packages_context_menu_path %>
2 changes: 1 addition & 1 deletion app/views/work_packages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= stylesheet_link_tag 'context_menu_rtl' if l(:direction) == 'rtl' %>
<% end %>
<div id="context-menu" style="display: none;"></div>
<%= javascript_tag "new ContextMenu('#{issues_context_menu_path}')" %>
<%= javascript_tag "new ContextMenu('#{work_packages_context_menu_path}')" %>

<% #include calendar js files in case they are needed for edit
include_calendar_headers_tags -%>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@

namespace :work_packages do
match 'auto_complete' => 'auto_completes#index', :via => [:get, :post], :format => false
match 'context_menu' => 'context_menus#index', :via => [:get, :post], :format => false
resources :calendar, :controller => 'calendars', :only => [:index]
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/versions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

it { response.should be_success }
it { response.should render_template("index") }
it { assert_select "script", :text => Regexp.new(Regexp.escape("new ContextMenu('/issues/context_menu')")) }
it { assert_select "script", :text => Regexp.new(Regexp.escape("new ContextMenu('/work_packages/context_menu')")) }

subject { assigns(:versions) }
it "shows Version with no date set" do
Expand Down
Loading