Links: Add endpoint to bulk create entity links#885
Conversation
BigRoy
left a comment
There was a problem hiding this comment.
@martastain I understood you weren't too happy with the bulk entry point to this. If you have better ideas to get the route/API name to align with the rest of the backend API let's do it.
| link_type = link.link_type or link.link | ||
| if link_type is None: | ||
| raise BadRequestException("Link type is not specified") | ||
|
|
||
| if perms is not None: | ||
| if perms.links.enabled and link_type not in perms.links.link_types: | ||
| raise ForbiddenException( | ||
| "You do not have permission to create this link type." | ||
| ) | ||
|
|
||
| if len(link_type.split("|")) != 3: | ||
| raise BadRequestException( | ||
| "Link type must be in the format 'name|input_type|output_type'" | ||
| ) |
There was a problem hiding this comment.
Not too happy myself that it duplicates the link type checks, permission checks and link type format checks compared to the 'create single link'. So may want to generalize that.
May want make a private _validate_link function that is used both here and in the single link create function to ensure logic remains consistent between the two?
| ) from None | ||
|
|
||
| await EventStream.dispatch( | ||
| "links.created", |
There was a problem hiding this comment.
This does introduce a new "bulk" event - is that what we'd want - or would we still want to continue emitting an event per created link?
Description of changes
Links: Add endpoint to bulk add links in one go
Technical details
Implements a bulk endpoint to allow batch creating links in one post request.
Example usage:
Additional context
Please read the code a few times to make sure it doesn't do anything stupid.