From 62ee5db752ced4d730f9ed84341c9ec3cd59c2be Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 28 Nov 2018 14:01:46 +0100 Subject: [PATCH] core: Remove AppTask Inheritance from Models --- passbook/core/models.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/passbook/core/models.py b/passbook/core/models.py index 964fe803d..67e4ff768 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -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)