core: Remove AppTask Inheritance from Models
This commit is contained in:
parent
bc65fae4b2
commit
62ee5db752
|
@ -8,7 +8,6 @@ from django.db import models
|
|||
from django.utils.translation import gettext as _
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
||||
from passbook.core.celery import CELERY_APP
|
||||
from passbook.lib.models import CreatedUpdatedModel, UUIDModel
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
@ -32,13 +31,6 @@ class Provider(models.Model):
|
|||
return getattr(self, 'name')
|
||||
return super().__str__()
|
||||
|
||||
class TaskModel(CELERY_APP.Task, models.Model):
|
||||
"""Django model which is also a celery task"""
|
||||
|
||||
class Meta:
|
||||
|
||||
abstract = True
|
||||
|
||||
class RuleModel(UUIDModel, CreatedUpdatedModel):
|
||||
"""Base model which can have rules applied to it"""
|
||||
|
||||
|
@ -99,7 +91,7 @@ class UserSourceConnection(CreatedUpdatedModel):
|
|||
unique_together = (('user', 'source'),)
|
||||
|
||||
@reversion.register()
|
||||
class Rule(TaskModel, UUIDModel, CreatedUpdatedModel):
|
||||
class Rule(UUIDModel, CreatedUpdatedModel):
|
||||
"""Rules which specify if a user is authorized to use an Application. Can be overridden by
|
||||
other types to add other fields, more logic, etc."""
|
||||
|
||||
|
@ -122,10 +114,6 @@ class Rule(TaskModel, UUIDModel, CreatedUpdatedModel):
|
|||
return self.name
|
||||
return "%s action %s" % (self.name, self.action)
|
||||
|
||||
def run(self, user_id: int) -> bool:
|
||||
"""Celery wrapper for passes"""
|
||||
return self.passes(User.objects.get(pk=user_id))
|
||||
|
||||
def passes(self, user: User) -> bool:
|
||||
"""Check if user instance passes this rule"""
|
||||
raise NotImplementedError()
|
||||
|
@ -152,7 +140,6 @@ class FieldMatcherRule(Rule):
|
|||
match_action = models.CharField(max_length=50, choices=MATCHES)
|
||||
value = models.TextField()
|
||||
|
||||
name = 'passbook_core.FieldMatcherRule'
|
||||
form = 'passbook.core.forms.rules.FieldMatcherRuleForm'
|
||||
|
||||
def __str__(self):
|
||||
|
@ -214,7 +201,6 @@ class WebhookRule(Rule):
|
|||
result_jsonpath = models.TextField()
|
||||
result_json_value = models.TextField()
|
||||
|
||||
name = 'passbook_core.WebhookRule'
|
||||
form = 'passbook.core.forms.rules.WebhookRuleForm'
|
||||
|
||||
def passes(self, user: User):
|
||||
|
@ -225,7 +211,3 @@ class WebhookRule(Rule):
|
|||
|
||||
verbose_name = _('Webhook Rule')
|
||||
verbose_name_plural = _('Webhook Rules')
|
||||
|
||||
# Register tasks
|
||||
for task_model in Rule.__subclasses__():
|
||||
CELERY_APP.tasks.register(task_model)
|
||||
|
|
Reference in a new issue