Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Openlobby Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
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
TO
openlobby
Openlobby Server
Commits
2c10c1c5
Commit
2c10c1c5
authored
7 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
Fix updating of name collision id on every save of existing user.
parent
057bdd20
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
openlobby/core/models.py
+3
-2
3 additions, 2 deletions
openlobby/core/models.py
tests/test_models.py
+11
-0
11 additions, 0 deletions
tests/test_models.py
with
14 additions
and
2 deletions
openlobby/core/models.py
+
3
−
2
View file @
2c10c1c5
...
@@ -18,9 +18,10 @@ class User(AbstractUser):
...
@@ -18,9 +18,10 @@ class User(AbstractUser):
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
# deal with first name and last name collisions
# deal with first name and last name collisions
collisions
=
User
.
objects
.
filter
(
first_name
=
self
.
first_name
,
last_name
=
self
.
last_name
)
\
collisions
=
User
.
objects
.
filter
(
first_name
=
self
.
first_name
,
last_name
=
self
.
last_name
)
\
.
order_by
(
'
-name_collision_id
'
)
[:
1
]
.
order_by
(
'
-name_collision_id
'
)
if
len
(
collisions
)
>
0
:
if
len
(
collisions
)
>
0
and
self
not
in
collisions
:
self
.
name_collision_id
=
collisions
[
0
].
name_collision_id
+
1
self
.
name_collision_id
=
collisions
[
0
].
name_collision_id
+
1
# TODO when we allow name change, it should also reset name_collision_id
super
().
save
(
*
args
,
**
kwargs
)
super
().
save
(
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_models.py
+
11
−
0
View file @
2c10c1c5
...
@@ -90,3 +90,14 @@ def test_user__name_collision():
...
@@ -90,3 +90,14 @@ def test_user__name_collision():
assert
u1
.
name_collision_id
==
0
assert
u1
.
name_collision_id
==
0
assert
u2
.
name_collision_id
==
1
assert
u2
.
name_collision_id
==
1
assert
u3
.
name_collision_id
==
2
assert
u3
.
name_collision_id
==
2
def
test_user__name_collision_is_not_updated_for_existing_user
():
u1
=
User
.
objects
.
create
(
username
=
'
a
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Reynolds
'
)
u2
=
User
.
objects
.
create
(
username
=
'
b
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Reynolds
'
)
assert
u1
.
name_collision_id
==
0
assert
u2
.
name_collision_id
==
1
u1
.
save
()
u2
.
save
()
assert
u1
.
name_collision_id
==
0
assert
u2
.
name_collision_id
==
1
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