diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-23 21:46:40 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-23 21:46:40 +0000 |
commit | c2e73160daa7782d7a91f2b6a974a936c6f084da (patch) | |
tree | 62e174df69aba43cb5a84f2ddd278dc4562963f0 /app/controllers/principal_memberships_controller.rb | |
parent | ca5946d82ebb96464a3d283be657bc24ce0c47f1 (diff) | |
download | redmine-c2e73160daa7782d7a91f2b6a974a936c6f084da.tar.gz redmine-c2e73160daa7782d7a91f2b6a974a936c6f084da.zip |
Adds a single controller for users and groups memberships and support for adding multiple projects at once (#11702).
git-svn-id: http://svn.redmine.org/redmine/trunk@13498 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/principal_memberships_controller.rb')
-rw-r--r-- | app/controllers/principal_memberships_controller.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/app/controllers/principal_memberships_controller.rb b/app/controllers/principal_memberships_controller.rb new file mode 100644 index 000000000..5af897b6e --- /dev/null +++ b/app/controllers/principal_memberships_controller.rb @@ -0,0 +1,80 @@ +# Redmine - project management software +# Copyright (C) 2006-2014 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 PrincipalMembershipsController < ApplicationController + layout 'admin' + + before_filter :require_admin + before_filter :find_principal, :only => [:new, :create] + before_filter :find_membership, :only => [:update, :destroy] + + def new + @projects = Project.active.all + @roles = Role.find_all_givable + respond_to do |format| + format.html + format.js + end + end + + def create + @members = Member.create_principal_memberships(@principal, params[:membership]) + respond_to do |format| + format.html { redirect_to_principal @principal } + format.js + end + end + + def update + @membership.attributes = params[:membership] + @membership.save + respond_to do |format| + format.html { redirect_to_principal @principal } + format.js + end + end + + def destroy + if @membership.deletable? + @membership.destroy + end + respond_to do |format| + format.html { redirect_to_principal @principal } + format.js + end + end + + private + + def find_principal + principal_id = params[:user_id] || params[:group_id] + @principal = Principal.find(principal_id) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_membership + @membership = Member.find(params[:id]) + @principal = @membership.principal + rescue ActiveRecord::RecordNotFound + render_404 + end + + def redirect_to_principal(principal) + redirect_to edit_polymorphic_path(principal, :tab => 'memberships') + end +end |