diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-05 16:35:27 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-05 16:35:27 +0000 |
commit | 78bd24c6f738ea946622bfab5b6ea8a2040f5bde (patch) | |
tree | d170a86a5fe88326435223b19b5670fe2c5df439 | |
parent | 229b2f8d2af251e1bce0fa11946c41095c19f834 (diff) | |
download | redmine-78bd24c6f738ea946622bfab5b6ea8a2040f5bde.tar.gz redmine-78bd24c6f738ea946622bfab5b6ea8a2040f5bde.zip |
Resourcified project memberships.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8789 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/members_controller.rb | 23 | ||||
-rw-r--r-- | app/views/members/autocomplete.html.erb | 1 | ||||
-rw-r--r-- | app/views/members/autocomplete_for_member.html.erb | 1 | ||||
-rw-r--r-- | app/views/projects/settings/_members.html.erb | 23 | ||||
-rw-r--r-- | config/routes.rb | 12 | ||||
-rw-r--r-- | lib/redmine.rb | 2 | ||||
-rw-r--r-- | test/functional/members_controller_test.rb | 24 | ||||
-rw-r--r-- | test/integration/routing/members_test.rb | 14 |
8 files changed, 48 insertions, 52 deletions
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 6d5dd4733..ae2f57a13 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -17,15 +17,15 @@ class MembersController < ApplicationController model_object Member - before_filter :find_model_object, :except => [:new, :autocomplete_for_member] - before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member] - before_filter :find_project, :only => [:new, :autocomplete_for_member] + before_filter :find_model_object, :except => [:create, :autocomplete] + before_filter :find_project_from_association, :except => [:create, :autocomplete] + before_filter :find_project_by_project_id, :only => [:create, :autocomplete] before_filter :authorize - def new + def create members = [] - if params[:member] && request.post? - attrs = params[:member].dup + if params[:membership] && request.post? + attrs = params[:membership].dup if (user_ids = attrs.delete(:user_ids)) user_ids.each do |user_id| members << Member.new(attrs.merge(:user_id => user_id)) @@ -63,8 +63,11 @@ class MembersController < ApplicationController end end - def edit - if request.post? and @member.update_attributes(params[:member]) + def update + if params[:membership] + @member.role_ids = params[:membership][:role_ids] + end + if request.put? && @member.save respond_to do |format| format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } format.js { @@ -79,7 +82,7 @@ class MembersController < ApplicationController end def destroy - if request.post? && @member.deletable? + if request.delete? && @member.deletable? @member.destroy end respond_to do |format| @@ -92,7 +95,7 @@ class MembersController < ApplicationController end end - def autocomplete_for_member + def autocomplete @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals render :layout => false end diff --git a/app/views/members/autocomplete.html.erb b/app/views/members/autocomplete.html.erb new file mode 100644 index 000000000..a3ae74a0b --- /dev/null +++ b/app/views/members/autocomplete.html.erb @@ -0,0 +1 @@ +<%= principals_check_box_tags 'membership[user_ids][]', @principals %> diff --git a/app/views/members/autocomplete_for_member.html.erb b/app/views/members/autocomplete_for_member.html.erb deleted file mode 100644 index 96b4c973b..000000000 --- a/app/views/members/autocomplete_for_member.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= principals_check_box_tags 'member[user_ids][]', @principals %>
\ No newline at end of file diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb index 02591efe9..5cd3afd32 100644 --- a/app/views/projects/settings/_members.html.erb +++ b/app/views/projects/settings/_members.html.erb @@ -18,21 +18,19 @@ <td class="<%= member.principal.class.name.downcase %>"><%= link_to_user member.principal %></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, + <% remote_form_for(:membership, member, :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 'member[role_ids][]', role.id, member.roles.include?(role), + <label><%= check_box_tag 'membership[role_ids][]', role.id, member.roles.include?(role), :disabled => member.member_roles.detect {|mr| mr.role_id == role.id && !mr.inherited_from.nil?} %> <%=h role %></label><br /> <% end %></p> - <%= hidden_field_tag 'member[role_ids][]', '' %> + <%= hidden_field_tag 'membership[role_ids][]', '' %> <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 class="buttons"> <%= link_to_function l(:button_edit), @@ -40,8 +38,8 @@ :class => 'icon icon-edit' %> <%= link_to_remote( l(:button_delete), - { :url => {:controller => 'members', :action => 'destroy', :id => member}, - :method => :post, + { :url => membership_path(member), + :method => :delete, :confirm => (!User.current.admin? && member.include?(User.current) ? l(:text_own_membership_delete_confirmation) : nil) }, :title => l(:button_delete), :class => 'icon icon-del' @@ -61,7 +59,7 @@ <div class="splitcontentright"> <% if roles.any? && principals.any? %> - <% remote_form_for(:member, @member, :url => {:controller => 'members', :action => 'new', :id => @project}, :method => :post, + <% remote_form_for(:membership, @member, :url => project_memberships_path(@project), :method => :post, :loading => '$(\'member-add-submit\').disable();', :complete => 'if($(\'member-add-submit\')) $(\'member-add-submit\').enable();') do |f| %> <fieldset><legend><%=l(:label_member_new)%></legend> @@ -70,17 +68,18 @@ <%= observe_field(:principal_search, :frequency => 0.5, :update => :principals, - :url => { :controller => 'members', :action => 'autocomplete_for_member', :id => @project }, + :url => autocomplete_project_memberships_path(@project), + :method => :get, :with => 'q') %> <div id="principals"> - <%= principals_check_box_tags 'member[user_ids][]', principals %> + <%= principals_check_box_tags 'membership[user_ids][]', principals %> </div> <p><%= l(:label_role_plural) %>: <% roles.each do |role| %> - <label><%= check_box_tag 'member[role_ids][]', role.id %> <%=h role %></label> + <label><%= check_box_tag 'membership[role_ids][]', role.id %> <%=h role %></label> <% end %></p> <p><%= submit_tag l(:button_add), :id => 'member-add-submit' %></p> diff --git a/config/routes.rb b/config/routes.rb index 15953076f..66f0182be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,15 +96,6 @@ ActionController::Routing::Routes.draw do |map| map.connect 'my/order_blocks', :controller => 'my', :action => 'order_blocks', :conditions => {:method => :post} - map.connect 'projects/:id/members/new', :controller => 'members', - :action => 'new', :conditions => { :method => :post } - map.connect 'members/edit/:id', :controller => 'members', - :action => 'edit', :id => /\d+/, :conditions => { :method => :post } - map.connect 'members/destroy/:id', :controller => 'members', - :action => 'destroy', :id => /\d+/, :conditions => { :method => :post } - map.connect 'members/autocomplete_for_member/:id', :controller => 'members', - :action => 'autocomplete_for_member', :conditions => { :method => :post } - map.with_options :controller => 'users' do |users| users.user_membership 'users/:id/memberships/:membership_id', :action => 'edit_membership', @@ -178,6 +169,9 @@ ActionController::Routing::Routes.draw do |map| project.resources :boards project.resources :repositories, :shallow => true, :except => [:index, :show], :member => {:committers => [:get, :post]} + project.resources :memberships, :shallow => true, :controller => 'members', + :only => [:create, :update, :destroy], + :collection => {:autocomplete => :get} project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get} project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get} diff --git a/lib/redmine.rb b/lib/redmine.rb index 6cb88a9bc..2a55a5ddb 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -52,7 +52,7 @@ Redmine::AccessControl.map do |map| map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member map.permission :select_project_modules, {:projects => :modules}, :require => :member - map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member + map.permission :manage_members, {:projects => :settings, :members => [:create, :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 diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb index 3a4b2256c..ffea36e2b 100644 --- a/test/functional/members_controller_test.rb +++ b/test/functional/members_controller_test.rb @@ -35,7 +35,7 @@ class MembersControllerTest < ActionController::TestCase def test_create assert_difference 'Member.count' do - post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7} + post :create, :project_id => 1, :membership => {:role_ids => [1], :user_id => 7} end assert_redirected_to '/projects/ecookbook/settings/members' assert User.find(7).member_of?(Project.find(1)) @@ -43,7 +43,7 @@ class MembersControllerTest < ActionController::TestCase def test_create_multiple assert_difference 'Member.count', 3 do - post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} + post :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]} end assert_redirected_to '/projects/ecookbook/settings/members' assert User.find(7).member_of?(Project.find(1)) @@ -51,7 +51,7 @@ class MembersControllerTest < ActionController::TestCase def test_xhr_create assert_difference 'Member.count', 3 do - post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} + post :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}, :format => "js" end assert_select_rjs :replace_html, 'tab-content-members' assert User.find(7).member_of?(Project.find(1)) @@ -61,7 +61,7 @@ class MembersControllerTest < ActionController::TestCase def test_xhr_create_with_failure assert_no_difference 'Member.count' do - post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} + post :create, :project_id => 1, :membership => {:role_ids => [], :user_ids => [7, 8, 9]}, :format => "js" end assert_select '#tab-content-members', 0 assert @response.body.match(/alert/i), "Alert message not sent" @@ -69,14 +69,14 @@ class MembersControllerTest < ActionController::TestCase def test_edit assert_no_difference 'Member.count' do - post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3} + put :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3} end assert_redirected_to '/projects/ecookbook/settings/members' end def test_xhr_edit assert_no_difference 'Member.count' do - xhr :post, :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3} + xhr :put, :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3} end assert_select_rjs :replace_html, 'tab-content-members' member = Member.find(2) @@ -86,7 +86,7 @@ class MembersControllerTest < ActionController::TestCase def test_destroy assert_difference 'Member.count', -1 do - post :destroy, :id => 2 + delete :destroy, :id => 2 end assert_redirected_to '/projects/ecookbook/settings/members' assert !User.find(3).member_of?(Project.find(1)) @@ -94,17 +94,17 @@ class MembersControllerTest < ActionController::TestCase def test_xhr_destroy assert_difference 'Member.count', -1 do - xhr :post, :destroy, :id => 2 + xhr :delete, :destroy, :id => 2 end assert_select_rjs :replace_html, 'tab-content-members' end - def test_autocomplete_for_member - get :autocomplete_for_member, :id => 1, :q => 'mis' + def test_autocomplete + get :autocomplete, :project_id => 1, :q => 'mis' assert_response :success - assert_template 'autocomplete_for_member' + assert_template 'autocomplete' assert_tag :label, :content => /User Misc/, - :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } } + :child => { :tag => 'input', :attributes => { :name => 'membership[user_ids][]', :value => '8' } } end end diff --git a/test/integration/routing/members_test.rb b/test/integration/routing/members_test.rb index 169fc62a0..4c78b15c7 100644 --- a/test/integration/routing/members_test.rb +++ b/test/integration/routing/members_test.rb @@ -20,20 +20,20 @@ require File.expand_path('../../../test_helper', __FILE__) class RoutingMembersTest < ActionController::IntegrationTest def test_members assert_routing( - { :method => 'post', :path => "/projects/5234/members/new" }, - { :controller => 'members', :action => 'new', :id => '5234' } + { :method => 'post', :path => "/projects/5234/memberships" }, + { :controller => 'members', :action => 'create', :project_id => '5234' } ) assert_routing( - { :method => 'post', :path => "/members/edit/5234" }, - { :controller => 'members', :action => 'edit', :id => '5234' } + { :method => 'put', :path => "/memberships/5234" }, + { :controller => 'members', :action => 'update', :id => '5234' } ) assert_routing( - { :method => 'post', :path => "/members/destroy/5234" }, + { :method => 'delete', :path => "/memberships/5234" }, { :controller => 'members', :action => 'destroy', :id => '5234' } ) assert_routing( - { :method => 'post', :path => "/members/autocomplete_for_member/5234" }, - { :controller => 'members', :action => 'autocomplete_for_member', :id => '5234' } + { :method => 'get', :path => "/projects/5234/memberships/autocomplete" }, + { :controller => 'members', :action => 'autocomplete', :project_id => '5234' } ) end end |