Merge branch 'ticket/unstable/809-add-multiple-projects' into unstable
This commit is contained in:
commit
a3b1127ef8
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
class AutoCompletesController < ApplicationController
|
class AutoCompletesController < ApplicationController
|
||||||
before_filter :find_project, :only => :issues
|
before_filter :find_project, :only => :issues
|
||||||
|
before_filter :require_admin, :only => :projects
|
||||||
|
|
||||||
def issues
|
def issues
|
||||||
@issues = []
|
@issues = []
|
||||||
|
@ -59,6 +60,12 @@ class AutoCompletesController < ApplicationController
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def projects
|
||||||
|
@principal = Principal.find(params[:id])
|
||||||
|
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @principal.projects
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
|
|
@ -128,8 +128,17 @@ class GroupsController < ApplicationController
|
||||||
|
|
||||||
def edit_membership
|
def edit_membership
|
||||||
@group = Group.find(params[:id])
|
@group = Group.find(params[:id])
|
||||||
|
|
||||||
|
if params[:project_ids] # Multiple memberships, one per project
|
||||||
|
params[:project_ids].each do |project_id|
|
||||||
|
@membership = Member.edit_membership(params[:membership_id], params[:membership].merge(:project_id => project_id), @group)
|
||||||
|
@membership.save if request.post?
|
||||||
|
end
|
||||||
|
else # Single membership
|
||||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
||||||
@membership.save if request.post?
|
@membership.save if request.post?
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @membership.valid?
|
if @membership.valid?
|
||||||
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
||||||
|
|
|
@ -197,8 +197,16 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
def edit_membership
|
def edit_membership
|
||||||
|
if params[:project_ids] # Multiple memberships, one per project
|
||||||
|
params[:project_ids].each do |project_id|
|
||||||
|
@membership = Member.edit_membership(params[:membership_id], params[:membership].merge(:project_id => project_id), @user)
|
||||||
|
@membership.save if request.post?
|
||||||
|
end
|
||||||
|
else # Single membership
|
||||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
||||||
@membership.save if request.post?
|
@membership.save if request.post?
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @membership.valid?
|
if @membership.valid?
|
||||||
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
||||||
|
|
|
@ -290,6 +290,14 @@ module ApplicationHelper
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def projects_check_box_tags(name, projects)
|
||||||
|
s = ''
|
||||||
|
projects.each do |project|
|
||||||
|
s << "<label>#{ check_box_tag name, project.id, false } #{h project}</label>\n"
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
# Truncates and returns the string as a single line
|
# Truncates and returns the string as a single line
|
||||||
def truncate_single_line(string, *args)
|
def truncate_single_line(string, *args)
|
||||||
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
||||||
|
|
|
@ -82,6 +82,12 @@ class Project < ActiveRecord::Base
|
||||||
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
||||||
named_scope :all_public, { :conditions => { :is_public => true } }
|
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||||
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
||||||
|
named_scope :like, lambda {|q|
|
||||||
|
s = "%#{q.to_s.strip.downcase}%"
|
||||||
|
{
|
||||||
|
:conditions => ["LOWER(name) LIKE ?", s]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
ProjectDrop.new(self)
|
ProjectDrop.new(self)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<%= projects_check_box_tags 'project_ids[]', @projects %>
|
|
@ -41,17 +41,5 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<% if projects.any? %>
|
<%= render :partial => 'members/membership_assignment', :locals => {:principal => @group, :projects => projects - @group.projects, :roles => roles } %>
|
||||||
<fieldset><legend><%=l(:label_project_new)%></legend>
|
|
||||||
<% remote_form_for(:membership, :url => { :action => 'edit_membership', :id => @group }) do %>
|
|
||||||
<%= label_tag "membership_project_id", l(:description_choose_project), :class => "hidden-for-sighted" %>
|
|
||||||
<%= select_tag 'membership[project_id]', options_for_membership_project_select(@group, projects) %>
|
|
||||||
<p><%= l(:label_role_plural) %>:
|
|
||||||
<% roles.each do |role| %>
|
|
||||||
<label><%= check_box_tag 'membership[role_ids][]', role.id %> <%=h role %></label>
|
|
||||||
<% end %></p>
|
|
||||||
<p><%= submit_tag l(:button_add) %></p>
|
|
||||||
<% end %>
|
|
||||||
</fieldset>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<% if projects.any? %>
|
||||||
|
<fieldset><legend><%=l(:label_project_new)%></legend>
|
||||||
|
<% remote_form_for(:membership, :url => { :action => 'edit_membership', :id => principal }) do %>
|
||||||
|
<p><%= text_field_tag 'project_search', nil, :size => "40" %></p>
|
||||||
|
<%= observe_field(:project_search,
|
||||||
|
:frequency => 0.5,
|
||||||
|
:update => :projects,
|
||||||
|
:url => { :controller => 'auto_completes', :action => 'projects', :id => principal },
|
||||||
|
:with => 'q')
|
||||||
|
%>
|
||||||
|
|
||||||
|
<div id="projects">
|
||||||
|
<%= principals_check_box_tags 'project_ids[]', projects %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><%= l(:label_role_plural) %>:
|
||||||
|
<% roles.each do |role| %>
|
||||||
|
<label><%= check_box_tag 'membership[role_ids][]', role.id %> <%=h role %></label>
|
||||||
|
<% end %></p>
|
||||||
|
<p><%= submit_tag l(:button_add) %></p>
|
||||||
|
<% end %>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
|
@ -47,16 +47,5 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<% if projects.any? %>
|
<%= render :partial => 'members/membership_assignment', :locals => {:principal => @user, :projects => projects - @user.projects, :roles => roles } %>
|
||||||
<fieldset><legend><%=l(:label_project_new)%></legend>
|
|
||||||
<% remote_form_for(:membership, :url => { :action => 'edit_membership', :id => @user }) do %>
|
|
||||||
<%= select_tag 'membership[project_id]', options_for_membership_project_select(@user, projects) %>
|
|
||||||
<p><%= l(:label_role_plural) %>:
|
|
||||||
<% roles.each do |role| %>
|
|
||||||
<label><%= check_box_tag 'membership[role_ids][]', role.id %> <%=h role %></label>
|
|
||||||
<% end %></p>
|
|
||||||
<p><%= submit_tag l(:button_add) %></p>
|
|
||||||
<% end %>
|
|
||||||
</fieldset>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -515,7 +515,7 @@ div#tab-content-members .splitcontentright, div#tab-content-memberships .splitco
|
||||||
div#tab-content-members fieldset, div#tab-content-memberships fieldset, div#tab-content-users fieldset { padding:1em; margin-bottom: 1em; }
|
div#tab-content-members fieldset, div#tab-content-memberships fieldset, div#tab-content-users fieldset { padding:1em; margin-bottom: 1em; }
|
||||||
div#tab-content-members fieldset legend, div#tab-content-memberships fieldset legend, div#tab-content-users fieldset legend { font-weight: bold; }
|
div#tab-content-members fieldset legend, div#tab-content-memberships fieldset legend, div#tab-content-users fieldset legend { font-weight: bold; }
|
||||||
div#tab-content-members fieldset label, div#tab-content-memberships fieldset label, div#tab-content-users fieldset label { display: block; }
|
div#tab-content-members fieldset label, div#tab-content-memberships fieldset label, div#tab-content-users fieldset label { display: block; }
|
||||||
div#tab-content-members fieldset div, div#tab-content-users fieldset div { max-height: 400px; overflow:auto; }
|
div#tab-content-members fieldset div, div#tab-content-users fieldset div, div#tab-content-memberships fieldset div { max-height: 400px; overflow:auto; }
|
||||||
|
|
||||||
table.members td.group { padding-left: 20px; background: url(../images/group.png) no-repeat 0% 50%; }
|
table.members td.group { padding-left: 20px; background: url(../images/group.png) no-repeat 0% 50%; }
|
||||||
|
|
||||||
|
|
|
@ -142,4 +142,59 @@ class AutoCompletesControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "POST to #projects" do
|
||||||
|
setup do
|
||||||
|
# Clear out some fixtures
|
||||||
|
Project.delete_all
|
||||||
|
ProjectCustomField.delete_all
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'require admin' do
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :projects, {}
|
||||||
|
|
||||||
|
assert_response 403
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a valid search' do
|
||||||
|
setup do
|
||||||
|
@user = User.generate_with_protected!
|
||||||
|
@projects = [
|
||||||
|
Project.generate!(:name => "Test"),
|
||||||
|
Project.generate!(:name => "This is a Test")
|
||||||
|
]
|
||||||
|
Project.generate!(:name => "No match")
|
||||||
|
|
||||||
|
@request.session[:user_id] = 1
|
||||||
|
post :projects, {
|
||||||
|
:id => @user.id,
|
||||||
|
:q => 'TeST'
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
should_assign_to(:principal) { @user }
|
||||||
|
should_assign_to(:projects) { @projects }
|
||||||
|
should_render_template :projects
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an invalid search' do
|
||||||
|
setup do
|
||||||
|
@user = User.generate_with_protected!
|
||||||
|
Project.generate!(:name => "Test")
|
||||||
|
|
||||||
|
@request.session[:user_id] = 1
|
||||||
|
post :projects, {
|
||||||
|
:id => @user.id,
|
||||||
|
:q => 'nothing'
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
should_assign_to(:principal) { @user }
|
||||||
|
should_assign_to(:projects) { [] }
|
||||||
|
should_render_template :projects
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,9 +95,16 @@ class GroupsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new_membership_with_multiple_projects
|
||||||
|
assert_difference 'Group.find(10).members.count', 3 do
|
||||||
|
post :edit_membership, :id => 10, :project_ids => [1,2,3], :membership => { :role_ids => ['1', '2']}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy_membership
|
def test_destroy_membership
|
||||||
assert_difference 'Group.find(10).members.count', -1 do
|
assert_difference 'Group.find(10).members.count', -1 do
|
||||||
post :destroy_membership, :id => 10, :membership_id => 6
|
post :destroy_membership, :id => 10, :membership_id => 6
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -302,6 +302,13 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert_equal [2], Member.find(1).role_ids
|
assert_equal [2], Member.find(1).role_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_membership_with_multiple_projects
|
||||||
|
assert_difference 'User.find(2).members.count', 2 do
|
||||||
|
post :edit_membership, :id => 2, :project_ids => [3,6], :membership => { :role_ids => ['1', '2']}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy_membership
|
def test_destroy_membership
|
||||||
post :destroy_membership, :id => 2, :membership_id => 1
|
post :destroy_membership, :id => 2, :membership_id => 1
|
||||||
assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
|
assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
|
||||||
|
|
Loading…
Reference in New Issue