Skip to content

Commit

Permalink
Fixes #36917 - Create current user permissions API
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalyjur authored and adamruzicka committed Dec 1, 2023
1 parent dd26cc3 commit 7412115
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/api/v2/permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/registries/foreman/access_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
3 changes: 3 additions & 0 deletions app/views/api/v2/permissions/current_permissions.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collection @current_permissions

extends 'api/v2/permissions/main'
1 change: 1 addition & 0 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
resources :permissions, :only => [:index, :show] do
collection do
get :resource_types
get :current_permissions
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/controllers/api/v2/permissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7412115

Please sign in to comment.