Skip to content

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

Closed
@jeremystretch

Description

@jeremystretch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: acceptedThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end user

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions