Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .github/workflows/cli-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,43 @@ jobs:
if: matrix.dandi-version == 'release'
run: pip install "dandi[test]"

- name: Install dev dandi
if: matrix.dandi-version == 'master'
run: pip install "dandi[test] @ git+https://github.com/dandi/dandi-cli"
- name: Extract CLI PR reference from description
Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member

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.

if: matrix.dandi-version == 'master' && github.event_name == 'pull_request'
id: cli-pr
run: |
if echo "${{ github.event.pull_request.body }}" | grep -i "Requires_CLI_PR:"; then
CLI_PR_URL=$(echo "${{ github.event.pull_request.body }}" | grep -i "Requires_CLI_PR:" | sed 's/.*Requires_CLI_PR:[[:space:]]*//' | head -1 | tr -d '\r\n')
echo "CLI PR URL found: $CLI_PR_URL"
# Extract PR number from URL (e.g., https://github.com/dandi/dandi-cli/pull/123)
CLI_PR_NUM=$(echo "$CLI_PR_URL" | grep -o '[0-9]\+' | tail -1)
echo "CLI PR number: $CLI_PR_NUM"
echo "cli_pr_num=$CLI_PR_NUM" >> $GITHUB_OUTPUT
else
echo "No CLI PR reference found in description"
echo "cli_pr_num=" >> $GITHUB_OUTPUT
fi

- name: Get CLI PR branch name
if: matrix.dandi-version == 'master' && steps.cli-pr.outputs.cli_pr_num != ''
id: cli-branch
run: |
CLI_PR_NUM="${{ steps.cli-pr.outputs.cli_pr_num }}"
echo "Getting branch name for CLI PR #$CLI_PR_NUM"
BRANCH_NAME=$(curl -s "https://api.github.com/repos/dandi/dandi-cli/pulls/$CLI_PR_NUM" | jq -r '.head.ref')
echo "Branch name: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT

- name: Install dev dandi from specific PR branch
if: matrix.dandi-version == 'master' && steps.cli-branch.outputs.branch_name != '' && steps.cli-branch.outputs.branch_name != 'null'
run: |
echo "Installing dandi from PR branch: ${{ steps.cli-branch.outputs.branch_name }}"
pip install "dandi[test] @ git+https://github.com/dandi/dandi-cli@${{ steps.cli-branch.outputs.branch_name }}"

- name: Install dev dandi from master
if: matrix.dandi-version == 'master' && (steps.cli-branch.outputs.branch_name == '' || steps.cli-branch.outputs.branch_name == 'null')
run: |
echo "Installing dandi from master branch"
pip install "dandi[test] @ git+https://github.com/dandi/dandi-cli"

- name: Run dandi-api tests in dandi-cli
run: |
Expand Down
27 changes: 25 additions & 2 deletions dandiapi/api/management/commands/createsuperuser.py
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
Expand All @@ -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):
Expand All @@ -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')
Copy link
Member Author

Choose a reason for hiding this comment

The 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.
Expand Down
13 changes: 9 additions & 4 deletions dandiapi/api/services/version/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ def _normalize_version_metadata(
version_metadata = {
'schemaKey': 'Dandiset',
'schemaVersion': settings.DANDI_SCHEMA_VERSION,
'contributor': [
'contributor': [],
**version_metadata,
}
# if function did not receive already a record for that name
# we create one:
if not any(r.get('name') == name for r in version_metadata['contributor']):
version_metadata['contributor'].insert(
0,
{
'name': name,
'email': email,
Expand All @@ -31,9 +38,7 @@ def _normalize_version_metadata(
'affiliation': [],
'includeInCitation': True,
},
],
**version_metadata,
}
)
# Run the version_metadata through the pydantic model to automatically include any boilerplate
# like the access or repository fields
return PydanticDandiset.model_construct(**version_metadata).model_dump(
Expand Down
23 changes: 17 additions & 6 deletions dandiapi/api/tests/test_dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
},
],
}

Expand All @@ -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',
'embargo_status': 'OPEN',
'star_count': 0,
'is_starred': False,
Expand Down Expand Up @@ -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',
Expand Down
Loading