annotate app/controllers/members_controller.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children a1bdbf8a87d5
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class MembersController < ApplicationController
Chris@0 19 model_object Member
Chris@1115 20 before_filter :find_model_object, :except => [:index, :create, :autocomplete]
Chris@1115 21 before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
Chris@1115 22 before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
Chris@0 23 before_filter :authorize
Chris@1115 24 accept_api_auth :index, :show, :create, :update, :destroy
Chris@0 25
Chris@1115 26 def index
Chris@1115 27 @offset, @limit = api_offset_and_limit
Chris@1115 28 @member_count = @project.member_principals.count
Chris@1464 29 @member_pages = Paginator.new @member_count, @limit, params['page']
Chris@1464 30 @offset ||= @member_pages.offset
Chris@1517 31 @members = @project.member_principals.
Chris@1517 32 order("#{Member.table_name}.id").
Chris@1517 33 limit(@limit).
Chris@1517 34 offset(@offset).
Chris@1517 35 all
Chris@1115 36 respond_to do |format|
Chris@1115 37 format.html { head 406 }
Chris@1115 38 format.api
Chris@1115 39 end
Chris@1115 40 end
Chris@1115 41
Chris@1115 42 def show
Chris@1115 43 respond_to do |format|
Chris@1115 44 format.html { head 406 }
Chris@1115 45 format.api
Chris@1115 46 end
Chris@1115 47 end
Chris@1115 48
Chris@1115 49 def create
Chris@0 50 members = []
Chris@1115 51 if params[:membership]
Chris@1115 52 if params[:membership][:user_ids]
Chris@1115 53 attrs = params[:membership].dup
Chris@1115 54 user_ids = attrs.delete(:user_ids)
Chris@0 55 user_ids.each do |user_id|
Chris@1115 56 members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
Chris@0 57 end
Chris@0 58 else
Chris@1115 59 members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
Chris@0 60 end
Chris@0 61 @project.members << members
Chris@0 62 end
Chris@1115 63
Chris@0 64 respond_to do |format|
Chris@1464 65 format.html { redirect_to_settings_in_projects }
Chris@1115 66 format.js { @members = members }
Chris@1115 67 format.api {
Chris@1115 68 @member = members.first
Chris@1115 69 if @member.valid?
Chris@1115 70 render :action => 'show', :status => :created, :location => membership_url(@member)
Chris@1115 71 else
Chris@1115 72 render_validation_errors(@member)
Chris@1115 73 end
Chris@1115 74 }
Chris@0 75 end
Chris@0 76 end
Chris@909 77
Chris@1115 78 def update
Chris@1115 79 if params[:membership]
Chris@1115 80 @member.role_ids = params[:membership][:role_ids]
Chris@929 81 end
Chris@1115 82 saved = @member.save
Chris@1115 83 respond_to do |format|
Chris@1464 84 format.html { redirect_to_settings_in_projects }
Chris@1115 85 format.js
Chris@1115 86 format.api {
Chris@1115 87 if saved
Chris@1115 88 render_api_ok
Chris@1115 89 else
Chris@1115 90 render_validation_errors(@member)
Chris@1115 91 end
Chris@1115 92 }
Chris@0 93 end
Chris@0 94 end
Chris@0 95
Chris@0 96 def destroy
Chris@1115 97 if request.delete? && @member.deletable?
Chris@0 98 @member.destroy
Chris@0 99 end
Chris@0 100 respond_to do |format|
Chris@1464 101 format.html { redirect_to_settings_in_projects }
Chris@1115 102 format.js
Chris@1115 103 format.api {
Chris@1115 104 if @member.destroyed?
Chris@1115 105 render_api_ok
Chris@1115 106 else
Chris@1115 107 head :unprocessable_entity
Chris@1115 108 end
Chris@0 109 }
Chris@0 110 end
Chris@0 111 end
Chris@909 112
Chris@1115 113 def autocomplete
Chris@1464 114 respond_to do |format|
Chris@1464 115 format.js
Chris@1464 116 end
Chris@1464 117 end
Chris@1464 118
Chris@1464 119 private
Chris@1464 120
Chris@1464 121 def redirect_to_settings_in_projects
Chris@1464 122 redirect_to settings_project_path(@project, :tab => 'members')
Chris@0 123 end
Chris@0 124 end