diff --git a/app/controllers/api/v2/permissions_controller.rb b/app/controllers/api/v2/permissions_controller.rb index b7b7e1d21e5..aa0e8efd563 100644 --- a/app/controllers/api/v2/permissions_controller.rb +++ b/app/controllers/api/v2/permissions_controller.rb @@ -25,6 +25,14 @@ def resource_types @total = @resource_types.size render :resource_types, :layout => 'api/v2/layouts/index_layout' end + + api :GET, "/permissions/current_permissions", N_("List all permissions for current user") + def current_permissions + @user = User.current + @current_permissions = @user.admin? ? Permission.all : @user.permissions + @total = @current_permissions.size + render :current_permissions, :layout => 'api/v2/layouts/index_layout' + end end end end diff --git a/app/registries/foreman/access_permissions.rb b/app/registries/foreman/access_permissions.rb index e7893b63fef..b20008811b5 100644 --- a/app/registries/foreman/access_permissions.rb +++ b/app/registries/foreman/access_permissions.rb @@ -18,6 +18,7 @@ :bookmarks => [:index, :show, :auto_complete_search, :welcome], :"api/v2/bookmarks" => [:index, :show], }, :public => true + map.permission :current_permissions, { :"api/v2/permissions" => [:current_permissions] }, :public => true end permission_set.security_block :architectures do |map| diff --git a/app/views/api/v2/permissions/current_permissions.json.rabl b/app/views/api/v2/permissions/current_permissions.json.rabl new file mode 100644 index 00000000000..d090110f6ff --- /dev/null +++ b/app/views/api/v2/permissions/current_permissions.json.rabl @@ -0,0 +1,3 @@ +collection @current_permissions + +extends 'api/v2/permissions/main' diff --git a/config/routes/api/v2.rb b/config/routes/api/v2.rb index db47e07f49c..8a021a66969 100644 --- a/config/routes/api/v2.rb +++ b/config/routes/api/v2.rb @@ -158,6 +158,7 @@ resources :permissions, :only => [:index, :show] do collection do get :resource_types + get :current_permissions end end diff --git a/test/controllers/api/v2/permissions_controller_test.rb b/test/controllers/api/v2/permissions_controller_test.rb index d4e872a4c0b..3de9823e9c5 100644 --- a/test/controllers/api/v2/permissions_controller_test.rb +++ b/test/controllers/api/v2/permissions_controller_test.rb @@ -22,4 +22,10 @@ def assert_response_not_empty assert_not_nil assigns(:resource_types) assert_response_not_empty end + + test "should list current user permissions" do + get :current_permissions + assert_not_nil assigns(:current_permissions) + assert_response_not_empty + end end