-
Notifications
You must be signed in to change notification settings - Fork 560
Add Developer Agreement API #25418
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
Merged
Merged
Add Developer Agreement API #25418
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| from django.urls import re_path | ||
|
|
||
| from .views import developer_support | ||
| from .views import developer_agreement_api, developer_support | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| re_path(r'support/', developer_support, name='developer-support'), | ||
| re_path(r'agreement/', developer_agreement_api, name='developer-agreement'), | ||
| ] |
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,83 @@ | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from django.conf import settings | ||
|
|
||
| from rest_framework import serializers | ||
| from rest_framework.test import APIRequestFactory | ||
|
|
||
| from olympia import amo | ||
| from olympia.amo.tests import TestCase, user_factory | ||
| from olympia.devhub.serializers import DeveloperAgreementSerializer | ||
| from olympia.zadmin.models import set_config | ||
|
|
||
|
|
||
| class TestDeveloperAgreementSerializer(TestCase): | ||
| def setUp(self): | ||
| self.request = APIRequestFactory().get('/') | ||
| self.request.user = user_factory(display_name=None) | ||
| self.change_date = datetime(2025, 8, 4, 0, 0) | ||
| set_config( | ||
| amo.config_keys.LAST_DEV_AGREEMENT_CHANGE_DATE, | ||
| self.change_date.isoformat(), | ||
| ) | ||
| self.serializer = DeveloperAgreementSerializer( | ||
| context={'request': self.request} | ||
| ) | ||
|
|
||
| def test_validate_last_developer_agreement_change(self): | ||
| # Passes when matches agreement change date. | ||
| assert ( | ||
| self.serializer.validate_last_developer_agreement_change(self.change_date) | ||
| == self.change_date | ||
| ) | ||
|
|
||
| # Errors on mismatch. | ||
| with self.assertRaises(serializers.ValidationError): | ||
| self.serializer.validate_last_developer_agreement_change( | ||
| self.change_date + timedelta(days=1) | ||
| ) | ||
|
|
||
| # When none is configured, uses the fallback. | ||
| set_config(amo.config_keys.LAST_DEV_AGREEMENT_CHANGE_DATE, None) | ||
| assert ( | ||
| self.serializer.validate_last_developer_agreement_change( | ||
| settings.DEV_AGREEMENT_CHANGE_FALLBACK | ||
| ) | ||
| == settings.DEV_AGREEMENT_CHANGE_FALLBACK | ||
| ) | ||
|
|
||
| # Or, if the configured date is in the future, still uses the fallback. | ||
| set_config( | ||
| amo.config_keys.LAST_DEV_AGREEMENT_CHANGE_DATE, | ||
| (datetime.now() + timedelta(days=10)).strftime('%Y-%m-%d %H:%M'), | ||
| ) | ||
| assert ( | ||
| self.serializer.validate_last_developer_agreement_change( | ||
| settings.DEV_AGREEMENT_CHANGE_FALLBACK | ||
| ) | ||
| == settings.DEV_AGREEMENT_CHANGE_FALLBACK | ||
| ) | ||
|
|
||
| def _serializer(self, **data): | ||
| data['last_developer_agreement_change'] = self.change_date.isoformat() | ||
| return DeveloperAgreementSerializer( | ||
| data=data, context={'request': self.request} | ||
| ) | ||
|
|
||
| def test_validate_display_name_required_for_anonymous_user(self): | ||
| assert self.request.user.has_anonymous_display_name | ||
| serializer = self._serializer() | ||
| assert not serializer.is_valid() | ||
| assert serializer.errors['display_name'] == ['display_name is required.'] | ||
|
|
||
| def test_validate_display_name_rejected_when_user_already_has_one(self): | ||
| self.request.user.update(display_name='user') | ||
| serializer = self._serializer(display_name='newuser') | ||
| assert not serializer.is_valid() | ||
| assert serializer.errors['display_name'] == ['User already has display_name.'] | ||
|
|
||
| def test_valid_when_user_already_has_display_name_and_field_omitted(self): | ||
| self.request.user.update(display_name='user') | ||
| serializer = self._serializer() | ||
| assert serializer.is_valid(), serializer.errors | ||
| assert 'display_name' not in serializer.validated_data |
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
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.
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.
I think this feedback is targeted more towards the ticket itself than this work, but this doesn't match what I had in mind (and again, we should have fleshed this out better - one for a team retro imo).
Feel free to turn this into a proper discussion, I might have misunderstood things.
My expectations (these are just examples, I haven't validated these are real);
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.
Right now it (and the other API work I've done so far) are generally exclusively using
SessionIDAuthentication, i.e. 'internal use'. Making it external is mainly adding JWT auth. Is that more in line with what would be needed? In which case I'd need to update those endpoints as well.See: #25374 (comment)
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.
@chrstinalin agree on your other comment about
user_uuidbeing extraneous when it's an authenticated request. But from the original, I don't know / understand why you'd want the userdisplay_name?Regarding internal/external use, I'm basing that requirement on this comment from Mat; mozilla/addons#16377 (comment)
Uh oh!
There was an error while loading. Please reload this page.
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.
display_nameis currently needed when its the first time the user has registered, I ended up modifying the behaviour a bit so that's a bit more clear (there's comments throughout), but you can see it here, for a fresh user:Uh oh!
There was an error while loading. Please reload this page.
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.
Ahh, right. I forgot to mention. For that, I did see that
read_dev_agreementis exposed already through/api/v5/accounts/account/(int:user_id|string:username)/. So it is possible to get that information via JWT without this endpoint.