Expose roles details via REST API (#11502).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10620 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-10-12 17:22:52 +00:00
parent 90e0d681dc
commit ad94777d9c
5 changed files with 44 additions and 5 deletions

View File

@ -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})

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -27,6 +27,10 @@ class RoutingRolesTest < ActionController::IntegrationTest
{ :method => 'get', :path => "/roles.xml" },
{ :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' }