diff --git a/passbook/flows/migrations/0009_source_flows.py b/passbook/flows/migrations/0009_source_flows.py index c713bcfd9..53be52031 100644 --- a/passbook/flows/migrations/0009_source_flows.py +++ b/passbook/flows/migrations/0009_source_flows.py @@ -80,7 +80,9 @@ def create_default_source_enrollment_flow( ) binding, _ = FlowStageBinding.objects.using(db_alias).update_or_create( - target=flow, stage=prompt_stage, defaults={"order": 0} + target=flow, + stage=prompt_stage, + defaults={"order": 0, "re_evaluate_policies": True}, ) PolicyBinding.objects.using(db_alias).update_or_create( policy=prompt_policy, target=binding, defaults={"order": 0} diff --git a/passbook/flows/migrations/0014_auto_20200925_2332.py b/passbook/flows/migrations/0014_auto_20200925_2332.py new file mode 100644 index 000000000..bfe53e102 --- /dev/null +++ b/passbook/flows/migrations/0014_auto_20200925_2332.py @@ -0,0 +1,51 @@ +# Generated by Django 3.1.1 on 2020-09-25 23:32 + +from django.apps.registry import Apps +from django.db import migrations, models +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +# First stage for default-source-enrollment flow (prompt stage) +# needs to have its policy re-evaluated +def update_default_source_enrollment_flow_binding( + apps: Apps, schema_editor: BaseDatabaseSchemaEditor +): + Flow = apps.get_model("passbook_flows", "Flow") + FlowStageBinding = apps.get_model("passbook_flows", "FlowStageBinding") + db_alias = schema_editor.connection.alias + + flows = Flow.objects.using(db_alias).filter(slug="default-source-enrollment") + if not flows.exists(): + return + flow = flows.first() + + binding = FlowStageBinding.objects.get(target=flow, order=0) + binding.re_evaluate_policies = True + binding.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_flows", "0013_auto_20200924_1605"), + ] + + operations = [ + migrations.AlterModelOptions( + name="flowstagebinding", + options={ + "ordering": ["target", "order"], + "verbose_name": "Flow Stage Binding", + "verbose_name_plural": "Flow Stage Bindings", + }, + ), + migrations.AlterField( + model_name="flowstagebinding", + name="re_evaluate_policies", + field=models.BooleanField( + default=False, + help_text="When this option is enabled, the planner will re-evaluate policies bound to this binding.", + ), + ), + migrations.RunPython(update_default_source_enrollment_flow_binding), + ] diff --git a/passbook/flows/models.py b/passbook/flows/models.py index 5bc0858d1..dc152e252 100644 --- a/passbook/flows/models.py +++ b/passbook/flows/models.py @@ -155,7 +155,10 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel): re_evaluate_policies = models.BooleanField( default=False, help_text=_( - "When this option is enabled, the planner will re-evaluate policies bound to this." + ( + "When this option is enabled, the planner will re-evaluate " + "policies bound to this binding." + ) ), ) @@ -170,11 +173,11 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel): return FlowStageBindingSerializer def __str__(self) -> str: - return f"'{self.target}' -> '{self.stage}' # {self.order}" + return f"{self.target} #{self.order} -> {self.stage}" class Meta: - ordering = ["order", "target"] + ordering = ["target", "order"] verbose_name = _("Flow Stage Binding") verbose_name_plural = _("Flow Stage Bindings") diff --git a/passbook/policies/models.py b/passbook/policies/models.py index f3f029777..99eb43495 100644 --- a/passbook/policies/models.py +++ b/passbook/policies/models.py @@ -64,7 +64,7 @@ class PolicyBinding(SerializerModel): return PolicyBindingSerializer def __str__(self) -> str: - return f"PolicyBinding policy={self.policy} target={self.target} order={self.order}" + return f"Policy Binding {self.target} #{self.order} {self.policy}" class Meta: diff --git a/passbook/sources/oauth/clients/oauth1.py b/passbook/sources/oauth/clients/oauth1.py index cb4387548..42d34d116 100644 --- a/passbook/sources/oauth/clients/oauth1.py +++ b/passbook/sources/oauth/clients/oauth1.py @@ -7,7 +7,6 @@ from requests.models import Response from requests_oauthlib import OAuth1 from structlog import get_logger -from passbook import __version__ from passbook.sources.oauth.clients.base import BaseOAuthClient from passbook.sources.oauth.exceptions import OAuthSourceException diff --git a/passbook/sources/oauth/clients/oauth2.py b/passbook/sources/oauth/clients/oauth2.py index dbf220033..a60e81a10 100644 --- a/passbook/sources/oauth/clients/oauth2.py +++ b/passbook/sources/oauth/clients/oauth2.py @@ -8,7 +8,6 @@ from requests.exceptions import RequestException from requests.models import Response from structlog import get_logger -from passbook import __version__ from passbook.sources.oauth.clients.base import BaseOAuthClient LOGGER = get_logger()