flows: allow uploading of custom flow backgrounds, update default flow background

This commit is contained in:
Jens Langhammer 2020-12-02 14:24:24 +01:00
parent 821458373d
commit cc5a0c23aa
12 changed files with 97 additions and 25 deletions

View File

@ -1,6 +0,0 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88

View File

@ -25,6 +25,7 @@ class FlowSerializer(ModelSerializer):
"slug",
"title",
"designation",
"background",
"stages",
"policies",
"cache_count",

View File

@ -21,20 +21,12 @@ class FlowForm(forms.ModelForm):
"title",
"slug",
"designation",
"background",
]
help_texts = {
"title": _("Shown as the Title in Flow pages."),
"slug": _("Visible in the URL."),
"designation": _(
(
"Decides what this Flow is used for. For example, the Authentication flow "
"is redirect to when an un-authenticated user visits passbook."
)
),
}
widgets = {
"name": forms.TextInput(),
"title": forms.TextInput(),
"background": forms.FileInput(),
}

View File

@ -0,0 +1,50 @@
# Generated by Django 3.1.3 on 2020-12-02 13:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("passbook_flows", "0015_flowstagebinding_evaluate_on_plan"),
]
operations = [
migrations.AddField(
model_name="flow",
name="background",
field=models.FileField(
blank=True,
default="../static/dist/assets/images/flow_background.jpg",
help_text="Background shown during execution",
upload_to="flow-backgrounds/",
),
),
migrations.AlterField(
model_name="flow",
name="designation",
field=models.CharField(
choices=[
("authentication", "Authentication"),
("authorization", "Authorization"),
("invalidation", "Invalidation"),
("enrollment", "Enrollment"),
("unenrollment", "Unrenollment"),
("recovery", "Recovery"),
("stage_configuration", "Stage Configuration"),
],
help_text="Decides what this Flow is used for. For example, the Authentication flow is redirect to when an un-authenticated user visits passbook.",
max_length=100,
),
),
migrations.AlterField(
model_name="flow",
name="slug",
field=models.SlugField(help_text="Visible in the URL.", unique=True),
),
migrations.AlterField(
model_name="flow",
name="title",
field=models.TextField(help_text="Shown as the Title in Flow pages."),
),
]

View File

@ -92,11 +92,27 @@ class Flow(SerializerModel, PolicyBindingModel):
flow_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
name = models.TextField()
slug = models.SlugField(unique=True)
slug = models.SlugField(unique=True, help_text=_("Visible in the URL."))
title = models.TextField()
title = models.TextField(help_text=_("Shown as the Title in Flow pages."))
designation = models.CharField(max_length=100, choices=FlowDesignation.choices)
designation = models.CharField(
max_length=100,
choices=FlowDesignation.choices,
help_text=_(
(
"Decides what this Flow is used for. For example, the Authentication flow "
"is redirect to when an un-authenticated user visits passbook."
)
),
)
background = models.FileField(
upload_to="flow-backgrounds/",
default="../static/dist/assets/images/flow_background.jpg",
blank=True,
help_text=_("Background shown during execution"),
)
stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True)

View File

@ -17,6 +17,10 @@
.pb-hidden {
display: none
}
.pf-c-background-image::before {
background-image: url("{{ background_url }}");
background-position: center;
}
</style>
{% endblock %}

View File

@ -11,7 +11,7 @@ from passbook.lib.sentry import SentryIgnoredException
def get_attrs(obj: SerializerModel) -> Dict[str, Any]:
"""Get object's attributes via their serializer, and covert it to a normal dict"""
data = dict(obj.serializer(obj).data)
to_remove = ("policies", "stages", "pk")
to_remove = ("policies", "stages", "pk", "background")
for to_remove_name in to_remove:
if to_remove_name in data:
data.pop(to_remove_name)

View File

@ -235,6 +235,8 @@ class FlowExecutorShellView(TemplateView):
template_name = "flows/shell.html"
def get_context_data(self, **kwargs) -> Dict[str, Any]:
flow: Flow = get_object_or_404(Flow, slug=self.kwargs.get("flow_slug"))
kwargs["background_url"] = flow.background.url
kwargs["exec_url"] = reverse("passbook_flows:flow-executor", kwargs=self.kwargs)
self.request.session[SESSION_KEY_GET] = self.request.GET
return kwargs

View File

@ -1,3 +1,11 @@
[tool.black]
target-version = ['py38']
exclude = 'node_modules'
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
src_paths = ["passbook", "tests", "lifecycle"]

View File

@ -6811,6 +6811,7 @@ definitions:
minLength: 1
slug:
title: Slug
description: Visible in the URL.
type: string
format: slug
pattern: ^[-a-zA-Z0-9_]+$
@ -6818,10 +6819,13 @@ definitions:
minLength: 1
title:
title: Title
description: Shown as the Title in Flow pages.
type: string
minLength: 1
designation:
title: Designation
description: Decides what this Flow is used for. For example, the Authentication
flow is redirect to when an un-authenticated user visits passbook.
type: string
enum:
- authentication
@ -6831,6 +6835,12 @@ definitions:
- unenrollment
- recovery
- stage_configuration
background:
title: Background
description: Background shown during execution
type: string
readOnly: true
format: uri
stages:
type: array
items:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 670 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -33,11 +33,6 @@ html {
margin-right: 0.5em;
}
.pf-c-background-image::before {
background-image: url("assets/images/flow_background.jpg");
background-position: center;
}
/* Fix patternfly sidebar and header with open Modal */
.pf-c-page__sidebar {
z-index: 0;