Skip to content

Commit

Permalink
Merge pull request #74 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v0.4.0 - #minor
  • Loading branch information
msom authored Feb 28, 2025
2 parents e7ca36f + cfab2fe commit fbf2c57
Show file tree
Hide file tree
Showing 38 changed files with 1,511 additions and 1,226 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
django = "~=5.0.10"
django = "~=5.0.11"
django-ninja = "~=1.1"
psycopg2-binary = "~=2.9.5"
django-environ = "~=0.11"
Expand Down
986 changes: 468 additions & 518 deletions Pipfile.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
| develop | ![Build Status](https://codebuild.eu-central-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiZk43RFNPWm5aNldBYmE3NU95MkFWNVg0aG5oMk1VRlhVcHNmdEVGOGFwc05zRW1lVG4zaU40dnBtSUFsd2dxd0tESlNYN1VkSS9pbkpFWDJ1ajQ0dkhrPSIsIml2UGFyYW1ldGVyU3BlYyI6IktHVHNJL21aN0NKKzg0V2YiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=develop) |
| master | ![Build Status](https://codebuild.eu-central-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiZk43RFNPWm5aNldBYmE3NU95MkFWNVg0aG5oMk1VRlhVcHNmdEVGOGFwc05zRW1lVG4zaU40dnBtSUFsd2dxd0tESlNYN1VkSS9pbkpFWDJ1ajQ0dkhrPSIsIml2UGFyYW1ldGVyU3BlYyI6IktHVHNJL21aN0NKKzg0V2YiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master) |


## Table of Content

- [Table of Content](#table-of-content)
- [Summary of the project](#summary-of-the-project)
- [Local development](#local-development)
- [Dependencies](#dependencies)
- [Setup](#setup)
- [Cognito](#cognito)
- [Local Cognito](#local-cognito)
- [Importing Data from the BOD](#importing-data-from-the-bod)
- [Local Development](#local-development-1)
- [Running tests in parallel](#running-tests-in-parallel)
- [vs code Integration](#vs-code-integration)
- [Debug from vs code](#debug-from-vs-code)
- [Run tests from within vs code](#run-tests-from-within-vs-code)
Expand Down Expand Up @@ -89,7 +92,7 @@ You can import a BOD dump and migrate its data:
```bash
make setup-bod
make import-bod file=dump.sql
app/manage.py bod_migrate
app/manage.py bod_sync
```

To generate more BOD models, run:
Expand Down
2 changes: 1 addition & 1 deletion app/access/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class UserAdmin(admin.ModelAdmin): # type:ignore[type-arg]
'''Admin View for User'''

list_display = ('user_id', 'username', 'deleted_at', 'provider')
list_display = ('user_id', 'username', 'last_name', 'first_name', 'deleted_at', 'provider')
list_filter = ('deleted_at', ('provider', admin.RelatedOnlyFieldListFilter))
actions = ('disable',)

Expand Down
15 changes: 10 additions & 5 deletions app/access/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def user_to_response(model: User) -> UserSchema:
first_name=model.first_name,
last_name=model.last_name,
email=model.email,
provider_id=model.provider.id,
provider_id=model.provider.provider_id,
)
return response

Expand Down Expand Up @@ -73,7 +73,7 @@ def create(request: HttpRequest, user_in: UserSchema) -> UserSchema:
- 500 (Internal Server Error) if there is inconsistency with cognito
- 503 (Service Unavailable) if cognito cannot be reached
"""
provider = get_object_or_404(Provider, id=user_in.provider_id)
provider = get_object_or_404(Provider, provider_id=user_in.provider_id)

user_out = User.objects.create(
username=user_in.username,
Expand Down Expand Up @@ -116,10 +116,15 @@ def update_user(
"""
user_object = get_object_or_404(User, username=username)

if not Provider.objects.filter(id=user_in.provider_id).exists():
provider = Provider.objects.filter(provider_id=user_in.provider_id).first()
if not provider:
raise HttpError(HTTPStatus.BAD_REQUEST, "Provider does not exist")

for attr, value in user_in.dict(exclude_unset=True).items():
setattr(user_object, attr, value)
user_object.username = user_in.username
user_object.first_name = user_in.first_name
user_object.last_name = user_in.last_name
user_object.email = user_in.email
user_object.provider_id = provider.id
user_object.save()

return user_to_response(user_object)
22 changes: 22 additions & 0 deletions app/access/migrations/0004_alter_user_username.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.9 on 2025-02-12 14:58

import utils.fields

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('access', '0003_user_user_id'),
]

operations = [
migrations.AlterField(
model_name='user',
name='username',
field=utils.fields.CustomSlugField(
max_length=100, unique=True, verbose_name='User name'
),
),
]
5 changes: 3 additions & 2 deletions app/access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Iterable

from cognito.utils.client import Client
from utils.fields import CustomSlugField
from utils.short_id import generate_short_id

from django.db import models
Expand Down Expand Up @@ -41,9 +42,9 @@ class User(models.Model):
_context = "User model"

def __str__(self) -> str:
return f'{self.first_name} {self.last_name}'
return str(self.username)

username = models.CharField(_(_context, "User name"), unique=True)
username = CustomSlugField(_(_context, "User name"), unique=True, max_length=100)
user_id = models.CharField(_(_context, "User ID"), unique=True, default=generate_short_id)
first_name = models.CharField(_(_context, "First name"))
last_name = models.CharField(_(_context, "Last name"))
Expand Down
2 changes: 1 addition & 1 deletion app/access/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserSchema(Schema):
first_name: str
last_name: str
email: str
provider_id: int
provider_id: str


class UserListSchema(Schema):
Expand Down
Loading

0 comments on commit fbf2c57

Please sign in to comment.