Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36917 - Create current user permissions API #9902

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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