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

Flip the many-to-many relationships for users & groups to object permissions #15464

Closed
jeremystretch opened this issue Mar 18, 2024 · 0 comments
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Milestone

Comments

@jeremystretch
Copy link
Member

Proposed Changes

There are currently many-to-many relationships from the ObjectPermission model to the User and Group models within the users app. These are both defined on the ObjectPermission model:

class ObjectPermission(models.Model):
    groups = models.ManyToManyField(
        to='users.Group',
        blank=True,
        related_name='object_permissions'
    )
    users = models.ManyToManyField(
        to=get_user_model(),
        blank=True,
        related_name='object_permissions'
    )

This proposal entails moving the primary M2M field definitions from ObjectPermission to the User and Group models, as such:

class Group(models.Model):
    object_permissions = models.ManyToManyField(
        to='users.ObjectPermission',
        blank=True,
        related_name='groups'
    )

class User(models.Model):
    object_permissions = models.ManyToManyField(
        to='users.ObjectPermission',
        blank=True,
        related_name='users'
    )

This is essentially a cosmetic change, as the related field names for all three models will remain the same. However, a migration will be required to effect the swap and renamed the intermediary tables accordingly. There may also be some side effects of the reversal that need to be handled; testing will be needed to identify them. (In the event any serious blockers arise, this initiative should probably be punted.)

Justification

Moving these relationships to the User & Group models feels more natural and less surprising than the current arrangement, which exists only because NetBox did not employ custom user or group models prior to v4.0.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user labels Mar 18, 2024
@jeremystretch jeremystretch added this to the v4.0 milestone Mar 18, 2024
jeremystretch added a commit that referenced this issue Mar 29, 2024
…5554)

* Move user & group M2M assignments for ObjectPermission

* Restore users & groups fields on ObjectPermission serializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

No branches or pull requests

1 participant