Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,24 @@ object HubResource {
)

/**
* Checks if a given user has liked a specific entity.
* Checks, for each requested entity, whether the given user has liked it.
*
* @param userId The ID of the user.
* @param entityId The ID of the entity.
* @param entityType The type of entity being checked (must be validated).
* @return `true` if the user has liked the entity, otherwise `false`.
* @param entityIds The entity IDs. Must have the same length as entityTypes.
* @param entityTypes The entity types. Must have the same length as entityIds.
* @return The liked status for each entity.
* @throws javax.ws.rs.BadRequestException if the lists have different lengths
*/
def isLikedHelper(
userId: Integer,
entityIds: java.util.List[Integer],
entityTypes: java.util.List[EntityType]
): java.util.List[LikedResponse] = {
if (entityTypes.size() != entityIds.size())
throw new BadRequestException(
"'entityType' and 'entityId' query parameter lists must have equal length."
)

val reqs: List[UserRequest] =
entityTypes.asScala
.zip(entityIds.asScala)
Expand Down Expand Up @@ -639,6 +645,7 @@ class HubResource {
* - entityType: the resource type
* - entityId: the resource ID
* - userIds: the list of user IDs with access to that resource
* @throws javax.ws.rs.BadRequestException if the lists have different lengths
*/
@GET
@Path("/user-access")
Expand All @@ -647,6 +654,11 @@ class HubResource {
@QueryParam("entityType") entityTypes: java.util.List[EntityType],
@QueryParam("entityId") entityIds: java.util.List[Integer]
Comment thread
carloea2 marked this conversation as resolved.
): java.util.List[AccessResponse] = {
if (entityTypes.size() != entityIds.size())
Comment thread
carloea2 marked this conversation as resolved.
throw new BadRequestException(
"'entityType' and 'entityId' query parameter lists must have equal length."
)

val reqs =
entityIds.asScala
.zip(entityTypes.asScala)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,15 @@ class HubResourceSpec
isLikedHelper(Integer.valueOf(ownerUid), ids(), types()).asScala shouldBe empty
}

it should "reject mismatched entity type and id lists" in {
intercept[BadRequestException](
isLikedHelper(Integer.valueOf(ownerUid), ids(wid, 810000), types(Wf))
)
intercept[BadRequestException](
isLikedHelper(Integer.valueOf(ownerUid), ids(wid), types(Wf, Ds))
)
}

"isLiked" should "resolve the liked flag against the session user, not another user" in {
seedWorkflow(810304, "wf_session_like")
seedWorkflowLike(810304, ownerUid)
Expand Down Expand Up @@ -845,6 +854,11 @@ class HubResourceSpec
response.userIds.asScala should contain(Integer.valueOf(ownerUid))
}

it should "reject mismatched entity type and id lists" in {
intercept[BadRequestException](hub.userAccess(types(Wf), ids(wid, 810000)))
intercept[BadRequestException](hub.userAccess(types(Wf, Ds), ids(wid)))
}

it should "return each entity's grantees from that entity's own access table" in {
seedWorkflow(810901, "wf_access", withOwnerRows = false)
seedDataset(820901, "ds_access")
Expand Down
Loading