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

Filter tenants and groups in Access Control by current region #4831

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

ZitaNemeckova
Copy link
Contributor

Closes #4720

  • Have a bunch of tenants
  • If you have all tenants in one region Tenant.count == Tenant.in_my_region.count set id of one of tenants to something outside current region(multiple its id by 3 or something)
  • Go to Configuration -> Access Control -> click a region

In this case cloudusers tenant is not in Tenant.in_my_region

Before:
image

After:
screen shot 2018-10-25 at 1 50 36 pm

@miq-bot add_label bug, hammer/no,

@mzazrivec
Copy link
Contributor

@lpichler is this change OK with you?


describe "#x_get_tree_tenant_kids" do
let!(:child_tenant) { FactoryGirl.create(:tenant, :parent => Tenant.root_tenant) }
let!(:child_tenant_out_of_region) { FactoryGirl.create(:tenant, :parent => Tenant.root_tenant, :id => Tenant.root_tenant.id * 3) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZitaNemeckova

you created child tenant in default region and his child which is "probably"( * 3) in different region and this situation doesn't happen in real.

we need to create tenant structure in default region and then whole tenant structure in other tenant region

and then check whether it is listing only tenant in current region.

you can get some inspiration from https://github.com/ManageIQ/manageiq/pull/17453/files#diff-de9adf0bd8114667190fecb643922d79R941 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usingid_in_region sounds better 👍

@ZitaNemeckova
Copy link
Contributor Author

@lpichler Changed it as you suggested so Tenant is in a MiqRegion that actually exists and not some random "of by three" non-existent one :) Is it ok with you now?

@@ -58,6 +58,6 @@ def x_get_tree_custom_kids(object_hash, count_only, _options)
end

def x_get_tree_tenant_kids(object, count_only)
count_only_or_objects(count_only, object.children, "name")
count_only_or_objects(count_only, object.children.in_my_region, "name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed, because object is already in one region and his children will be also the same region. I can show it you in my env.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's no way for a Tenant to have a child that's in another region. Noted :)

@@ -83,4 +83,17 @@ def x_get_tree_custom_kids_for_and_expect_objects(type_of_model, expected_object
end
end
end

describe "#x_get_tree_tenant_kids" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better however you are testing a code which I suggested to removed - you can still reuse the test for the "count" part.

and tests are better but it is still not reflect DB with 2 region, you can image it like two duplicated DB with different IDs, so one object in one region exists like duplicated object in other region.
You tests are mixing it together(like one tenant has children from other region) which is probably testing issue but it is not same as in real. SO I am suggesting to do it like it could be in real.

So one thing what you need to have is Tenant.root in other region.

     let!(:child_tenant) { FactoryGirl.create(:tenant, :parent => Tenant.root_tenant) }
     let(:inactive_region) { FactoryGirl.create(:miq_region) }
     let(:tenant_root_in_inactive_region) do
      root_in_inactive_region = Tenant.root_tenant.dup
      root_in_inactive_region.id = Tenant.id_in_region(Tenant.count + 1_000_000, inactive_region.region) # you can create a method (DRY)
     root_in_inactive_region.save
     root_in_inactive_region
    end


     let!(:child_tenant_out_of_region) { FactoryGirl.create(:tenant, :parent => tenant_root_in_inactive_region, :id => Tenant.id_in_region(Tenant.count + 1_000_000, inactive_region.region)) }

Copy link
Contributor Author

@ZitaNemeckova ZitaNemeckova Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you didn't try that out or I'm missing something :) It's impossible to create second root Tenant in specs. It fails at Validation failed: Tenant: Parent required. I'll use a tenant that's in different region but has a parent from active region. Spec checks that count is correct not their relationship.

End removing the tree code because parent and child tenant have to be in the same region as you said earlier :)

Is that ok with you? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you are right. It about that validator use current region. I think we can skip validation with
root_in_inactive_region.save!(:validate => false) in this case and you can leave parent as nil.

thanks!

@lpichler
Copy link
Contributor

lpichler commented Oct 29, 2018

@lpichler Changed it as you suggested so Tenant is in a MiqRegion that actually exists and not some random "of by three" non-existent one :) Is it ok with you now?

Much better and I gave you other suggestions :)

@ZitaNemeckova ZitaNemeckova force-pushed the tenants_in_my_region branch 2 times, most recently from 89a5046 to 1cb0c58 Compare October 30, 2018 08:57
end

it 'counts only Tenants in active region' do
MiqRegion.seed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put this to the before block

@ZitaNemeckova ZitaNemeckova force-pushed the tenants_in_my_region branch 2 times, most recently from b68ed5b to 5201bc8 Compare October 30, 2018 10:17
@ZitaNemeckova ZitaNemeckova changed the title Filter tenants in Access Control by current region Filter tenants and groups in Access Control by current region Oct 30, 2018
@ZitaNemeckova ZitaNemeckova force-pushed the tenants_in_my_region branch 2 times, most recently from 759e1bf to 6893b69 Compare October 30, 2018 13:43
@miq-bot
Copy link
Member

miq-bot commented Oct 30, 2018

Checked commit ZitaNemeckova@6893b69 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@ZitaNemeckova ZitaNemeckova force-pushed the tenants_in_my_region branch 2 times, most recently from 7ce0a85 to 57c4300 Compare October 31, 2018 10:46
@ZitaNemeckova
Copy link
Contributor Author

@miq-bot remove_label hammer/no
@miq-bot add_label hammer/yes

@mzazrivec mzazrivec self-assigned this Nov 1, 2018
@mzazrivec mzazrivec added this to the Sprint 98 Ending Nov 5, 2018 milestone Nov 1, 2018
@mzazrivec mzazrivec merged commit 79ac457 into ManageIQ:master Nov 1, 2018
simaishi pushed a commit that referenced this pull request Nov 1, 2018
Filter tenants and groups in Access Control by current region

(cherry picked from commit 79ac457)
@simaishi
Copy link
Contributor

simaishi commented Nov 1, 2018

Hammer backport details:

$ git log -1
commit 056aac1f922ee57edb9abfb64f86250882e367c1
Author: Milan Zázrivec <[email protected]>
Date:   Thu Nov 1 11:05:12 2018 +0100

    Merge pull request #4831 from ZitaNemeckova/tenants_in_my_region
    
    Filter tenants and groups in Access Control by current region
    
    (cherry picked from commit 79ac45765a1da8f54e806ff923f8430a677a9e98)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants