-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(models): oauth claims and user flow
- Loading branch information
1 parent
644a623
commit 9222258
Showing
21 changed files
with
270 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .userflow import UserFlowAdmin | ||
|
||
__all__ = ["UserFlowAdmin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import logging | ||
|
||
from django.contrib import admin | ||
|
||
from web.core import models | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@admin.register(models.UserFlow) | ||
class UserFlowAdmin(admin.ModelAdmin): | ||
list_display = ("label", "scopes", "eligibility_claim", "oauth_config") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Generated by Django 5.1.5 on 2025-01-27 23:58 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
("oauth", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UserFlow", | ||
fields=[ | ||
("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
( | ||
"label", | ||
models.CharField( | ||
help_text="A human readable label, used as the display text (user-facing)", max_length=50 | ||
), | ||
), | ||
( | ||
"system_name", | ||
models.SlugField(help_text="Internal system name for this flow, mapped to the root URL.", unique=True), | ||
), | ||
("urlconf_path", models.CharField(help_text="Django app path to the URLconf for this flow.", max_length=100)), | ||
( | ||
"scopes", | ||
models.CharField( | ||
help_text="A space-separated list of identifiers used to specify what information is being requested", | ||
max_length=200, | ||
), | ||
), | ||
( | ||
"eligibility_claim", | ||
models.CharField(help_text="The claim that is used to verify eligibility", max_length=50), | ||
), | ||
( | ||
"extra_claims", | ||
models.CharField( | ||
blank=True, default="", help_text="A space-separated list of any additional claims", max_length=200 | ||
), | ||
), | ||
( | ||
"redirect_failure", | ||
models.CharField( | ||
default="oauth:error", | ||
help_text="A Django route in the form of app:endpoint to redirect to after a successful claims check", | ||
max_length=50, | ||
), | ||
), | ||
( | ||
"redirect_success", | ||
models.CharField( | ||
default="oauth:success", | ||
help_text="A Django route in the form of app:endpoint to redirect to after a successful claims check", | ||
max_length=50, | ||
), | ||
), | ||
( | ||
"scheme_override", | ||
models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="(Optional) the authentication scheme to use. Defaults to that provided by the OAuth config.", # noqa: E501 | ||
max_length=50, | ||
verbose_name="Claims scheme", | ||
), | ||
), | ||
( | ||
"oauth_config", | ||
models.ForeignKey( | ||
help_text="The IdG connection details for this flow.", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="oauth.ClientConfig", | ||
), | ||
), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .userflow import UserFlow | ||
|
||
__all__ = ["UserFlow"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import importlib | ||
from uuid import uuid4 | ||
|
||
from django.db import models | ||
|
||
from web.oauth.models.config import ClientConfig | ||
|
||
|
||
class UserFlow(models.Model): | ||
"""Represents a user journey through the DDRC app.""" | ||
|
||
id = models.UUIDField( | ||
primary_key=True, | ||
default=uuid4, | ||
editable=False, | ||
) | ||
label = models.CharField( | ||
help_text="A human readable label, used as the display text (user-facing)", | ||
max_length=50, | ||
) | ||
system_name = models.SlugField( | ||
help_text="Internal system name for this flow, mapped to the root URL.", | ||
unique=True, | ||
) | ||
urlconf_path = models.CharField( | ||
help_text="Django app path to the URLconf for this flow.", | ||
max_length=100, | ||
) | ||
oauth_config = models.ForeignKey( | ||
ClientConfig, | ||
on_delete=models.PROTECT, | ||
help_text="The IdG connection details for this flow.", | ||
) | ||
scopes = models.CharField( | ||
help_text="A space-separated list of identifiers used to specify what information is being requested", | ||
max_length=200, | ||
) | ||
eligibility_claim = models.CharField( | ||
help_text="The claim that is used to verify eligibility", | ||
max_length=50, | ||
) | ||
extra_claims = models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="A space-separated list of any additional claims", | ||
max_length=200, | ||
) | ||
redirect_failure = models.CharField( | ||
default="oauth:error", | ||
help_text="A Django route in the form of app:endpoint to redirect to after a successful claims check", | ||
max_length=50, | ||
) | ||
redirect_success = models.CharField( | ||
default="oauth:success", | ||
help_text="A Django route in the form of app:endpoint to redirect to after a successful claims check", | ||
max_length=50, | ||
) | ||
scheme_override = models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="(Optional) the authentication scheme to use. Defaults to that provided by the OAuth config.", | ||
max_length=50, | ||
verbose_name="Claims scheme", | ||
) | ||
|
||
@property | ||
def all_claims(self): | ||
return " ".join((self.eligibility_claim, self.extra_claims)) | ||
|
||
@property | ||
def index_url(self): | ||
try: | ||
match = [url for url in self.urlpatterns if url.pattern.regex.match("")] | ||
index = match[0] | ||
return f"{self.urlconf.app_name}:{index.name}" | ||
except Exception: | ||
return None | ||
|
||
@property | ||
def urlconf(self): | ||
try: | ||
return importlib.import_module(self.urlconf_path) | ||
except Exception: | ||
return None | ||
|
||
@property | ||
def urlpatterns(self): | ||
try: | ||
return self.urlconf.urlpatterns | ||
except Exception: | ||
return [] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .config import ClientConfigAdmin | ||
|
||
__all__ = ["ClientConfigAdmin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import logging | ||
|
||
from django.contrib import admin | ||
|
||
from .. import models | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@admin.register(models.ClientConfig) | ||
class ClientConfigAdmin(admin.ModelAdmin): | ||
list_display = ("client_name", "authority", "scheme") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[ | ||
{ | ||
"model": "oauth.oauthclientconfig", | ||
"model": "oauth.clientconfig", | ||
"pk": "6915939f-a852-441e-aec6-9fb225156656", | ||
"fields": { | ||
"client_name": "dev", | ||
"client_id_secret_name": "dev-client-id", | ||
"authority": "https://dev.ca.gov", | ||
"scheme": "dev-ddrc", | ||
"scopes": "attribute:flag" | ||
"authority": "https://dev.cdt.ca.gov", | ||
"scheme": "dev" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .config import OAuthClientConfig | ||
from .config import ClientConfig | ||
from .secret_name_field import SecretNameField | ||
|
||
__all__ = ["OAuthClientConfig", "SecretNameField"] | ||
__all__ = ["ClientConfig", "SecretNameField"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.