flows: improve strings, ensure default-source-enrollment's first stage has re_evaluate_policies

This commit is contained in:
Jens Langhammer 2020-09-26 01:37:06 +02:00
parent 7d533889bc
commit 5d46c1ea5a
6 changed files with 61 additions and 7 deletions

View File

@ -80,7 +80,9 @@ def create_default_source_enrollment_flow(
) )
binding, _ = FlowStageBinding.objects.using(db_alias).update_or_create( 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( PolicyBinding.objects.using(db_alias).update_or_create(
policy=prompt_policy, target=binding, defaults={"order": 0} policy=prompt_policy, target=binding, defaults={"order": 0}

View File

@ -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),
]

View File

@ -155,7 +155,10 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel):
re_evaluate_policies = models.BooleanField( re_evaluate_policies = models.BooleanField(
default=False, default=False,
help_text=_( 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 return FlowStageBindingSerializer
def __str__(self) -> str: def __str__(self) -> str:
return f"'{self.target}' -> '{self.stage}' # {self.order}" return f"{self.target} #{self.order} -> {self.stage}"
class Meta: class Meta:
ordering = ["order", "target"] ordering = ["target", "order"]
verbose_name = _("Flow Stage Binding") verbose_name = _("Flow Stage Binding")
verbose_name_plural = _("Flow Stage Bindings") verbose_name_plural = _("Flow Stage Bindings")

View File

@ -64,7 +64,7 @@ class PolicyBinding(SerializerModel):
return PolicyBindingSerializer return PolicyBindingSerializer
def __str__(self) -> str: 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: class Meta:

View File

@ -7,7 +7,6 @@ from requests.models import Response
from requests_oauthlib import OAuth1 from requests_oauthlib import OAuth1
from structlog import get_logger from structlog import get_logger
from passbook import __version__
from passbook.sources.oauth.clients.base import BaseOAuthClient from passbook.sources.oauth.clients.base import BaseOAuthClient
from passbook.sources.oauth.exceptions import OAuthSourceException from passbook.sources.oauth.exceptions import OAuthSourceException

View File

@ -8,7 +8,6 @@ from requests.exceptions import RequestException
from requests.models import Response from requests.models import Response
from structlog import get_logger from structlog import get_logger
from passbook import __version__
from passbook.sources.oauth.clients.base import BaseOAuthClient from passbook.sources.oauth.clients.base import BaseOAuthClient
LOGGER = get_logger() LOGGER = get_logger()