-
Notifications
You must be signed in to change notification settings - Fork 16
BF: avoid clobbering of dict(..., **rec) type and always add a record for the author for new dandisets #2377
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
yarikoptic
wants to merge
9
commits into
master
Choose a base branch
from
bf-doi-name
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.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aebb454
BF: avoid clobbering of dict(..., **rec) type and always add a record…
yarikoptic de1218f
Make sure both contributors (creator and added contrib) are in metadata
asmacdo 683fec4
fixup: name format
asmacdo b86f0c2
fixup: linter
asmacdo da7b1bf
commit to bump the tests
asmacdo 745110a
Allow creation of superuser with a name
asmacdo 6c473e0
Add Requires_CLI_PR to test against a specific PR
asmacdo d21e1e2
fixup: parse CLI PR
asmacdo d52b927
fixup precommit
asmacdo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
from composed_configuration._allauth_support.management.commands import createsuperuser | ||
|
@@ -11,8 +12,12 @@ | |
from composed_configuration._allauth_support.createsuperuser import EmailAsUsernameProxyUser | ||
|
||
|
||
def create_usermetadata(instance: EmailAsUsernameProxyUser, *args, **kwargs): | ||
UserMetadata.objects.create(user=instance, status=UserMetadata.Status.APPROVED) | ||
def create_usermetadata(instance: EmailAsUsernameProxyUser, created: bool, **kwargs): # noqa: FBT001 | ||
if created and not hasattr(instance, '_usermetadata_created'): | ||
UserMetadata.objects.get_or_create( | ||
user=instance, defaults={'status': UserMetadata.Status.APPROVED} | ||
) | ||
instance._usermetadata_created = True # noqa: SLF001 | ||
|
||
|
||
class Command(createsuperuser.Command): | ||
|
@@ -25,6 +30,24 @@ def handle(self, *args, **kwargs) -> str | None: | |
# Save the return value of the parent class function so we can return it later | ||
return_value = super().handle(*args, **kwargs) | ||
|
||
# Set first_name and last_name from environment variables if provided | ||
first_name = os.environ.get('DJANGO_SUPERUSER_FIRST_NAME') | ||
last_name = os.environ.get('DJANGO_SUPERUSER_LAST_NAME') | ||
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. see if could pass as CLI options for this management command instead of relying on internally defined env vars here. Then adjust dandi-cli fixture to provide some name. |
||
|
||
if first_name or last_name: | ||
# Find the user that was just created | ||
email = kwargs.get('email') or os.environ.get('DJANGO_SUPERUSER_EMAIL') | ||
if email: | ||
try: | ||
user = createsuperuser.user_model.objects.get(email=email) | ||
if first_name: | ||
user.first_name = first_name | ||
if last_name: | ||
user.last_name = last_name | ||
user.save() | ||
except createsuperuser.user_model.DoesNotExist: | ||
pass | ||
|
||
# Disconnect the signal handler. This isn't strictly necessary, but this avoids any | ||
# unexpected behavior if, for example, someone extends this command and doesn't | ||
# realize there's a signal handler attached dynamically. | ||
|
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 |
---|---|---|
|
@@ -541,13 +541,13 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user): | |
# This contributor is different from the admin_user | ||
'contributor': [ | ||
{ | ||
'name': 'Jane Doe', | ||
'name': 'Doe, Jane', | ||
'email': '[email protected]', | ||
'roleName': ['dcite:ContactPerson'], | ||
'schemaKey': 'Person', | ||
'affiliation': [], | ||
'includeInCitation': True, | ||
} | ||
}, | ||
], | ||
} | ||
|
||
|
@@ -571,7 +571,7 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user): | |
'created': TIMESTAMP_RE, | ||
'modified': TIMESTAMP_RE, | ||
}, | ||
'contact_person': 'Jane Doe', | ||
'contact_person': 'Doe, John', | ||
yarikoptic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'embargo_status': 'OPEN', | ||
'star_count': 0, | ||
'is_starred': False, | ||
|
@@ -603,21 +603,32 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user): | |
'version': 'draft', | ||
'url': url, | ||
'dateCreated': UTC_ISO_TIMESTAMP_RE, | ||
'citation': (f'Jane Doe ({year}) {name} (Version draft) [Data set]. DANDI Archive. {url}'), | ||
'citation': ( | ||
f'Doe, John; Doe, Jane ({year}) {name} ' | ||
f'(Version draft) [Data set]. DANDI Archive. {url}' | ||
), | ||
'@context': f'https://raw.githubusercontent.com/dandi/schema/master/releases/{settings.DANDI_SCHEMA_VERSION}/context.json', | ||
'schemaVersion': settings.DANDI_SCHEMA_VERSION, | ||
'schemaKey': 'Dandiset', | ||
'access': [{'schemaKey': 'AccessRequirements', 'status': 'dandi:OpenAccess'}], | ||
'repository': settings.DANDI_WEB_APP_URL, | ||
'contributor': [ | ||
{ | ||
'name': 'Jane Doe', | ||
'affiliation': [], | ||
'email': '[email protected]', | ||
'includeInCitation': True, | ||
'name': 'Doe, John', | ||
'roleName': ['dcite:ContactPerson'], | ||
'schemaKey': 'Person', | ||
}, | ||
{ | ||
'name': 'Doe, Jane', | ||
'email': '[email protected]', | ||
'roleName': ['dcite:ContactPerson'], | ||
'schemaKey': 'Person', | ||
'affiliation': [], | ||
'includeInCitation': True, | ||
} | ||
}, | ||
], | ||
'assetsSummary': { | ||
'schemaKey': 'AssetsSummary', | ||
|
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.
what is all this and why we need it for this fix testing?
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 opened a PR against dandi-cli, this lets us test against cli PRs
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 can open another PR for this, but since I wanted to use it I figured it would be good to at least test it on this one.