diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-12 17:22:52 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-12 17:22:52 +0000 |
commit | ad94777d9c2475ccbc9b933302b2fd427e944d87 (patch) | |
tree | 605bfd6c4c68839b9fbbf00ac6a1536ce857e361 | |
parent | 90e0d681dcd911ab597628213bda4bbb6ee3c5f7 (diff) | |
download | redmine-ad94777d9c2475ccbc9b933302b2fd427e944d87.tar.gz redmine-ad94777d9c2475ccbc9b933302b2fd427e944d87.zip |
Expose roles details via REST API (#11502).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10620 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/roles_controller.rb | 13 | ||||
-rw-r--r-- | app/views/roles/show.api.rsb | 9 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | test/integration/api_test/roles_test.rb | 21 | ||||
-rw-r--r-- | test/integration/routing/roles_test.rb | 4 |
5 files changed, 44 insertions, 5 deletions
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 5f3885267..29e7604dc 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -18,10 +18,9 @@ class RolesController < ApplicationController layout 'admin' - before_filter :require_admin, :except => :index - before_filter :require_admin_or_api_request, :only => :index - before_filter :find_role, :only => [:edit, :update, :destroy] - accept_api_auth :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] def index respond_to do |format| @@ -35,6 +34,12 @@ class RolesController < ApplicationController end end + def show + respond_to do |format| + format.api + end + end + def new # Prefills the form with 'Non member' role permissions by default @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) diff --git a/app/views/roles/show.api.rsb b/app/views/roles/show.api.rsb new file mode 100644 index 000000000..4e81819cf --- /dev/null +++ b/app/views/roles/show.api.rsb @@ -0,0 +1,9 @@ +api.role do + api.id @role.id + api.name @role.name + api.array :permissions do + @role.permissions.each do |perm| + api.permission(perm.to_s) + end + end +end diff --git a/config/routes.rb b/config/routes.rb index a7e0bdc56..61a580097 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -289,7 +289,7 @@ RedmineApp::Application.routes.draw do end end resources :custom_fields, :except => :show - resources :roles, :except => :show do + resources :roles do collection do match 'permissions', :via => [:get, :post] end diff --git a/test/integration/api_test/roles_test.rb b/test/integration/api_test/roles_test.rb index 87affe18c..807e1ffee 100644 --- a/test/integration/api_test/roles_test.rb +++ b/test/integration/api_test/roles_test.rb @@ -66,4 +66,25 @@ class ApiTest::RolesTest < ActionController::IntegrationTest end end end + + context "/roles/:id" do + context "GET" do + context "xml" do + should "return the role" do + get '/roles/1.xml' + + assert_response :success + assert_equal 'application/xml', @response.content_type + + assert_select 'role' do + assert_select 'name', :text => 'Manager' + assert_select 'role permissions[type=array]' do + assert_select 'permission', Role.find(1).permissions.size + assert_select 'permission', :text => 'view_issues' + end + end + end + end + end + end end diff --git a/test/integration/routing/roles_test.rb b/test/integration/routing/roles_test.rb index 0ec486a07..401ab0d48 100644 --- a/test/integration/routing/roles_test.rb +++ b/test/integration/routing/roles_test.rb @@ -28,6 +28,10 @@ class RoutingRolesTest < ActionController::IntegrationTest { :controller => 'roles', :action => 'index', :format => 'xml' } ) assert_routing( + { :method => 'get', :path => "/roles/2.xml" }, + { :controller => 'roles', :action => 'show', :id => '2', :format => 'xml' } + ) + assert_routing( { :method => 'get', :path => "/roles/new" }, { :controller => 'roles', :action => 'new' } ) |