]> source.dussan.org Git - redmine.git/commitdiff
Don't render memberships forms, use #edit instead.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Jan 2017 10:26:36 +0000 (10:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Jan 2017 10:26:36 +0000 (10:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16149 e93f8b46-1217-0410-a6f0-8f06a7374b81

18 files changed:
app/controllers/members_controller.rb
app/controllers/principal_memberships_controller.rb
app/helpers/principal_memberships_helper.rb
app/views/members/_edit.html.erb [new file with mode: 0644]
app/views/members/edit.html.erb [new file with mode: 0644]
app/views/members/edit.js.erb [new file with mode: 0644]
app/views/principal_memberships/_edit.html.erb [new file with mode: 0644]
app/views/principal_memberships/_index.html.erb
app/views/principal_memberships/edit.html.erb [new file with mode: 0644]
app/views/principal_memberships/edit.js.erb [new file with mode: 0644]
app/views/principal_memberships/update.js.erb
app/views/projects/settings/_members.html.erb
config/routes.rb
lib/redmine.rb
test/functional/members_controller_test.rb
test/functional/principal_memberships_controller_test.rb
test/integration/routing/members_test.rb
test/integration/routing/principal_memberships_test.rb

index ca3dcd474dede359547cd2767ba3ff46d0d114e3..38cdfcd8ad99a0a0187a69d97ec82bd898091645 100644 (file)
@@ -80,6 +80,10 @@ class MembersController < ApplicationController
     end
   end
 
+  def edit
+    @roles = Role.givable.to_a
+  end
+
   def update
     if params[:membership]
       @member.set_editable_role_ids(params[:membership][:role_ids])
index b03460b5475c805fd094a610909a11ac7c53390f..d4f4ba2ded596e7b5dabdbc905cd9f0cab2a2f3a 100644 (file)
@@ -21,7 +21,7 @@ class PrincipalMembershipsController < ApplicationController
 
   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
@@ -40,6 +40,10 @@ class PrincipalMembershipsController < ApplicationController
     end
   end
 
+  def edit
+    @roles = Role.givable.to_a
+  end
+
   def update
     @membership.attributes = params[:membership]
     @membership.save
index e3ef37798d2fa63daad00cde9bd6dba1c0b60f6d..10f278ddcc720b653613133ebab9e7b7253b63b7 100644 (file)
@@ -46,6 +46,14 @@ module PrincipalMembershipsHelper
     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)
diff --git a/app/views/members/_edit.html.erb b/app/views/members/_edit.html.erb
new file mode 100644 (file)
index 0000000..91c340f
--- /dev/null
@@ -0,0 +1,21 @@
+<%= 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 %>
diff --git a/app/views/members/edit.html.erb b/app/views/members/edit.html.erb
new file mode 100644 (file)
index 0000000..99ef316
--- /dev/null
@@ -0,0 +1,3 @@
+<%= title "#{@member.principal} - #{@member.project}" %>
+
+<%= render :partial => 'edit' %>
diff --git a/app/views/members/edit.js.erb b/app/views/members/edit.js.erb
new file mode 100644 (file)
index 0000000..379ed3e
--- /dev/null
@@ -0,0 +1,3 @@
+$("#member-<%= @member.id %>-roles").hide();
+$("#member-<%= @member.id %>-form").html("<%= escape_javascript(render :partial => "edit") %>");
+
diff --git a/app/views/principal_memberships/_edit.html.erb b/app/views/principal_memberships/_edit.html.erb
new file mode 100644 (file)
index 0000000..af05c49
--- /dev/null
@@ -0,0 +1,19 @@
+<%= 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 %>
index 76a629f952404578e8675b42ae55415e500b7bde..b451f536b9e81c71b2b39e1f1ab3bf5680e03546 100644 (file)
@@ -1,5 +1,3 @@
-<% 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>
diff --git a/app/views/principal_memberships/edit.html.erb b/app/views/principal_memberships/edit.html.erb
new file mode 100644 (file)
index 0000000..15e6412
--- /dev/null
@@ -0,0 +1,3 @@
+<%= title "#{@membership.principal} - #{@membership.project}" %>
+
+<%= render :partial => 'edit' %>
diff --git a/app/views/principal_memberships/edit.js.erb b/app/views/principal_memberships/edit.js.erb
new file mode 100644 (file)
index 0000000..083bac5
--- /dev/null
@@ -0,0 +1,2 @@
+$("#member-<%= @membership.id %>-roles").hide();
+$("#member-<%= @membership.id %>-form").html("<%= escape_javascript(render :partial => "edit") %>");
index 2986c4e55886d53260b3e374aeafe98ea3d149fc..2b720ff9eb2e9b806a8e2d21b386706f09d01589 100644 (file)
@@ -1,5 +1,8 @@
-<% 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(', ')))) %>');
index 1dd665a34e2afe7e00abc662f85e38365c37a227..4009e7b155e0699cf196eadf6eef16ddd57a66de 100644 (file)
@@ -1,5 +1,4 @@
-<% 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? %>
index 3a096e127160ae4f19ee27f912729b8ec766cfee..374e2b29418e3786667f65d8a1265232693cbd46 100644 (file)
@@ -113,7 +113,7 @@ Rails.application.routes.draw do
     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
index 4ad182046a3c0d7ebe40fed659d999752803e30c..e3ff60fd146e52350c67079da9fb00ad2ce6ce54 100644 (file)
@@ -83,7 +83,7 @@ Redmine::AccessControl.map do |map|
   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
 
index d132c8293cdc7b2f057b30fa9dfbe95b267a6690..6de763fd1b605c36b07bfbc17c010a8b68b37cfd 100644 (file)
@@ -110,6 +110,17 @@ class MembersControllerTest < Redmine::ControllerTest
     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}
index f20a52099efcb1c0a359dff4ce273ee8cb154c27..ca0b2c53a12dc7c48f36457ab012ea2afcc48667 100644 (file)
@@ -105,6 +105,17 @@ class PrincipalMembershipsControllerTest < Redmine::ControllerTest
     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]}
@@ -120,7 +131,7 @@ class PrincipalMembershipsControllerTest < Redmine::ControllerTest
       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
index ae3eb5b5e8cdc813b0e17193d745ce4aafc0cfb1..985d697e0f53bd17e198ed89fffa02c832654108 100644 (file)
@@ -22,6 +22,7 @@ class RoutingMembersTest < Redmine::RoutingTest
     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'
 
index b40eb2ca3640f163c86cfde5dc7e63db8b68f176..db91c850b20b5942db0a6385248a97d69522cdd1 100644 (file)
@@ -21,6 +21,7 @@ class RoutingPrincipalMembershipsTest < Redmine::RoutingTest
   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
@@ -28,6 +29,7 @@ class RoutingPrincipalMembershipsTest < Redmine::RoutingTest
   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