-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: User agreements API for generic agreement records #35895
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
Draft
xitij2000
wants to merge
3
commits into
openedx:master
Choose a base branch
from
open-craft:kshitij/acknowledgements
base: master
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.
+710
−32
Draft
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
25 changes: 25 additions & 0 deletions
25
openedx/core/djangoapps/agreements/migrations/0006_useragreementrecord.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,25 @@ | ||
| # Generated by Django 4.2.16 on 2024-12-06 11:34 | ||
|
|
||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ('agreements', '0005_timestampedmodels'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='UserAgreementRecord', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('agreement_type', models.CharField(max_length=255)), | ||
| ('timestamp', models.DateTimeField(auto_now_add=True)), | ||
| ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| ), | ||
| ] |
63 changes: 63 additions & 0 deletions
63
...e/djangoapps/agreements/migrations/0007_historicaluseragreement_useragreement_and_more.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,63 @@ | ||
| # Generated by Django 5.2.10 on 2026-01-26 10:21 | ||
|
|
||
| import django.db.models.deletion | ||
| import simple_history.models | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('agreements', '0006_useragreementrecord'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='HistoricalUserAgreement', | ||
| fields=[ | ||
| ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), | ||
| ('type', models.CharField(db_index=True, max_length=255)), | ||
| ('name', models.CharField(help_text='Human-readable name for the agreement type. Will be displayed to users in alert to accept the agreement.', max_length=255)), | ||
| ('summary', models.TextField(help_text='Brief summary of the agreement content. Will be displayed to users in alert to accept the agreement.', max_length=1024)), | ||
| ('text', models.TextField(blank=True, help_text='Full text of the agreement. (Required if url is not provided)', null=True)), | ||
| ('url', models.URLField(blank=True, help_text='URL where the full agreement can be accessed. Will be used for "Learn More" link in alert to accept the agreement.', null=True)), | ||
| ('created', models.DateTimeField(blank=True, editable=False)), | ||
| ('updated', models.DateTimeField(help_text='Timestamp of the last update to this agreement. If changed users will be prompted to accept the agreement again.')), | ||
| ('history_id', models.AutoField(primary_key=True, serialize=False)), | ||
| ('history_date', models.DateTimeField()), | ||
| ('history_change_reason', models.CharField(max_length=100, null=True)), | ||
| ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), | ||
| ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| options={ | ||
| 'verbose_name': 'historical user agreement', | ||
| 'verbose_name_plural': 'historical user agreements', | ||
| 'ordering': ('-history_date', '-history_id'), | ||
| 'get_latest_by': ('history_date', 'history_id'), | ||
| }, | ||
| bases=(simple_history.models.HistoricalChanges, models.Model), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='UserAgreement', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('type', models.CharField(max_length=255, unique=True)), | ||
| ('name', models.CharField(help_text='Human-readable name for the agreement type. Will be displayed to users in alert to accept the agreement.', max_length=255)), | ||
| ('summary', models.TextField(help_text='Brief summary of the agreement content. Will be displayed to users in alert to accept the agreement.', max_length=1024)), | ||
| ('text', models.TextField(blank=True, help_text='Full text of the agreement. (Required if url is not provided)', null=True)), | ||
| ('url', models.URLField(blank=True, help_text='URL where the full agreement can be accessed. Will be used for "Learn More" link in alert to accept the agreement.', null=True)), | ||
| ('created', models.DateTimeField(auto_now_add=True)), | ||
| ('updated', models.DateTimeField(help_text='Timestamp of the last update to this agreement. If changed users will be prompted to accept the agreement again.')), | ||
| ], | ||
| options={ | ||
| 'constraints': [models.CheckConstraint(condition=models.Q(('text__isnull', False), ('url__isnull', False), _connector='OR'), name='agreement_has_text_or_url')], | ||
| }, | ||
| ), | ||
| migrations.AddField( | ||
| model_name='useragreementrecord', | ||
| name='agreement', | ||
| field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='records', to='agreements.useragreement'), | ||
| ), | ||
| ] |
38 changes: 38 additions & 0 deletions
38
...angoapps/agreements/migrations/0008_remove_useragreementrecord_agreement_type_and_more.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,38 @@ | ||
| # Generated by Django 5.2.10 on 2026-01-26 10:22 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
|
|
||
| def migrate_agreement_type(apps, schema_editor): | ||
| UserAgreementRecord = apps.get_model('agreements', 'UserAgreementRecord') | ||
| UserAgreement = apps.get_model('agreements', 'UserAgreement') | ||
| for user_agreement_record in UserAgreementRecord.objects.all(): | ||
| user_agreement_record.agreement = UserAgreement.objects.get_or_create(type=user_agreement_record.agreement_type, defaults=dict(text='')) | ||
|
|
||
|
|
||
| def migrate_agreement_type_rev(apps, schema_editor): | ||
| UserAgreementRecord = apps.get_model('agreements', 'UserAgreementRecord') | ||
| for user_agreement_record in UserAgreementRecord.objects.all(): | ||
| user_agreement_record.agreement_type = user_agreement_record.agreement.type | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('agreements', '0007_historicaluseragreement_useragreement_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(migrate_agreement_type, migrate_agreement_type_rev), | ||
| migrations.RemoveField( | ||
| model_name='useragreementrecord', | ||
| name='agreement_type', | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='useragreementrecord', | ||
| name='agreement', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='records', to='agreements.useragreement'), | ||
| ), | ||
| ] |
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 |
|---|---|---|
|
|
@@ -31,3 +31,25 @@ class LTIPIISignatureSerializer(serializers.ModelSerializer): | |
| class Meta: | ||
| model = LTIPIISignature | ||
| fields = ('username', 'course_id', 'lti_tools', 'created_at') | ||
|
|
||
|
|
||
| class UserAgreementSerializer(serializers.Serializer): | ||
| """ | ||
| Serializer for UserAgreement model | ||
| """ | ||
| type = serializers.CharField(read_only=True) | ||
| name = serializers.CharField(read_only=True) | ||
| summary = serializers.CharField(read_only=True) | ||
| has_text = serializers.BooleanField(read_only=True) | ||
| url = serializers.URLField(read_only=True) | ||
| updated = serializers.DateTimeField(read_only=True) | ||
|
|
||
|
|
||
| class UserAgreementRecordSerializer(serializers.Serializer): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xitij2000 any specific reason for not using ModelSerializer? I think it might help here. |
||
| """ | ||
| Serializer for UserAgreementRecord model | ||
| """ | ||
| username = serializers.CharField(read_only=True) | ||
| agreement_type = serializers.CharField(read_only=True) | ||
| accepted_at = serializers.DateTimeField() | ||
| is_current = serializers.BooleanField(read_only=True) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.