-
Notifications
You must be signed in to change notification settings - Fork 356
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
Conversation
c508f65
to
e88c149
Compare
@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) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 .
There was a problem hiding this comment.
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 👍
e88c149
to
9fa2e98
Compare
@lpichler Changed it as you suggested so |
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) }
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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!
Much better and I gave you other suggestions :) |
89a5046
to
1cb0c58
Compare
end | ||
|
||
it 'counts only Tenants in active region' do | ||
MiqRegion.seed |
There was a problem hiding this comment.
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
b68ed5b
to
5201bc8
Compare
759e1bf
to
6893b69
Compare
Checked commit ZitaNemeckova@6893b69 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
7ce0a85
to
57c4300
Compare
Filter tenants and groups in Access Control by current region (cherry picked from commit 79ac457)
Hammer backport details:
|
Closes #4720
Tenant.count == Tenant.in_my_region.count
setid
of one of tenants to something outside current region(multiple itsid
by 3 or something)In this case
cloudusers
tenant is not inTenant.in_my_region
Before:
After:
@miq-bot add_label bug, hammer/no,