Skip to content

Expose taxon admin_url in API and consume in frontend #1040

@coderabbitai

Description

@coderabbitai

Problem

Currently, the frontend hardcodes the admin URL for taxa with a production domain and path:

get adminUrl(): string {
  return `https://api.antenna.insectai.org/bereich/main/taxon/${this.id}`
}

This causes two issues:

  1. The URL always points to production, even in development and staging environments
  2. The path segment varies by environment, and the frontend doesn't have knowledge of these routing rules

Proposed Solution

Move the admin URL logic to the backend, making it the source of truth:

Backend changes (ami/main/api/serializers.py):

  • Add an admin_url field (or links.admin) to taxon serializers (TaxonSerializer, TaxonListSerializer, TaxonNoParentNestedSerializer)
  • Compute the URL using environment-specific routing rules
  • Example:
class TaxonSerializer(serializers.ModelSerializer):
    admin_url = serializers.SerializerMethodField()
    
    def get_admin_url(self, obj):
        request = self.context.get('request')
        return build_admin_url(request, obj.id)

Frontend changes (ui/src/data-services/models/species.ts):

  • Consume the admin_url field from the API
  • Return undefined if not provided by the backend
  • Example:
get adminUrl(): string | undefined {
  return this._species.admin_url ?? this._species?.links?.admin ?? undefined
}

UI behavior:

  • Admin button only shows when species.adminUrl is truthy and canUpdate is true
  • If backend omits the URL for certain environments or roles, button won't appear

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions