Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Giger
funkwhale
Commits
581c531f
Verified
Commit
581c531f
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
See #170: proper error handling for username uniqueness in channels
parent
a3505d20
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/audio/serializers.py
+9
-0
9 additions, 0 deletions
api/funkwhale_api/audio/serializers.py
api/tests/audio/test_serializers.py
+17
-1
17 additions, 1 deletion
api/tests/audio/test_serializers.py
with
26 additions
and
1 deletion
api/funkwhale_api/audio/serializers.py
+
9
−
0
View file @
581c531f
...
...
@@ -6,6 +6,7 @@ from funkwhale_api.common import serializers as common_serializers
from
funkwhale_api.common
import
utils
as
common_utils
from
funkwhale_api.common
import
locales
from
funkwhale_api.common
import
preferences
from
funkwhale_api.federation
import
models
as
federation_models
from
funkwhale_api.federation
import
serializers
as
federation_serializers
from
funkwhale_api.federation
import
utils
as
federation_utils
from
funkwhale_api.music
import
models
as
music_models
...
...
@@ -74,6 +75,14 @@ class ChannelCreateSerializer(serializers.Serializer):
validated_data
[
"
metadata
"
]
=
metadata
return
validated_data
def
validate_username
(
self
,
value
):
matching
=
federation_models
.
Actor
.
objects
.
local
().
filter
(
preferred_username__iexact
=
value
)
if
matching
.
exists
():
raise
serializers
.
ValidationError
(
"
This username is already taken
"
)
return
value
@transaction.atomic
def
create
(
self
,
validated_data
):
from
.
import
views
...
...
This diff is collapsed.
Click to expand it.
api/tests/audio/test_serializers.py
+
17
−
1
View file @
581c531f
...
...
@@ -56,7 +56,6 @@ def test_channel_serializer_create_honor_max_channels_setting(factories, prefere
attributed_to
=
factories
[
"
federation.Actor
"
](
local
=
True
)
factories
[
"
audio.Channel
"
](
attributed_to
=
attributed_to
)
data
=
{
# TODO: cover
"
name
"
:
"
My channel
"
,
"
username
"
:
"
mychannel
"
,
"
description
"
:
{
"
text
"
:
"
This is my channel
"
,
"
content_type
"
:
"
text/markdown
"
},
...
...
@@ -71,6 +70,23 @@ def test_channel_serializer_create_honor_max_channels_setting(factories, prefere
assert
serializer
.
is_valid
(
raise_exception
=
True
)
def
test_channel_serializer_create_validates_username
(
factories
):
attributed_to
=
factories
[
"
federation.Actor
"
](
local
=
True
)
data
=
{
"
name
"
:
"
My channel
"
,
"
username
"
:
attributed_to
.
preferred_username
.
upper
(),
"
description
"
:
{
"
text
"
:
"
This is my channel
"
,
"
content_type
"
:
"
text/markdown
"
},
"
tags
"
:
[
"
hello
"
,
"
world
"
],
"
content_category
"
:
"
other
"
,
}
serializer
=
serializers
.
ChannelCreateSerializer
(
data
=
data
,
context
=
{
"
actor
"
:
attributed_to
}
)
with
pytest
.
raises
(
serializers
.
serializers
.
ValidationError
,
match
=
r
"
.*username.*
"
):
assert
serializer
.
is_valid
(
raise_exception
=
True
)
def
test_channel_serializer_create_podcast
(
factories
):
attributed_to
=
factories
[
"
federation.Actor
"
](
local
=
True
)
...
...
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