Mercurial > hg > soundsoftware-site
diff app/controllers/roles_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 433d4f72a19b |
children | 622f24f53b42 |
line wrap: on
line diff
--- a/app/controllers/roles_controller.rb Wed Jan 23 13:11:25 2013 +0000 +++ b/app/controllers/roles_controller.rb Thu Jun 20 13:14:14 2013 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 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 @@ -18,44 +18,66 @@ class RolesController < ApplicationController layout 'admin' - before_filter :require_admin - - verify :method => :post, :only => [ :destroy ], - :redirect_to => { :action => :index } + before_filter :require_admin, :except => [:index, :show] + before_filter :require_admin_or_api_request, :only => [:index, :show] + before_filter :find_role, :only => [:show, :edit, :update, :destroy] + accept_api_auth :index, :show def index - @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' - render :action => "index", :layout => false if request.xhr? + respond_to do |format| + format.html { + @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position' + render :action => "index", :layout => false if request.xhr? + } + format.api { + @roles = Role.givable.all + } + end + end + + def show + respond_to do |format| + format.api + end end def new - # Prefills the form with 'Non member' role permissions + # Prefills the form with 'Non member' role permissions by default @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) + if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) + @role.copy_from(@copy_from) + end + @roles = Role.sorted.all + end + + def create + @role = Role.new(params[:role]) if request.post? && @role.save # workflow copy if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) - @role.workflows.copy(copy_from) + @role.workflow_rules.copy(copy_from) end flash[:notice] = l(:notice_successful_create) redirect_to :action => 'index' else - @permissions = @role.setable_permissions - @roles = Role.find :all, :order => 'builtin, position' + @roles = Role.sorted.all + render :action => 'new' end end def edit - @role = Role.find(params[:id]) - if request.post? and @role.update_attributes(params[:role]) + end + + def update + if request.put? and @role.update_attributes(params[:role]) flash[:notice] = l(:notice_successful_update) redirect_to :action => 'index' else - @permissions = @role.setable_permissions + render :action => 'edit' end end def destroy - @role = Role.find(params[:id]) @role.destroy redirect_to :action => 'index' rescue @@ -63,8 +85,8 @@ redirect_to :action => 'index' end - def report - @roles = Role.find(:all, :order => 'builtin, position') + def permissions + @roles = Role.sorted.all @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } if request.post? @roles.each do |role| @@ -75,4 +97,12 @@ redirect_to :action => 'index' end end + + private + + def find_role + @role = Role.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end end