Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
9c971b14
Commit
9c971b14
authored
3 months ago
by
Erwan Rouchet
Committed by
Bastien Abadie
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Support multiline strings in user configurations
parent
9eba7b3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2496
Support multiline strings in user configurations
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/serializers/workers.py
+13
-6
13 additions, 6 deletions
arkindex/process/serializers/workers.py
arkindex/process/tests/worker_versions/test_create.py
+189
-481
189 additions, 481 deletions
arkindex/process/tests/worker_versions/test_create.py
with
202 additions
and
487 deletions
arkindex/process/serializers/workers.py
+
13
−
6
View file @
9c971b14
...
...
@@ -169,11 +169,12 @@ class UserConfigurationFieldSerializer(serializers.Serializer):
subtype
=
EnumField
(
UserConfigurationFieldType
,
required
=
False
)
required
=
serializers
.
BooleanField
(
default
=
False
)
choices
=
serializers
.
ListField
(
required
=
False
,
allow_empty
=
False
,
allow_null
=
True
)
multiline
=
serializers
.
BooleanField
(
required
=
False
)
def
to_internal_value
(
self
,
data
):
errors
=
defaultdict
(
list
)
allowed_fields
=
[
"
title
"
,
"
type
"
,
"
required
"
,
"
default
"
,
"
choices
"
,
"
subtype
"
]
allowed_fields
=
(
"
title
"
,
"
type
"
,
"
required
"
,
"
default
"
,
"
choices
"
,
"
subtype
"
,
"
multiline
"
)
if
not
isinstance
(
data
,
dict
):
errors
[
"
__all__
"
]
=
[
f
"
User configuration field definitions should be of type dict, not
{
type
(
data
).
__name__
}
.
"
]
...
...
@@ -182,7 +183,7 @@ class UserConfigurationFieldSerializer(serializers.Serializer):
for
field
in
data
:
if
field
not
in
allowed_fields
:
errors
[
field
].
append
(
"
Configurable properties can only be defined using the following keys:
title, type, required, default, subtype, choices
.
"
f
"
Configurable properties can only be defined using the following keys:
{
'
,
'
.
join
(
allowed_fields
)
}
.
"
)
default_value
=
data
.
get
(
"
default
"
)
...
...
@@ -194,12 +195,14 @@ class UserConfigurationFieldSerializer(serializers.Serializer):
if
field_type
==
UserConfigurationFieldType
.
List
and
not
subtype
:
errors
[
"
subtype
"
].
append
(
'
The
"
subtype
"
field must be set for
"
list
"
type properties.
'
)
# Handle subtypes
if
subtype
is
not
None
:
if
field_type
!=
UserConfigurationFieldType
.
List
:
errors
[
"
subtype
"
].
append
(
'
The
"
subtype
"
field can only be set for a
"
list
"
type property.
'
)
if
subtype
not
in
[
UserConfigurationFieldType
.
Int
,
UserConfigurationFieldType
.
Float
,
UserConfigurationFieldType
.
String
,
UserConfigurationFieldType
.
Boolean
]:
errors
[
"
subtype
"
].
append
(
"
Subtype can only be int, float, bool or string.
"
)
# Handle enums
if
choices
is
not
None
:
if
field_type
!=
UserConfigurationFieldType
.
Enum
:
...
...
@@ -207,6 +210,11 @@ class UserConfigurationFieldSerializer(serializers.Serializer):
# If the configuration parameter is of enum type, an eventual default value won't match the field type
if
default_value
and
default_value
not
in
choices
:
errors
[
"
default
"
].
append
(
f
"
{
default_value
}
is not an available choice.
"
)
# Only allow the multiline property on string fields
if
"
multiline
"
in
data
and
field_type
!=
UserConfigurationFieldType
.
String
:
errors
[
"
multiline
"
].
append
(
'
The
"
multiline
"
field can only be set for a
"
string
"
type property.
'
)
# Handle everything else
if
default_value
is
not
None
and
field_type
!=
UserConfigurationFieldType
.
Enum
:
try
:
...
...
@@ -278,17 +286,16 @@ class WorkerVersionSerializer(serializers.ModelSerializer):
return
tag
def
validate_configuration
(
self
,
configuration
):
errors
=
defaultdict
(
list
)
user_configuration
=
configuration
.
get
(
"
user_configuration
"
)
if
not
user_configuration
:
return
configuration
field
=
serializers
.
DictField
(
child
=
UserConfigurationFieldSerializer
())
try
:
field
.
to_internal_value
(
user_configuration
)
except
ValidationError
as
e
:
errors
[
"
user_configuration
"
].
append
(
e
.
detail
)
if
errors
:
raise
ValidationError
(
errors
)
raise
ValidationError
({
"
user_configuration
"
:
e
.
detail
})
return
configuration
def
validate
(
self
,
data
):
...
...
This diff is collapsed.
Click to expand it.
arkindex/process/tests/worker_versions/test_create.py
+
189
−
481
View file @
9c971b14
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment