Skip to content

Commit

Permalink
Merge branch 'main' into inatnls-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jun 21, 2024
2 parents 12f1eee + 5867814 commit 505b522
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 44 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CICD-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ jobs:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.ref_name }}

refresh-dev-staging-deployment:
name: Refresh Dev Staging Deployment
needs: build-and-push-dev-docker-image
runs-on: ubuntu-20.04
steps:
- name: Refresh Dev inaturalistapi
uses: actions/github-script@v6
with:
github-token: ${{secrets.STAGING_DEPLOYMENT_PERSONAL_ACCESS_TOKEN}}
script: |-
await github.rest.actions.createWorkflowDispatch({
owner: "inaturalist",
repo: "staging-deployment",
workflow_id: "CD-workflow-dispatch.yml",
ref: "main",
inputs: {
"service-type": "api",
"service-version": "${{ github.ref_name }}"
},
}).catch(error => error).then(response => {
core.debug(response);
if (response.status !== 204) {
core.setFailed(`create workflow_dispatch received status code ${response.status}`);
}
});
notify-slack:
name: Notify Slack
needs: build-and-push-dev-docker-image
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/CICD-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ jobs:
${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.sha }}
${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:latest
refresh-main-staging-deployment:
name: Refresh Main Staging Deployment
needs: build-and-push-main-docker-image
runs-on: ubuntu-20.04
steps:
- name: Refresh Main inaturalistapi
uses: actions/github-script@v6
with:
github-token: ${{secrets.STAGING_DEPLOYMENT_PERSONAL_ACCESS_TOKEN}}
script: |-
await github.rest.actions.createWorkflowDispatch({
owner: "inaturalist",
repo: "staging-deployment",
workflow_id: "CD-workflow-dispatch.yml",
ref: "main",
inputs: {
"service-type": "api",
"service-version": "latest"
},
}).catch(error => error).then(response => {
core.debug(response);
if (response.status !== 204) {
core.setFailed(`create workflow_dispatch received status code ${response.status}`);
}
});
notify-slack:
name: Notify Slack
needs: build-and-push-main-docker-image
Expand Down
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
17 changes: 17 additions & 0 deletions lib/models/observation_query_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,23 @@ ObservationQueryBuilder.reqToElasticQueryComponents = async req => {
inverseFilters.push( nestedQuery );
}

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", annotationUserIDs )
]
}
}
}
};
searchFilters.push( nestedQuery );
}

if (
req.userSession
// Don't filter out obs by blocking users if the viewer is just viewing a
Expand Down
1 change: 1 addition & 0 deletions lib/views/_observation_search_params_v1.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- $ref: "#/parameters/without_term_id"
- $ref: "#/parameters/without_term_value_id"
- $ref: "#/parameters/term_id_or_unknown"
- $ref: "#/parameters/annotation_user_id"
# other
- $ref: "#/parameters/acc_above"
- $ref: "#/parameters/acc_below"
Expand Down
8 changes: 8 additions & 0 deletions lib/views/swagger_v1.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,14 @@ parameters:
Must be combined with the `term_value_id` or the `without_term_value_id` parameter.
Must have an annotation using this controlled term ID and associated term value IDs
or be missing this annotation.
annotation_user_id:
name: annotation_user_id
type: array
items:
type: string
in: query
description: |
Must have an annotation created by this user
ofv_datatype:
name: ofv_datatype
type: array
Expand Down
2 changes: 1 addition & 1 deletion openapi/paths/v2/observation_sounds/{uuid}.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = sendWrapper => {
}

PUT.apiDoc = {
tags: ["ObservationPhotos"],
tags: ["ObservationSounds"],
summary: "Update an observation sound",
security: [{
userJwtRequired: []
Expand Down
1 change: 1 addition & 0 deletions openapi/schema/request/observation_photos_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = Joi.object( )
.description( "UUID for the existing observation" ),
photo_id: Joi.number( ).integer( )
.description( "Sequential ID for the existing photo" ),
position: Joi.number( ).integer( ),
uuid: Joi.string( ).guid( { version: "uuidv4" } )
.description(
"New UUID for the photo, helps prevent duplication in poor network conditions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = Joi.object( ).keys( {
.description(
"New UUID for the photo, helps prevent duplication in poor network conditions"
),
"observation_photo[position]": Joi.number( ).integer( ),
file: Joi.binary( ).required( )
} ).unknown( true );
1 change: 1 addition & 0 deletions openapi/schema/request/observations_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +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.string( ) ),
acc_above: Joi.number( ).integer( ),
acc_below: Joi.number( ).integer( ),
acc_below_or_unknown: Joi.number( ).integer( ),
Expand Down
1 change: 1 addition & 0 deletions openapi/schema/response/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = Joi.object( ).keys( {
icon_url: Joi.string( ).valid( null ),
identifications_count: Joi.number( ).integer( ),
journal_posts_count: Joi.number( ).integer( ),
annotated_observations_count: Joi.number( ).integer( ),
last_active: Joi.date( ).iso( ),
login: Joi.string( ),
monthly_supporter: Joi.boolean( ).valid( null ),
Expand Down
92 changes: 53 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/controllers/v1/observations_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,12 @@ describe( "ObservationsController", ( ) => {
expect( q.filters ).to.eql( [{ terms: { id: experimentObsIDs } }] );
} );

it( "filters by annotation user ID", async ( ) => {
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 );
} );

//
// Sorting
//
Expand Down
12 changes: 9 additions & 3 deletions test/integration/v2/observation_photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe( "ObservationPhotos", ( ) => {
id: 1234,
uuid: "b9576748-095f-43e4-ae25-0bb86ec74c47",
observation_id: "c1386ffd-1a87-40f7-b646-b9f716595567",
position: 0
position: 1
};

describe( "create", ( ) => {
Expand All @@ -26,14 +26,19 @@ describe( "ObservationPhotos", ( ) => {
request( this.app ).post( "/v2/observation_photos" )
.set( "Authorization", token )
.set( "Content-Type", "multipart/form-data" )
.field( "fields", "id,uuid" )
.field( "fields", "id,uuid,position" )
.field( "observation_photo[observation_id]", obsPhoto.observation_id )
.field( "observation_photo[position]", 1 )
.attach( "file", "test/fixtures/cuthona_abronia-tagged.jpg" )
.expect( 200 )
.expect( res => {
// NOTE: these properties are just what was stubbed with `const obsPhoto` above, so
// this just tests that the endpoint was hit without error and returned what we
// instructed it to return
const resObj = res.body.results[0];
expect( resObj.uuid ).to.eq( obsPhoto.uuid );
expect( resObj.id ).to.eq( obsPhoto.id );
expect( resObj.position ).to.eq( obsPhoto.position );
} )
.expect( "Content-Type", /json/ )
.expect( 200, done );
Expand All @@ -50,7 +55,8 @@ describe( "ObservationPhotos", ( ) => {
observation_photo: {
observation_id: obsPhoto.observation_id,
photo_id: 123,
uuid: obsPhoto.uuid
uuid: obsPhoto.uuid,
position: 2
}
} )
.expect( 200, done );
Expand Down

0 comments on commit 505b522

Please sign in to comment.