Skip to content
Merged
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
3 changes: 1 addition & 2 deletions app/controllers/AnnotationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ class AnnotationController @Inject()(
annotationInfos <- annotationDAO.findAllListableExplorationals(
isFinished,
None,
isForOwnDashboard = true,
AnnotationType.Explorational,
filterOwnedOrShared = true,
limit.getOrElse(annotationService.DefaultAnnotationListLimit),
pageNumber.getOrElse(0)
)
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/UserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class UserController @Inject()(userService: UserService,
annotations <- annotationDAO.findAllListableExplorationals(
isFinished,
Some(request.identity._id),
isForOwnDashboard = true,
AnnotationType.Explorational,
filterOwnedOrShared = true,
limit.getOrElse(annotationService.DefaultAnnotationListLimit),
pageNumber.getOrElse(0)
)
Expand Down Expand Up @@ -118,8 +117,7 @@ class UserController @Inject()(userService: UserService,
annotations <- annotationDAO.findAllListableExplorationals(
isFinished,
Some(userIdValidated),
isForOwnDashboard = false,
AnnotationType.Explorational,
filterOwnedOrShared = false,
limit.getOrElse(annotationService.DefaultAnnotationListLimit),
pageNumber.getOrElse(0)
)
Expand Down
24 changes: 19 additions & 5 deletions app/models/annotation/Annotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,34 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati
// format: on
}

/**
* Find all annotations which are listable by the user specified in 'forUser'
*
* @param isFinished
* If set to `true`, only finished annotations are returned. If set to `false`, only active annotations are returned.
* If set to `None`, all non-cancelled annotations are returned.
* @param forUser
* If set, only annotations of this user are returned. If not set, all annotations are returned.
* @param filterOwnedOrShared
* If `true`, the function lists only annotations owned by the user or explicitly shared with them (used for the
* user's own dashboard). If `false`, it lists all annotations the viewer is allowed to see.
* @param limit
* The maximum number of annotations to return.
* @param pageNumber
* The page number to return. The first page is 0.
*/
def findAllListableExplorationals(
isFinished: Option[Boolean],
forUser: Option[ObjectId],
// In dashboard, list only own + explicitly shared annotations. When listing those of another user, list all of their annotations the viewer is allowed to see
isForOwnDashboard: Boolean,
typ: AnnotationType,
filterOwnedOrShared: Boolean,
limit: Int,
pageNumber: Int = 0)(implicit ctx: DBAccessContext): Fox[List[AnnotationCompactInfo]] =
for {
accessQuery <- if (isForOwnDashboard) accessQueryFromAccessQWithPrefix(listAccessQ, q"a.")
accessQuery <- if (filterOwnedOrShared) accessQueryFromAccessQWithPrefix(listAccessQ, q"a.")
else accessQueryFromAccessQWithPrefix(readAccessQWithPrefix, q"a.")
stateQuery = getStateQuery(isFinished)
userQuery = forUser.map(u => q"a._user = $u").getOrElse(q"TRUE")
typQuery = q"a.typ = $typ"
typQuery = q"a.typ = ${AnnotationType.Explorational}"

query = q"""WITH
-- teams_agg is extracted to avoid left-join fanout.
Expand Down