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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
openlobby
Openlobby Server
Commits
62235959
Commit
62235959
authored
7 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
Add name collision ID to User model.
parent
cd721a50
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
openlobby/core/migrations/0010_user_name_collision_id.py
+18
-0
18 additions, 0 deletions
openlobby/core/migrations/0010_user_name_collision_id.py
openlobby/core/models.py
+9
-0
9 additions, 0 deletions
openlobby/core/models.py
tests/test_models.py
+16
-0
16 additions, 0 deletions
tests/test_models.py
with
43 additions
and
0 deletions
openlobby/core/migrations/0010_user_name_collision_id.py
0 → 100644
+
18
−
0
View file @
62235959
# Generated by Django 2.0.2 on 2018-02-20 20:28
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
core
'
,
'
0009_auto_20180217_1850
'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'
user
'
,
name
=
'
name_collision_id
'
,
field
=
models
.
IntegerField
(
default
=
0
),
),
]
This diff is collapsed.
Click to expand it.
openlobby/core/models.py
+
9
−
0
View file @
62235959
...
@@ -13,6 +13,15 @@ class User(AbstractUser):
...
@@ -13,6 +13,15 @@ class User(AbstractUser):
openid_uid
=
models
.
CharField
(
max_length
=
255
,
null
=
True
)
openid_uid
=
models
.
CharField
(
max_length
=
255
,
null
=
True
)
extra
=
JSONField
(
null
=
True
,
blank
=
True
)
extra
=
JSONField
(
null
=
True
,
blank
=
True
)
is_author
=
models
.
BooleanField
(
default
=
False
)
is_author
=
models
.
BooleanField
(
default
=
False
)
name_collision_id
=
models
.
IntegerField
(
default
=
0
)
def
save
(
self
,
*
args
,
**
kwargs
):
# deal with first name and last name collisions
collisions
=
User
.
objects
.
filter
(
first_name
=
self
.
first_name
,
last_name
=
self
.
last_name
)
\
.
order_by
(
'
-name_collision_id
'
)[:
1
]
if
len
(
collisions
)
>
0
:
self
.
name_collision_id
=
collisions
[
0
].
name_collision_id
+
1
super
().
save
(
*
args
,
**
kwargs
)
class
OpenIdClient
(
models
.
Model
):
class
OpenIdClient
(
models
.
Model
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_models.py
+
16
−
0
View file @
62235959
...
@@ -74,3 +74,19 @@ def test_login_attempt__default_expiration():
...
@@ -74,3 +74,19 @@ def test_login_attempt__default_expiration():
attempt
=
LoginAttempt
.
objects
.
create
(
openid_client
=
client
,
state
=
'
foo
'
,
attempt
=
LoginAttempt
.
objects
.
create
(
openid_client
=
client
,
state
=
'
foo
'
,
app_redirect_uri
=
'
http://openlobby/app
'
)
app_redirect_uri
=
'
http://openlobby/app
'
)
assert
attempt
.
expiration
==
10000
+
settings
.
LOGIN_ATTEMPT_EXPIRATION
assert
attempt
.
expiration
==
10000
+
settings
.
LOGIN_ATTEMPT_EXPIRATION
def
test_user__no_name_collision
():
User
.
objects
.
create
(
username
=
'
a
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Gosling
'
)
User
.
objects
.
create
(
username
=
'
b
'
,
first_name
=
'
Burt
'
,
last_name
=
'
Reynolds
'
)
user
=
User
.
objects
.
create
(
username
=
'
c
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Reynolds
'
)
assert
user
.
name_collision_id
==
0
def
test_user__name_collision
():
u1
=
User
.
objects
.
create
(
username
=
'
a
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Gosling
'
)
u2
=
User
.
objects
.
create
(
username
=
'
b
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Gosling
'
)
u3
=
User
.
objects
.
create
(
username
=
'
c
'
,
first_name
=
'
Ryan
'
,
last_name
=
'
Gosling
'
)
assert
u1
.
name_collision_id
==
0
assert
u2
.
name_collision_id
==
1
assert
u3
.
name_collision_id
==
2
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