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

ObjectPermission Data Migration from Region/Site to Location #3418

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

HanlinMiao
Copy link
Contributor

@HanlinMiao HanlinMiao commented Mar 13, 2023

Closes: #

What's Changed

  1. Add Location/LocationType ContentType to object_types field of existing Region and Site ObjectPermissions
  2. Add migration Test

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@@ -299,6 +299,7 @@ def reassign_model_instances_to_locations(apps, model):
Location = apps.get_model("dcim", "location")
LocationType = apps.get_model("dcim", "locationtype")
location_ct = ContentType.objects.get_for_model(Location)
location_type_ct = ContentType.objects.get_for_model(LocationType)
model_class = apps.get_model("dcim", f"{model}")
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick inc

Suggested change
model_class = apps.get_model("dcim", f"{model}")
model_class = apps.get_model("dcim", model)

region_permissions = self.object_permission.objects.filter(
name__in=["Test Region Permission 1", "Test Region Permission 2"]
)
self.assertEqual(
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this more concise by using assertCountEqual and dropping sorted. Not blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I do want to check the actual content of the many-to-many field just to make sure it is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

assertCountEqual does check that the content of the iterables matches it just ignores the sort order. I don't know why they named it assertCountEqual

@HanlinMiao HanlinMiao merged commit b1f3d64 into next Mar 14, 2023
@HanlinMiao HanlinMiao deleted the hanlin-object-permission branch March 14, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants