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

API support for adding/removing Policies to/from Policy Profiles #14575

Merged
merged 2 commits into from
Apr 27, 2017
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
12 changes: 12 additions & 0 deletions app/models/miq_policy_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def destroy_policy_tags
Tag.find_by(:name => "/miq_policy/assignment/#{self.class.to_s.underscore}/#{id}").try!(:destroy)
end

def add_policy(policy)
add_member(policy)
end

def remove_policy(policy)
remove_member(policy)
end

def get_policies
miq_policies
end

def add_to(ids, db)
model = db.respond_to?(:constantize) ? db.constantize : db
ids.each do|id|
Expand Down
8 changes: 6 additions & 2 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1160,15 +1160,19 @@
- :name: delete
:identifier: profile_delete
:disabled: true
:subcollection_actions:
:policies_subcollection_actions:
:post:
- :name: assign
:identifier: policy_profile_assign
- :name: unassign
:identifier: policy_profile_assign
- :name: resolve
:subresource_actions:
:policies_subresource_actions:
:post:
- :name: assign
:identifier: policy_profile_assign
- :name: unassign
:identifier: policy_profile_assign
- :name: resolve
:providers:
:description: Providers
Expand Down
5 changes: 5 additions & 0 deletions db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,11 @@
:feature_type: admin
:hidden: true
:identifier: profile_edit
- :name: Edit Policies Assignment
:description: Edit Policy Profile's policies assignments
:feature_type: admin
:hidden: true
:identifier: policy_profile_assign
- :name: Policies
:description: Everything under Policies Accordion
:protected: true
Expand Down
20 changes: 19 additions & 1 deletion spec/requests/api/policies_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def test_unassign_multiple_policies(object_policies_url, collection, subcollecti
api_basic_authorize subcollection_action_identifier(collection, subcollection, :unassign)

object = options[:object]

[p1, p2, p3].each { |p| object.add_policy(p) }
run_post(object_policies_url, gen_request(:unassign, [{:guid => p2.guid}, {:guid => p3.guid}]))
object.reload

expect_multiple_action_result(2)
expect(object.get_policies.size).to eq(1)
Expand All @@ -139,6 +139,24 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc
expect(object.get_policies.first.guid).to eq(ps1.guid)
end

context "Policy profile policies assignment" do
let(:policy_profile_url) { policy_profiles_url(ps2.id) }
let(:policy_profile_policies_url) { "#{policy_profile_url}/policies" }

it "adds Policies to a Policy Profile" do
test_assign_multiple_policies(policy_profile_url,
policy_profile_policies_url,
:policy_profiles,
:policies,
:object => ps2,
:policies => [p1, p2, p3])
end

it "removes Policies from a Policy Profile" do
test_unassign_multiple_policies(policy_profile_policies_url, :policy_profiles, :policies, :object => ps2)
end
end

context "Provider policies subcollection assignment" do
let(:provider_url) { providers_url(provider.id) }
let(:provider_policies_url) { "#{provider_url}/policies" }
Expand Down