Skip to content

Commit

Permalink
ref(backup): Remove SanitizeUserImportsMixin (#55875)
Browse files Browse the repository at this point in the history
This was redundant code that basically duplicated the functionality of
the `__relocation_scope__` we set on each model. What the models that
used it really wanted was to be in the global relocation scope, which is
now the case.

Issue: getsentry/team-ospo#181
  • Loading branch information
azaslavsky authored Sep 8, 2023
1 parent c2a8264 commit 7e05c8d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
8 changes: 4 additions & 4 deletions fixtures/backup/model_dependencies/detailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
}
},
"model": "sentry.Authenticator",
"relocation_scope": "User",
"relocation_scope": "Global",
"silos": [
"Control"
]
Expand Down Expand Up @@ -3305,7 +3305,7 @@
}
},
"model": "sentry.UserPermission",
"relocation_scope": "User",
"relocation_scope": "Global",
"silos": [
"Control"
]
Expand Down Expand Up @@ -3338,7 +3338,7 @@
"sentry.UserRole": {
"foreign_keys": {},
"model": "sentry.UserRole",
"relocation_scope": "User",
"relocation_scope": "Global",
"silos": [
"Control"
]
Expand All @@ -3355,7 +3355,7 @@
}
},
"model": "sentry.UserRoleUser",
"relocation_scope": "User",
"relocation_scope": "Global",
"silos": [
"Control"
]
Expand Down
26 changes: 0 additions & 26 deletions src/sentry/backup/mixins.py

This file was deleted.

7 changes: 4 additions & 3 deletions src/sentry/models/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
available_authenticators,
)
from sentry.auth.authenticators.base import EnrollmentStatus
from sentry.backup.mixins import SanitizeUserImportsMixin
from sentry.backup.scopes import RelocationScope
from sentry.db.models import (
BaseManager,
Expand Down Expand Up @@ -140,8 +139,10 @@ def to_python(self, value):


@control_silo_only_model
class Authenticator(SanitizeUserImportsMixin, BaseModel):
__relocation_scope__ = RelocationScope.User
class Authenticator(BaseModel):
# It only makes sense to import/export this data when doing a full global backup/restore, so it
# lives in the `Global` scope, even though it only depends on the `User` model.
__relocation_scope__ = RelocationScope.Global

id = BoundedAutoField(primary_key=True)
user = FlexibleForeignKey("sentry.User", db_index=True)
Expand Down
7 changes: 4 additions & 3 deletions src/sentry/models/userpermission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

from django.db import models

from sentry.backup.mixins import SanitizeUserImportsMixin
from sentry.backup.scopes import RelocationScope
from sentry.db.models import FlexibleForeignKey, Model, control_silo_only_model, sane_repr


@control_silo_only_model
class UserPermission(SanitizeUserImportsMixin, Model):
class UserPermission(Model):
"""
Permissions are applied to administrative users and control explicit scope-like permissions within the API.
Generally speaking, they should only apply to active superuser sessions.
"""

__relocation_scope__ = RelocationScope.User
# It only makes sense to import/export this data when doing a full global backup/restore, so it
# lives in the `Global` scope, even though it only depends on the `User` model.
__relocation_scope__ = RelocationScope.Global

user = FlexibleForeignKey("sentry.User")
# permissions should be in the form of 'service-name.permission-name'
Expand Down
13 changes: 8 additions & 5 deletions src/sentry/models/userrole.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.conf import settings
from django.db import models

from sentry.backup.mixins import SanitizeUserImportsMixin
from sentry.backup.scopes import RelocationScope
from sentry.db.models import ArrayField, DefaultFieldsModel, control_silo_only_model, sane_repr
from sentry.db.models.fields.foreignkey import FlexibleForeignKey
Expand All @@ -12,12 +11,14 @@


@control_silo_only_model
class UserRole(SanitizeUserImportsMixin, DefaultFieldsModel):
class UserRole(DefaultFieldsModel):
"""
Roles are applied to administrative users and apply a set of `UserPermission`.
"""

__relocation_scope__ = RelocationScope.User
# It only makes sense to import/export this data when doing a full global backup/restore, so it
# lives in the `Global` scope, even though it only depends on the `User` model.
__relocation_scope__ = RelocationScope.Global

name = models.CharField(max_length=32, unique=True)
permissions = ArrayField()
Expand All @@ -42,8 +43,10 @@ def permissions_for_user(cls, user_id: int) -> FrozenSet[str]:


@control_silo_only_model
class UserRoleUser(SanitizeUserImportsMixin, DefaultFieldsModel):
__relocation_scope__ = RelocationScope.User
class UserRoleUser(DefaultFieldsModel):
# It only makes sense to import/export this data when doing a full global backup/restore, so it
# lives in the `Global` scope, even though it only depends on the `User` model.
__relocation_scope__ = RelocationScope.Global

user = FlexibleForeignKey("sentry.User")
role = FlexibleForeignKey("sentry.UserRole")
Expand Down

0 comments on commit 7e05c8d

Please sign in to comment.