summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/groups_controller.rb18
-rw-r--r--app/controllers/principal_memberships_controller.rb80
-rw-r--r--app/controllers/users_controller.rb23
3 files changed, 83 insertions, 38 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 45ed4c4e1..d67f0382b 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -23,6 +23,7 @@ class GroupsController < ApplicationController
accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
helper :custom_fields
+ helper :principal_memberships
def index
respond_to do |format|
@@ -119,23 +120,6 @@ class GroupsController < ApplicationController
end
end
- def edit_membership
- @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
- @membership.save if request.post?
- respond_to do |format|
- format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
- format.js
- end
- end
-
- def destroy_membership
- Member.find(params[:membership_id]).destroy if request.post?
- respond_to do |format|
- format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
- format.js
- end
- end
-
private
def find_group
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
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index bb56fb285..d14914af4 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -19,13 +19,14 @@ class UsersController < ApplicationController
layout 'admin'
before_filter :require_admin, :except => :show
- before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership]
+ before_filter :find_user, :only => [:show, :edit, :update, :destroy]
accept_api_auth :index, :show, :create, :update, :destroy
helper :sort
include SortHelper
helper :custom_fields
include CustomFieldsHelper
+ helper :principal_memberships
def index
sort_init 'login', 'asc'
@@ -173,26 +174,6 @@ class UsersController < ApplicationController
end
end
- def edit_membership
- @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
- @membership.save
- respond_to do |format|
- format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
- format.js
- end
- end
-
- def destroy_membership
- @membership = Member.find(params[:membership_id])
- if @membership.deletable?
- @membership.destroy
- end
- respond_to do |format|
- format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
- format.js
- end
- end
-
private
def find_user