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

Fix resource quota permissions #77

Merged
merged 1 commit into from
Nov 26, 2024
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
4 changes: 4 additions & 0 deletions app/models/foreman_resource_quota/resource_quota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ResourceQuota < ApplicationRecord
scoped_search on: :name, complete_value: true
scoped_search on: :id, complete_enabled: false, only_explicit: true, validator: ScopedSearch::Validators::INTEGER

def self.permission_name
'resource_quotas'
end

def number_of_hosts
hosts_resources.size
end
Expand Down
32 changes: 16 additions & 16 deletions lib/foreman_resource_quota/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

# Add permissions
security_block :foreman_resource_quota do
permission 'view_foreman_resource_quota/resource_quotas',
permission :view_resource_quotas,
{ 'foreman_resource_quota/resource_quotas': %i[index welcome auto_complete_search],
'foreman_resource_quota/api/v2/resource_quotas': %i[index show utilization missing_hosts hosts users usergroups
auto_complete_search],
'foreman_resource_quota/api/v2/resource_quotas/:resource_quota_id/': %i[utilization missing_hosts hosts users
usergroups] },
resource_type: 'ForemanResourceQuota::ResourceQuota'
permission 'create_foreman_resource_quota/resource_quotas',
permission :create_resource_quotas,
{ 'foreman_resource_quota/resource_quotas': %i[new create],
'foreman_resource_quota/api/v2/resource_quotas': %i[create] },
resource_type: 'ForemanResourceQuota::ResourceQuota'
permission 'edit_foreman_resource_quota/resource_quotas',
permission :edit_resource_quotas,
{ 'foreman_resource_quota/resource_quotas': %i[edit update],
'foreman_resource_quota/api/v2/resource_quotas': %i[update] },
resource_type: 'ForemanResourceQuota::ResourceQuota'
permission 'destroy_foreman_resource_quota/resource_quotas',
permission :destroy_resource_quotas,
{ 'foreman_resource_quota/resource_quotas': %i[destroy],
'foreman_resource_quota/api/v2/resource_quotas': %i[destroy] },
resource_type: 'ForemanResourceQuota::ResourceQuota'
Expand All @@ -33,18 +33,18 @@
end

# Add a permissions to default roles (Viewer and Manager)
role 'Resource Quota Manager', ['view_foreman_resource_quota/resource_quotas',
'create_foreman_resource_quota/resource_quotas',
'edit_foreman_resource_quota/resource_quotas',
'destroy_foreman_resource_quota/resource_quotas',
'view_hosts',
'edit_hosts',
'view_users',
'edit_users']
role 'Resource Quota User', ['view_foreman_resource_quota/resource_quotas',
'view_hosts',
'view_users',
'view_usergroups']
role 'Resource Quota Manager', %i[view_resource_quotas
create_resource_quotas
edit_resource_quotas
destroy_resource_quotas
view_hosts
edit_hosts
view_users
edit_users]
role 'Resource Quota User', %i[view_resource_quotas
view_hosts
view_users
view_usergroups]
add_all_permissions_to_default_roles

# add controller parameter extension
Expand Down
Loading