🌱(demo) create dev users and make them doc accesses

To be able to test with dummy data, we need to create
our dev users from the demo and to give them access to
the docs.
The sub is the unicity of the user for our oidc provider,
so we need to know the sub to be able to create
correctly the user, it is why we set the sub
as the email of the user in the realm.json file.
This commit is contained in:
Anthony LC
2024-07-04 16:40:32 +02:00
committed by Anthony LC
parent 7d3fd25c61
commit be93598b2d
5 changed files with 77 additions and 0 deletions

View File

@@ -8,6 +8,10 @@ and this project adheres to
## [Unreleased] ## [Unreleased]
## Added
- 🤡(demo) generate dummy documents on dev users #120
## [1.0.0] - 2024-07-02 ## [1.0.0] - 2024-07-02
## Added ## Added

View File

@@ -1339,6 +1339,21 @@
"jsonType.label": "String" "jsonType.label": "String"
} }
}, },
{
"id": "qb109597-e31e-46d7-7844-62e5fcf32ac8",
"name": "email sub",
"protocol": "openid-connect",
"protocolMapper": "oidc-usermodel-property-mapper",
"consentRequired": false,
"config": {
"userinfo.token.claim": "true",
"user.attribute": "email",
"id.token.claim": "true",
"access.token.claim": "true",
"claim.name": "sub",
"jsonType.label": "String"
}
},
{ {
"id": "61c135e5-2447-494b-bc70-9612f383be27", "id": "61c135e5-2447-494b-bc70-9612f383be27",
"name": "email verified", "name": "email verified",

View File

@@ -5,3 +5,19 @@ NB_OBJECTS = {
"docs": 50, "docs": 50,
"max_users_per_document": 50, "max_users_per_document": 50,
} }
DEV_USERS = [
{
"username": "impress",
"email": "impress@impress.world",
},
{
"username": "user-e2e-webkit",
"email": "user@webkit.e2e",
},
{
"username": "user-e2e-firefox",
"email": "user@firefox.e2e",
},
{"username": "user-e2e-chromium", "email": "user@chromium.e2e"},
]

View File

@@ -152,6 +152,38 @@ def create_demo(stdout):
) )
queue.flush() queue.flush()
with Timeit(stdout, "Creating development users"):
for dev_user in defaults.DEV_USERS:
queue.push(
models.User(
admin_email=dev_user["email"],
email=dev_user["email"],
sub=dev_user["email"],
password="!",
is_superuser=False,
is_active=True,
is_staff=False,
language=random.choice(settings.LANGUAGES)[0],
)
)
queue.flush()
with Timeit(stdout, "Creating docs accesses on development users"):
for dev_user in defaults.DEV_USERS:
docs_ids = list(models.Document.objects.values_list("id", flat=True))
user_id = models.User.objects.get(email=dev_user["email"]).id
for doc_id in docs_ids:
role = random.choice(models.RoleChoices.choices)
queue.push(
models.DocumentAccess(
document_id=doc_id, user_id=user_id, role=role[0]
)
)
queue.flush()
with Timeit(stdout, "Creating Template"): with Timeit(stdout, "Creating Template"):
with open( with open(
file="demo/data/template/code.txt", mode="r", encoding="utf-8" file="demo/data/template/code.txt", mode="r", encoding="utf-8"

View File

@@ -19,3 +19,13 @@ def test_commands_create_demo():
assert models.User.objects.count() >= 50 assert models.User.objects.count() >= 50
assert models.Document.objects.count() >= 50 assert models.Document.objects.count() >= 50
assert models.DocumentAccess.objects.count() > 50 assert models.DocumentAccess.objects.count() > 50
# assert dev users have doc accesses
user = models.User.objects.get(email="impress@impress.world")
assert models.DocumentAccess.objects.filter(user=user).exists()
user = models.User.objects.get(email="user@webkit.e2e")
assert models.DocumentAccess.objects.filter(user=user).exists()
user = models.User.objects.get(email="user@firefox.e2e")
assert models.DocumentAccess.objects.filter(user=user).exists()
user = models.User.objects.get(email="user@chromium.e2e")
assert models.DocumentAccess.objects.filter(user=user).exists()