-
Notifications
You must be signed in to change notification settings - Fork 5
feat(medcat-demo-web-app): CU-869b855n0 Manual model access #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mart-r
wants to merge
55
commits into
main
Choose a base branch
from
feat/medcat-demo-web-app/CU-869b855n0-manual-model-access
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
955105e
CU-869b855n0: Add models for questionnaire
mart-r 171eeb6
CU-869b855n0: Add endpoints for questionnaire
mart-r 0fc11b5
CU-869b855n0: Use questionnaire endpoints
mart-r 31f4770
CU-869b855n0: Add decorator for requiring valid API key
mart-r 3799409
CU-869b855n0: Add relevant admin bits to API keys and questions
mart-r 0cdc4e8
CU-869b855n0: Add API-key requiring endpoint
mart-r 6310810
Fix typo
mart-r 36c9bcf
Fix another few typos
mart-r 56eacae
CU-869b855n0: Add UI for questionnaire
mart-r b501a3a
CU-869b855n0: Change entry point for questionnaire
mart-r 674e61d
CU-869b855n0: Unify registration of models and their admin stuff
mart-r d7ffe54
CU-869b855n0: Move migrations to startup instead of build time
mart-r 290883a
CU-869b855n0: Collect static at Dockerfile time
mart-r b0eb578
CU-869b855n0: Update migrations
mart-r 7f49695
CU-869b855n0: Update / fix startup commnad
mart-r a0c73e3
CU-869b855n0: Remove collectstatic from CMD since it's done at build …
mart-r d5b59b2
CU-869b855n0: Fix endpoint from questionnaire to submit
mart-r f5199f8
CU-869b855n0: Fix another endpoint typo
mart-r fdf0082
CU-869b855n0: Fix yet another endpoint typo
mart-r 58e2ec0
CU-869b855n0: Fix callback URL
mart-r 2a50482
CU-869b855n0: Update template for better accuracy
mart-r 2f5206f
CU-869b855n0: Fix URL in setup for callback endpoint
mart-r 49bc6c5
CU-869b855n0: Add medvat version to more contexts
mart-r 6a095f4
CU-869b855n0: Add medcat version to more contexts (in questionnaire)
mart-r 4fe7f58
CU-869b855n0: Make number of questions dynamic
mart-r 2b58745
CU-869b855n0: Add base template to quiz
mart-r c685911
CU-869b855n0: Fix URL in template again
mart-r 363f50e
CU-869b855n0: Add base template to cooldown template
mart-r dc0c516
CU-869b855n0: Add base template to error template
mart-r 55b4c11
CU-869b855n0: Some whitespace changes
mart-r 16ebb2b
CU-869b855n0: Fix quiz template
mart-r f9723fc
CU-869b855n0: Fix URL for retry on cooldown
mart-r 20b0ac5
CU-869b855n0: Add link to questionnaire (and UMLS license) to API key…
mart-r 64d6e78
CU-869b855n0: Update template to include details on expiry and attempts
mart-r 71839b2
CU-869b855n0: Fix missing medcat version context
mart-r 568ebb5
CU-869b855n0: Centralise cooldown time
mart-r 25dab53
CU-869b855n0: Fix cooldown (hopefully)
mart-r 726c351
CU-869b855n0: Avoid treating a migration with error in its name as an…
mart-r ccf0f27
CU-869b855n0: Avoid mention of API key to lower confusion
mart-r 76b7e36
CU-869b855n0: Update messaging for no API-key activation
mart-r 976c130
CU-869b855n0: Remove question and attempt models
mart-r ae3b3e7
CU-869b855n0: Remove questionnaire endpoints
mart-r b909540
CU-869b855n0: Fix issue with show lib version
mart-r f470e44
CU-869b855n0: Allow (by default) 14 days for API key cooldown
mart-r 02e49c2
CU-869b855n0: Add permission to manually add API keys
mart-r 0b722bf
CU-869b855n0: Allow changing expiry date of API key
mart-r 6393910
CU-869b855n0: Update manual API callback URL
mart-r fedf1ad
CU-869b855n0: Add API key link
mart-r d309f38
CU-869b855n0: Update admin view with correct URL
mart-r af29da5
CU-869b855n0: Some formatting changes to dockerfile
mart-r 59ffb95
CU-869b855n0: Fix copy link
mart-r 9e6e0d0
CU-869b855n0: Remove mention of questionnaire
mart-r acb81e8
CU-869b855n0: Add default value for expiry of API keys
mart-r ebd4286
CU-869b855n0: Update expiry default with picklable method
mart-r fd20cab
CU-869b855n0: Add migration for default expiry
mart-r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| from functools import wraps | ||
| from django.http import JsonResponse | ||
| from .models import APIKey | ||
|
|
||
|
|
||
| def require_valid_api_key(view_func): | ||
| """ | ||
| Decorator to protect endpoints with API key authentication | ||
|
|
||
| Usage: | ||
| @require_valid_api_key | ||
| def my_protected_view(request): | ||
| # Your view logic | ||
| pass | ||
| """ | ||
| @wraps(view_func) | ||
| def wrapper(request, *args, **kwargs): | ||
| # Check for API key in header or query parameter | ||
| api_key = ( | ||
| request.headers.get('X-API-Key') or | ||
| request.GET.get('api_key') or | ||
| request.POST.get('api_key') | ||
| ) | ||
|
|
||
| if not api_key: | ||
| return JsonResponse({ | ||
| 'error': 'API key required', | ||
| 'message': 'Please provide an API key via X-API-Key header or api_key parameter' | ||
| }, status=401) | ||
|
|
||
| if not APIKey.is_valid(api_key): | ||
| return JsonResponse({ | ||
| 'error': 'Invalid or expired API key', | ||
| 'message': 'Please obtain a valid API key' | ||
| }, status=401) | ||
|
|
||
| # API key is valid, proceed with the view | ||
| return view_func(request, *args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| # Example usage in views.py: | ||
| """ | ||
| from .decorators import require_valid_api_key | ||
|
|
||
| @require_valid_api_key | ||
| def protected_endpoint(request): | ||
| return JsonResponse({ | ||
| 'message': 'You have access to this protected resource!', | ||
| 'data': {'example': 'data'} | ||
| }) | ||
| """ |
34 changes: 34 additions & 0 deletions
34
medcat-demo-app/webapp/demo/migrations/0003_auto_20251120_2221.py
This file contains hidden or 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,34 @@ | ||
| # Generated by Django 3.2.25 on 2025-11-20 22:21 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('demo', '0002_downloader_medcatmodel'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='APIKey', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('key', models.CharField(db_index=True, max_length=64, unique=True)), | ||
| ('identifier', models.CharField(max_length=255)), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('expires_at', models.DateTimeField()), | ||
| ('is_active', models.BooleanField(default=True)), | ||
| ], | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='downloader', | ||
| name='downloaded_file', | ||
| field=models.CharField(max_length=100), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='medcatmodel', | ||
| name='model_description', | ||
| field=models.TextField(max_length=200), | ||
| ), | ||
| ] |
19 changes: 19 additions & 0 deletions
19
medcat-demo-app/webapp/demo/migrations/0004_alter_apikey_expires_at.py
This file contains hidden or 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,19 @@ | ||
| # Generated by Django 3.2.25 on 2025-11-24 16:21 | ||
|
|
||
| import demo.models | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('demo', '0003_auto_20251120_2221'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='apikey', | ||
| name='expires_at', | ||
| field=models.DateTimeField(default=demo.models._default_expiry), | ||
| ), | ||
| ] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-word this to "If you are unable to obtain an API key due to your application for a UMLS license being unanswered"