Skip to content

Commit

Permalink
annotation_user_id param accepts user login strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jun 20, 2024
1 parent c50cb2a commit 5867814
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/api_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const apiUtil = class apiUtil {
["not_in_project", "not_in_project", Project.findAllByIDElastic],
["members_of_project", "members_of_project", Project.findAllByIDElastic],
["ident_user_id", "ident_users", User.findAllByLoginOrID],
["without_ident_user_id", "without_ident_users", User.findAllByLoginOrID]
["without_ident_user_id", "without_ident_users", User.findAllByLoginOrID],
["annotation_user_id", "annotation_users", User.findAllByLoginOrID]
];
_.each( arrayInstancesToLookup, lookupMapping => {
const [paramKey, objectKey, lookupMethod] = lookupMapping;
Expand Down
5 changes: 3 additions & 2 deletions lib/models/observation_query_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,14 +959,15 @@ ObservationQueryBuilder.reqToElasticQueryComponents = async req => {
inverseFilters.push( nestedQuery );
}

if ( params.annotation_user_id ) {
if ( req.inat.annotation_users ) {
const annotationUserIDs = _.map( req.inat.annotation_users, "id" );
const nestedQuery = {
nested: {
path: "annotations",
query: {
bool: {
filter: [
esClient.termFilter( "annotations.user_id", params.annotation_user_id )
esClient.termFilter( "annotations.user_id", annotationUserIDs )
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/views/swagger_v1.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ parameters:
name: annotation_user_id
type: array
items:
type: integer
type: string
in: query
description: |
Must have an annotation created by this user
Expand Down
2 changes: 1 addition & 1 deletion openapi/schema/request/observations_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports = Joi.object( ).keys( {
term_value_id: Joi.array( ).items( Joi.number( ).integer( ) ),
without_term_value_id: Joi.array( ).items( Joi.number( ).integer( ) ),
term_id_or_unknown: Joi.array( ).items( Joi.number( ).integer( ) ),
annotation_user_id: Joi.array( ).items( Joi.number( ).integer( ) ),
annotation_user_id: Joi.array( ).items( Joi.string( ) ),
acc_above: Joi.number( ).integer( ),
acc_below: Joi.number( ).integer( ),
acc_below_or_unknown: Joi.number( ).integer( ),
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/v1/observations_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ describe( "ObservationsController", ( ) => {
} );

it( "filters by annotation user ID", async ( ) => {
const q = await Q( { annotation_user_id: 1 } );
const q = await Q( { inat: { annotation_users: [{ id: 1, login: "userlogin" }] } } );
expect( q.filters[0].nested.query.bool.filter[0]
.terms["annotations.user_id"][0] ).to.eql( 1 );
} );
Expand Down

0 comments on commit 5867814

Please sign in to comment.