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:
- The URL always points to production, even in development and staging environments
- 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
Problem
Currently, the frontend hardcodes the admin URL for taxa with a production domain and path:
This causes two issues:
Proposed Solution
Move the admin URL logic to the backend, making it the source of truth:
Backend changes (ami/main/api/serializers.py):
admin_urlfield (orlinks.admin) to taxon serializers (TaxonSerializer, TaxonListSerializer, TaxonNoParentNestedSerializer)Frontend changes (ui/src/data-services/models/species.ts):
admin_urlfield from the APIundefinedif not provided by the backendUI behavior:
species.adminUrlis truthy andcanUpdateis trueReferences