summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-05-10 10:54:31 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-05-10 10:54:31 +0000
commit7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643 (patch)
treeba6a18abff6ca69af528b3d295263d049a22266f /app
parent814e138c2a1105f8d9d10c4362a889dd71aff32d (diff)
downloadredmine-7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643.tar.gz
redmine-7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643.zip
Allows multiple roles on the same project (#706). Prerequisite for user groups feature.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2726 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application.rb4
-rw-r--r--app/controllers/issues_controller.rb2
-rw-r--r--app/controllers/members_controller.rb7
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/controllers/queries_controller.rb4
-rw-r--r--app/controllers/roles_controller.rb8
-rw-r--r--app/controllers/users_controller.rb18
-rw-r--r--app/helpers/application_helper.rb4
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/issue_status.rb32
-rw-r--r--app/models/member.rb22
-rw-r--r--app/models/member_role.rb27
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/role.rb9
-rw-r--r--app/models/user.rb24
-rw-r--r--app/views/account/show.rhtml2
-rw-r--r--app/views/projects/settings/_members.rhtml40
-rw-r--r--app/views/queries/_form.rhtml2
-rw-r--r--app/views/users/_memberships.rhtml60
-rw-r--r--app/views/workflows/edit.rhtml2
20 files changed, 180 insertions, 97 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index f86487305..9123cfc07 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -38,10 +38,6 @@ class ApplicationController < ActionController::Base
require_dependency "repository/#{scm.underscore}"
end
- def current_role
- @current_role ||= User.current.role_for_project(@project)
- end
-
def user_setup
# Check the settings cache for each request
Setting.check_cache
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 784d620e3..24c204098 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -146,7 +146,7 @@ class IssuesController < ApplicationController
return
end
@issue.status = default_status
- @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
+ @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
if request.get? || request.xhr?
@issue.start_date ||= Date.today
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb
index e2bc9257f..eb5989525 100644
--- a/app/controllers/members_controller.rb
+++ b/app/controllers/members_controller.rb
@@ -48,7 +48,12 @@ class MembersController < ApplicationController
if request.post? and @member.update_attributes(params[:member])
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
- format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
+ format.js {
+ render(:update) {|page|
+ page.replace_html "tab-content-members", :partial => 'projects/settings/members'
+ page.visual_effect(:highlight, "member-#{@member.id}")
+ }
+ }
end
end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b663291de..3f29e4e4c 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -112,7 +112,7 @@ class ProjectsController < ApplicationController
redirect_to_project_menu_item(@project, params[:jump]) && return
end
- @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
+ @members_by_role = @project.members.find(:all, :include => [:user, :roles], :order => 'position').group_by {|m| m.roles.first}
@subprojects = @project.children.visible
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
@trackers = @project.rolled_up_trackers
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index b688d2c43..16755a125 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -24,7 +24,7 @@ class QueriesController < ApplicationController
@query = Query.new(params[:query])
@query.project = params[:query_is_for_all] ? nil : @project
@query.user = User.current
- @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
+ @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
@query.column_names = nil if params[:default_columns]
params[:fields].each do |field|
@@ -48,7 +48,7 @@ class QueriesController < ApplicationController
end if params[:fields]
@query.attributes = params[:query]
@query.project = nil if params[:query_is_for_all]
- @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
+ @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
@query.column_names = nil if params[:default_columns]
if @query.save
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb
index 6185d70ef..8074b18b9 100644
--- a/app/controllers/roles_controller.rb
+++ b/app/controllers/roles_controller.rb
@@ -40,7 +40,7 @@ class RolesController < ApplicationController
@role.workflows.copy(copy_from)
end
flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'list'
+ redirect_to :action => 'index'
end
@permissions = @role.setable_permissions
@roles = Role.find :all, :order => 'builtin, position'
@@ -50,7 +50,7 @@ class RolesController < ApplicationController
@role = Role.find(params[:id])
if request.post? and @role.update_attributes(params[:role])
flash[:notice] = l(:notice_successful_update)
- redirect_to :action => 'list'
+ redirect_to :action => 'index'
end
@permissions = @role.setable_permissions
end
@@ -58,7 +58,7 @@ class RolesController < ApplicationController
def destroy
@role = Role.find(params[:id])
@role.destroy
- redirect_to :action => 'list'
+ redirect_to :action => 'index'
rescue
flash[:error] = 'This role is in use and can not be deleted.'
redirect_to :action => 'index'
@@ -73,7 +73,7 @@ class RolesController < ApplicationController
role.save
end
flash[:notice] = l(:notice_successful_update)
- redirect_to :action => 'list'
+ redirect_to :action => 'index'
end
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index e0b508c7b..72a4b6c83 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -86,10 +86,7 @@ class UsersController < ApplicationController
end
end
@auth_sources = AuthSource.find(:all)
- @roles = Role.find_all_givable
- @projects = Project.active.find(:all, :order => 'lft')
@membership ||= Member.new
- @memberships = @user.memberships
end
def edit_membership
@@ -97,12 +94,23 @@ class UsersController < ApplicationController
@membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
@membership.attributes = params[:membership]
@membership.save if request.post?
- redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
+ respond_to do |format|
+ format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
+ format.js {
+ render(:update) {|page|
+ page.replace_html "tab-content-memberships", :partial => 'users/memberships'
+ page.visual_effect(:highlight, "member-#{@membership.id}")
+ }
+ }
+ end
end
def destroy_membership
@user = User.find(params[:id])
Member.find(params[:membership_id]).destroy if request.post?
- redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
+ respond_to do |format|
+ format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
+ format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
+ end
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b7865ecde..2382983ff 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -28,10 +28,6 @@ module ApplicationHelper
extend Forwardable
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
- def current_role
- @current_role ||= User.current.role_for_project(@project)
- end
-
# Return true if user is authorized for controller/action, otherwise false
def authorize_for(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @project)
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 23035b927..da49577e5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -205,7 +205,7 @@ class Issue < ActiveRecord::Base
# Returns an array of status that user is able to apply
def new_statuses_allowed_to(user)
- statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
+ statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker)
statuses << status unless statuses.empty?
statuses.uniq.sort
end
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index 16c7bce91..ca33d37d6 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -36,24 +36,34 @@ class IssueStatus < ActiveRecord::Base
# Returns an array of all statuses the given role can switch to
# Uses association cache when called more than one time
- def new_statuses_allowed_to(role, tracker)
- new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
- new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : []
+ def new_statuses_allowed_to(roles, tracker)
+ if roles && tracker
+ role_ids = roles.collect(&:id)
+ new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort
+ else
+ []
+ end
end
# Same thing as above but uses a database query
# More efficient than the previous method if called just once
- def find_new_statuses_allowed_to(role, tracker)
- new_statuses = workflows.find(:all,
- :include => :new_status,
- :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker
- new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : []
+ def find_new_statuses_allowed_to(roles, tracker)
+ if roles && tracker
+ workflows.find(:all,
+ :include => :new_status,
+ :conditions => { :role_id => roles.collect(&:id),
+ :tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort
+ else
+ []
+ end
end
- def new_status_allowed_to?(status, role, tracker)
- status && role && tracker ?
- !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? :
+ def new_status_allowed_to?(status, roles, tracker)
+ if status && roles && tracker
+ !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil?
+ else
false
+ end
end
def <=>(status)
diff --git a/app/models/member.rb b/app/models/member.rb
index 5228d1ffc..2dc91cba7 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# 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
@@ -17,15 +17,12 @@
class Member < ActiveRecord::Base
belongs_to :user
- belongs_to :role
+ has_many :member_roles, :dependent => :delete_all
+ has_many :roles, :through => :member_roles
belongs_to :project
- validates_presence_of :role, :user, :project
+ validates_presence_of :user, :project
validates_uniqueness_of :user_id, :scope => :project_id
-
- def validate
- errors.add :role_id, :invalid if role && !role.member?
- end
def name
self.user.name
@@ -42,11 +39,18 @@ class Member < ActiveRecord::Base
end
def <=>(member)
- role == member.role ? (user <=> member.user) : (role <=> member.role)
+ a, b = roles.sort.first, member.roles.sort.first
+ a == b ? (user <=> member.user) : (a <=> b)
end
def before_destroy
# remove category based auto assignments for this member
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
end
+
+ protected
+
+ def validate
+ errors.add_to_base "Role can't be blank" if roles.empty?
+ end
end
diff --git a/app/models/member_role.rb b/app/models/member_role.rb
new file mode 100644
index 000000000..46777cd1e
--- /dev/null
+++ b/app/models/member_role.rb
@@ -0,0 +1,27 @@
+# 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.
+
+class MemberRole < ActiveRecord::Base
+ belongs_to :member
+ belongs_to :role
+
+ validates_presence_of :role
+
+ def validate
+ errors.add :role_id, :invalid if role && !role.member?
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 261844e8e..922f522f1 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -135,7 +135,7 @@ class Project < ActiveRecord::Base
statements << "1=0"
if user.logged?
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
- allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
+ allowed_project_ids = user.memberships.select {|m| m.roles.detect {|role| role.allowed_to?(permission)}}.collect {|m| m.project_id}
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
elsif Role.anonymous.allowed_to?(permission)
# anonymous user allowed on public project
@@ -247,12 +247,14 @@ class Project < ActiveRecord::Base
# Deletes all project's members
def delete_all_members
+ me, mr = Member.table_name, MemberRole.table_name
+ connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
Member.delete_all(['project_id = ?', id])
end
# Users issues can be assigned to
def assignable_users
- members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
+ members.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.user}.sort
end
# Returns the mail adresses of users that should be always notified on project events
diff --git a/app/models/role.rb b/app/models/role.rb
index b07e7a039..a93c4eaca 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -38,7 +38,8 @@ class Role < ActiveRecord::Base
end
end
- has_many :members
+ has_many :member_roles, :dependent => :destroy
+ has_many :members, :through => :member_roles
acts_as_list
serialize :permissions, Array
@@ -82,7 +83,11 @@ class Role < ActiveRecord::Base
end
def <=>(role)
- position <=> role.position
+ role ? position <=> role.position : -1
+ end
+
+ def to_s
+ name
end
# Return true if the role is a builtin role
diff --git a/app/models/user.rb b/app/models/user.rb
index 3c9a1c753..3c6f72387 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -33,7 +33,7 @@ class User < ActiveRecord::Base
:username => '#{login}'
}
- has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name"
+ has_many :memberships, :class_name => 'Member', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name"
has_many :members, :dependent => :delete_all
has_many :projects, :through => :memberships
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
@@ -229,26 +229,30 @@ class User < ActiveRecord::Base
!logged?
end
- # Return user's role for project
- def role_for_project(project)
+ # Return user's roles for project
+ def roles_for_project(project)
+ roles = []
# No role on archived projects
- return nil unless project && project.active?
+ return roles unless project && project.active?
if logged?
# Find project membership
membership = memberships.detect {|m| m.project_id == project.id}
if membership
- membership.role
+ roles = membership.roles
else
@role_non_member ||= Role.non_member
+ roles << @role_non_member
end
else
@role_anonymous ||= Role.anonymous
+ roles << @role_anonymous
end
+ roles
end
# Return true if the user is a member of project
def member_of?(project)
- role_for_project(project).member?
+ !roles_for_project(project).detect {|role| role.member?}.nil?
end
# Return true if the user is allowed to do the specified action on project
@@ -264,13 +268,13 @@ class User < ActiveRecord::Base
# Admin users are authorized for anything else
return true if admin?
- role = role_for_project(project)
- return false unless role
- role.allowed_to?(action) && (project.is_public? || role.member?)
+ roles = roles_for_project(project)
+ return false unless roles
+ roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
elsif options[:global]
# authorize if user has at least one role that has this permission
- roles = memberships.collect {|m| m.role}.uniq
+ roles = memberships.collect {|m| m.roles}.flatten.uniq
roles.detect {|r| r.allowed_to?(action)} || (self.logged? ? Role.non_member.allowed_to?(action) : Role.anonymous.allowed_to?(action))
else
false
diff --git a/app/views/account/show.rhtml b/app/views/account/show.rhtml
index 6b70c5f86..c97da7f97 100644
--- a/app/views/account/show.rhtml
+++ b/app/views/account/show.rhtml
@@ -25,7 +25,7 @@
<ul>
<% for membership in @memberships %>
<li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %>
- (<%=h membership.role.name %>, <%= format_date(membership.created_on) %>)</li>
+ (<%=h membership.roles.collect(&:to_s).join(', ') %>, <%= format_date(membership.created_on) %>)</li>
<% end %>
</ul>
<% end %>
diff --git a/app/views/projects/settings/_members.rhtml b/app/views/projects/settings/_members.rhtml
index 312403993..a6bdd9504 100644
--- a/app/views/projects/settings/_members.rhtml
+++ b/app/views/projects/settings/_members.rhtml
@@ -1,36 +1,43 @@
<%= error_messages_for 'member' %>
<% roles = Role.find_all_givable
- members = @project.members.find(:all, :include => [:role, :user]).sort %>
+ members = @project.members.find(:all, :include => [:roles, :user]).sort %>
<div class="splitcontentleft">
<% if members.any? %>
-<table class="list">
+<table class="list members">
<thead>
<th><%= l(:label_user) %></th>
- <th><%= l(:label_role) %></th>
+ <th><%= l(:label_role_plural) %></th>
<th style="width:15%"></th>
<%= call_hook(:view_projects_settings_members_table_header, :project => @project) %>
</thead>
<tbody>
<% members.each do |member| %>
<% next if member.new_record? %>
- <tr id="member-<%= member.id %>" class="<%= cycle 'odd', 'even' %>">
- <td><%=h member.name %></td>
- <td align="center">
+ <tr id="member-<%= member.id %>" class="<%= cycle 'odd', 'even' %> member">
+ <td class="user"><%= link_to_user member.user %></td>
+ <td class="roles">
+ <span id="member-<%= member.id %>-roles"><%=h member.roles.sort.collect(&:to_s).join(', ') %></span>
<% if authorize_for('members', 'edit') %>
- <% remote_form_for(:member, member, :url => {:controller => 'members', :action => 'edit', :id => member}, :method => :post) do |f| %>
- <%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, {}, :class => "small" %>
- <%= submit_tag l(:button_change), :class => "small" %>
+ <% remote_form_for(:member, member, :url => {:controller => 'members', :action => 'edit', :id => member},
+ :method => :post,
+ :html => { :id => "member-#{member.id}-roles-form", :style => 'display:none;' }) do |f| %>
+ <p><% roles.each do |role| %>
+ <label><%= check_box_tag 'member[role_ids][]', role.id, member.roles.include?(role) %> <%=h role %></label><br />
+ <% end %></p>
+ <p><%= submit_tag l(:button_change), :class => "small" %>
+ <%= link_to_function l(:button_cancel), "$('member-#{member.id}-roles').show(); $('member-#{member.id}-roles-form').hide(); return false;" %></p>
<% end %>
<% end %>
- </td>
- <td align="center">
+ </td>
+ <td class="buttons">
+ <%= link_to_function l(:button_edit), "$('member-#{member.id}-roles').hide(); $('member-#{member.id}-roles-form').show(); return false;", :class => 'icon icon-edit' %>
<%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member},
:method => :post
}, :title => l(:button_delete),
:class => 'icon icon-del' %>
- </td>
- <%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %>
+ </td>
+ <%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %>
</tr>
</tbody>
<% end; reset_cycle %>
@@ -58,8 +65,11 @@
<% end -%>
</div>
<% end %>
- <p><%= l(:label_role) %>: <%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, :selected => nil %>
- <%= submit_tag l(:button_add) %></p>
+ <p><%= l(:label_role_plural) %>:
+ <% roles.each do |role| %>
+ <label><%= check_box_tag 'member[role_ids][]', role.id %> <%=h role %></label>
+ <% end %></p>
+ <p><%= submit_tag l(:button_add) %></p>
</fieldset>
<% end %>
<% end %>
diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml
index 28faba177..577699d70 100644
--- a/app/views/queries/_form.rhtml
+++ b/app/views/queries/_form.rhtml
@@ -6,7 +6,7 @@
<p><label for="query_name"><%=l(:field_name)%></label>
<%= text_field 'query', 'name', :size => 80 %></p>
-<% if User.current.admin? || (@project && current_role.allowed_to?(:manage_public_queries)) %>
+<% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %>
<p><label for="query_is_public"><%=l(:field_is_public)%></label>
<%= check_box 'query', 'is_public',
:onchange => (User.current.admin? ? nil : 'if (this.checked) {$("query_is_for_all").checked = false; $("query_is_for_all").disabled = true;} else {$("query_is_for_all").disabled = false;}') %></p>
diff --git a/app/views/users/_memberships.rhtml b/app/views/users/_memberships.rhtml
index d1657fb98..8b458e0b2 100644
--- a/app/views/users/_memberships.rhtml
+++ b/app/views/users/_memberships.rhtml
@@ -1,24 +1,36 @@
-<% if @memberships.any? %>
+<% roles = Role.find_all_givable %>
+<% projects = Project.active.find(:all, :order => 'lft') %>
+
+<div class="splitcontentleft">
+<% if @user.memberships.any? %>
<table class="list memberships">
<thead>
<th><%= l(:label_project) %></th>
- <th><%= l(:label_role) %></th>
+ <th><%= l(:label_role_plural) %></th>
<th style="width:15%"></th>
</thead>
<tbody>
- <% @memberships.each do |membership| %>
+ <% @user.memberships.each do |membership| %>
<% next if membership.new_record? %>
- <tr class="<%= cycle 'odd', 'even' %>">
- <td><%=h membership.project %></td>
- <td align="center">
- <% form_tag({ :action => 'edit_membership', :id => @user, :membership_id => membership }) do %>
- <%= select_tag 'membership[role_id]', options_from_collection_for_select(@roles, "id", "name", membership.role_id) %>
- <%= submit_tag l(:button_change), :class => "small" %>
+ <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class">
+ <td class="project"><%=h membership.project %></td>
+ <td class="roles">
+ <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span>
+ <% remote_form_for(:membership, :url => { :action => 'edit_membership', :id => @user, :membership_id => membership },
+ :html => { :id => "member-#{membership.id}-roles-form", :style => 'display:none;'}) do %>
+ <p><% roles.each do |role| %>
+ <label><%= check_box_tag 'membership[role_ids][]', role.id, membership.roles.include?(role) %> <%=h role %></label><br />
+ <% end %></p>
+ <p><%= submit_tag l(:button_change) %>
+ <%= link_to_function l(:button_cancel), "$('member-#{membership.id}-roles').show(); $('member-#{membership.id}-roles-form').hide(); return false;" %></p>
<% end %>
- </td>
- <td align="center">
- <%= link_to l(:button_delete), {:action => 'destroy_membership', :id => @user, :membership_id => membership }, :method => :post, :class => 'icon icon-del' %>
- </td>
+ </td>
+ <td class="buttons">
+ <%= link_to_function l(:button_edit), "$('member-#{membership.id}-roles').hide(); $('member-#{membership.id}-roles-form').show(); return false;", :class => 'icon icon-edit' %>
+ <%= link_to_remote l(:button_delete), { :url => { :controller => 'users', :action => 'destroy_membership', :id => @user, :membership_id => membership },
+ :method => :post },
+ :class => 'icon icon-del' %>
+ </td>
</tr>
</tbody>
<% end; reset_cycle %>
@@ -26,15 +38,19 @@
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
+</div>
-<% if @projects.any? %>
-<p>
-<label><%=l(:label_project_new)%></label><br/>
-<% form_tag({ :action => 'edit_membership', :id => @user }) do %>
-<%= select_tag 'membership[project_id]', options_for_membership_project_select(@user, @projects) %>
-<%= l(:label_role) %>:
-<%= select_tag 'membership[role_id]', options_from_collection_for_select(@roles, "id", "name") %>
-<%= submit_tag l(:button_add) %>
+<div class="splitcontentright">
+<% if projects.any? %>
+<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 %>
-</p>
+</fieldset>
<% end %>
+</div>
diff --git a/app/views/workflows/edit.rhtml b/app/views/workflows/edit.rhtml
index 1aef8eb7e..134dfb3e7 100644
--- a/app/views/workflows/edit.rhtml
+++ b/app/views/workflows/edit.rhtml
@@ -43,7 +43,7 @@
<% for old_status in @statuses %>
<tr class="<%= cycle("odd", "even") %>">
<td><%= old_status.name %></td>
- <% new_status_ids_allowed = old_status.find_new_statuses_allowed_to(@role, @tracker).collect(&:id) -%>
+ <% new_status_ids_allowed = old_status.find_new_statuses_allowed_to([@role], @tracker).collect(&:id) -%>
<% for new_status in @statuses -%>
<td align="center">
<input type="checkbox"