end
end
+ def edit
+ @roles = Role.givable.to_a
+ end
+
def update
if params[:membership]
@member.set_editable_role_ids(params[:membership][:role_ids])
before_action :require_admin
before_action :find_principal, :only => [:new, :create]
- before_action :find_membership, :only => [:update, :destroy]
+ before_action :find_membership, :only => [:edit, :update, :destroy]
def new
@projects = Project.active.all
end
end
+ def edit
+ @roles = Role.givable.to_a
+ end
+
def update
@membership.attributes = params[:membership]
@membership.save
end
end
+ def edit_principal_membership_path(principal, *args)
+ if principal.is_a?(Group)
+ edit_group_membership_path(principal, *args)
+ else
+ edit_user_membership_path(principal, *args)
+ end
+ end
+
def principal_membership_path(principal, membership, *args)
if principal.is_a?(Group)
group_membership_path(principal, membership, *args)
--- /dev/null
+<%= form_for(@member, :url => membership_path(@member),
+ :as => :membership,
+ :remote => request.xhr?,
+ :method => :put) do |f| %>
+ <p>
+ <% @roles.each do |role| %>
+ <label>
+ <%= check_box_tag('membership[role_ids][]',
+ role.id, @member.roles.to_a.include?(role),
+ :id => nil,
+ :disabled => !@member.role_editable?(role)) %> <%= role %>
+ </label><br />
+ <% end %>
+ </p>
+ <%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
+ <p>
+ <%= submit_tag l(:button_save), :class => "small" %>
+ <%= link_to_function l(:button_cancel),
+ "$('#member-#{@member.id}-roles').show(); $('#member-#{@member.id}-form').empty(); return false;" if request.xhr? %>
+ </p>
+<% end %>
--- /dev/null
+<%= title "#{@member.principal} - #{@member.project}" %>
+
+<%= render :partial => 'edit' %>
--- /dev/null
+$("#member-<%= @member.id %>-roles").hide();
+$("#member-<%= @member.id %>-form").html("<%= escape_javascript(render :partial => "edit") %>");
+
--- /dev/null
+<%= form_for(:membership, :url => principal_membership_path(@principal, @membership),
+ :remote => request.xhr?,
+ :method => :put) do %>
+ <p>
+ <% @roles.each do |role| %>
+ <label>
+ <%= check_box_tag 'membership[role_ids][]', role.id, @membership.roles.to_a.include?(role),
+ :disabled => !@membership.role_editable?(role),
+ :id => nil %> <%= role.name %>
+ </label><br />
+ <% end %>
+ </p>
+ <%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
+ <p>
+ <%= submit_tag l(:button_save) %>
+ <%= link_to_function l(:button_cancel),
+ "$('#member-#{@membership.id}-roles').show(); $('#member-#{@membership.id}-form').empty(); return false;" if request.xhr? %>
+ </p>
+<% end %>
-<% roles = Role.find_all_givable %>
-
<p><%= link_to l(:label_add_projects), new_principal_membership_path(principal), :remote => true, :class => "icon icon-add" %></p>
<% if principal.memberships.any? %>
</td>
<td class="roles">
<span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span>
- <%= form_for(:membership, :remote => true,
- :url => principal_membership_path(principal, membership), :method => :put,
- :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),
- :disabled => membership.member_roles.detect {|mr| mr.role_id == role.id && !mr.inherited_from.nil?},
- :id => nil %> <%=h role %></label><br />
- <% end %></p>
- <%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
- <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 %>
+ <div id="member-<%= membership.id %>-form"></div>
</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 l(:button_edit),
+ edit_principal_membership_path(principal, membership),
+ :remote => true,
+ :class => 'icon icon-edit'
%>
<%= delete_link principal_membership_path(principal, membership), :remote => true if membership.deletable? %>
</td>
--- /dev/null
+<%= title "#{@membership.principal} - #{@membership.project}" %>
+
+<%= render :partial => 'edit' %>
--- /dev/null
+$("#member-<%= @membership.id %>-roles").hide();
+$("#member-<%= @membership.id %>-form").html("<%= escape_javascript(render :partial => "edit") %>");
-<% if @membership.valid? %>
- $('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'principal_memberships/index', :locals => {:principal => @principal}) %>');
+<% if @membership.destroyed? %>
+ $("#member-<%= @membership.id %>").remove();
+<% elsif @membership.valid? %>
+ $("#member-<%= @membership.id %>-form").empty();
+ $("#member-<%= @membership.id %>-roles").html("<%= escape_javascript @membership.roles.sort.collect(&:to_s).join(', ') %>").show();
$("#member-<%= @membership.id %>").effect("highlight");
<% else %>
alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))) %>');
-<% roles = Role.find_all_givable
- members = @project.memberships.sorted.to_a %>
+<% members = @project.memberships.sorted.to_a %>
<p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>
<td class="name icon icon-<%= member.principal.class.name.downcase %>"><%= link_to_user member.principal %></td>
<td class="roles">
<span id="member-<%= member.id %>-roles"><%= member.roles.sort.collect(&:to_s).join(', ') %></span>
- <%= form_for(member,
- {:as => :membership, :remote => true,
- :url => membership_path(member),
- :method => :put,
- :html => { :id => "member-#{member.id}-roles-form", :class => 'hol' }}
- ) do |f| %>
- <p>
- <% roles.each do |role| %>
- <label>
- <%= check_box_tag('membership[role_ids][]',
- role.id, member.roles.include?(role),
- :id => nil,
- :disabled => !member.role_editable?(role)) %> <%= role %>
- </label><br />
- <% end %>
- </p>
- <%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
- <p>
- <%= submit_tag l(:button_save), :class => "small" %>
- <%= link_to_function(l(:button_cancel),
- "$('#member-#{member.id}-roles').show(); $('#member-#{member.id}-roles-form').hide(); return false;") %>
- </p>
- <% end %>
+ <div id="member-<%= member.id %>-form"></div>
</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 l(:button_edit),
+ edit_membership_path(member),
+ :remote => true,
+ :class => 'icon icon-edit' %>
<%= delete_link membership_path(member),
:remote => true,
:data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {}) if member.deletable? %>
end
shallow do
- resources :memberships, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do
+ resources :memberships, :controller => 'members' do
collection do
get 'autocomplete'
end
map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
map.permission :select_project_modules, {:projects => :modules}, :require => :member
map.permission :view_members, {:members => [:index, :show]}, :public => true, :read => true
- map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :new, :create, :update, :destroy, :autocomplete]}, :require => :member
+ map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :new, :create, :edit, :update, :destroy, :autocomplete]}, :require => :member
map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
assert_match /alert/, response.body, "Alert message not sent"
end
+ def test_edit
+ get :edit, :id => 2
+ assert_response :success
+ assert_select 'input[name=?][value=?][checked=checked]', 'membership[role_ids][]', '2'
+ end
+
+ def test_xhr_edit
+ xhr :get, :edit, :id => 2
+ assert_response :success
+ end
+
def test_update
assert_no_difference 'Member.count' do
put :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
assert_include 'Role cannot be empty', response.body, "Error message not sent"
end
+ def test_edit_user_membership
+ get :edit, :user_id => 2, :id => 1
+ assert_response :success
+ assert_select 'input[name=?][value=?][checked=checked]', 'membership[role_ids][]', '1'
+ end
+
+ def test_xhr_edit_user_membership
+ xhr :get, :edit, :user_id => 2, :id => 1
+ assert_response :success
+ end
+
def test_update_user_membership
assert_no_difference 'Member.count' do
put :update, :user_id => 2, :id => 1, :membership => {:role_ids => [2]}
assert_equal 'text/javascript', response.content_type
end
assert_equal [2], Member.find(1).role_ids
- assert_include 'tab-content-memberships', response.body
+ assert_include '$("#member-1-roles").html("Developer").show();', response.body
end
def test_destroy_user_membership
should_route 'GET /projects/foo/memberships/new' => 'members#new', :project_id => 'foo'
should_route 'POST /projects/foo/memberships' => 'members#create', :project_id => 'foo'
+ should_route 'GET /memberships/5234/edit' => 'members#edit', :id => '5234'
should_route 'PUT /memberships/5234' => 'members#update', :id => '5234'
should_route 'DELETE /memberships/5234' => 'members#destroy', :id => '5234'
def test_user_memberships
should_route 'GET /users/123/memberships/new' => 'principal_memberships#new', :user_id => '123'
should_route 'POST /users/123/memberships' => 'principal_memberships#create', :user_id => '123'
+ should_route 'GET /users/123/memberships/55/edit' => 'principal_memberships#edit', :user_id => '123', :id => '55'
should_route 'PUT /users/123/memberships/55' => 'principal_memberships#update', :user_id => '123', :id => '55'
should_route 'DELETE /users/123/memberships/55' => 'principal_memberships#destroy', :user_id => '123', :id => '55'
end
def test_group_memberships
should_route 'GET /groups/123/memberships/new' => 'principal_memberships#new', :group_id => '123'
should_route 'POST /groups/123/memberships' => 'principal_memberships#create', :group_id => '123'
+ should_route 'GET /groups/123/memberships/55/edit' => 'principal_memberships#edit', :group_id => '123', :id => '55'
should_route 'PUT /groups/123/memberships/55' => 'principal_memberships#update', :group_id => '123', :id => '55'
should_route 'DELETE /groups/123/memberships/55' => 'principal_memberships#destroy', :group_id => '123', :id => '55'
end