Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resetTaskBundle endpoint #1107

Merged
merged 26 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ffc45ff
add resetTaskBundle endpoint
CollinBeczak Mar 1, 2024
49ac832
add bundleTasks endpoint and fix bugs with bundle resets and simplify…
CollinBeczak Mar 9, 2024
6096fcc
remove bundleTasks endpoint
CollinBeczak Mar 10, 2024
c99f843
fix task bundle reset to setup up tasks added back with the proper re…
CollinBeczak Mar 11, 2024
25e8c06
run scalafmt
CollinBeczak Mar 11, 2024
eac3b5b
formatting, and fix test to allow task in bundle to be unlocked
CollinBeczak Mar 11, 2024
635949a
fix some variables in the task bundling related tests
CollinBeczak Mar 11, 2024
759a8aa
revert task locking on fetch
CollinBeczak Mar 11, 2024
3386a8d
remove test because it is no longer needed
CollinBeczak Mar 11, 2024
aecba90
add task locking back
CollinBeczak Mar 11, 2024
6c3b8c9
updae comments
CollinBeczak Mar 12, 2024
5cc7b95
add needed value in tasks that were reset and added back into the tas…
CollinBeczak Mar 13, 2024
33ef580
formatting
CollinBeczak Mar 20, 2024
61bafed
remove logger and reorganize code
CollinBeczak Apr 21, 2024
0b381b7
change the fetch bundle endpoint from a GET to a POST
CollinBeczak Apr 22, 2024
8b0e10c
fix mixed up param descriptions
CollinBeczak Apr 22, 2024
98a709f
simplify task removal in bundle reset
CollinBeczak Apr 22, 2024
fa28dc5
remove primary task id from params and simplify endpoints
CollinBeczak Apr 22, 2024
bc7b220
remove primary task id descriptions
CollinBeczak Apr 22, 2024
1997cc3
remove params from tests
CollinBeczak Apr 22, 2024
7c6d0c1
fix tests
CollinBeczak Apr 22, 2024
ff3f658
fix wrong column name issue
CollinBeczak Apr 22, 2024
e9463d7
split bundle tasks functionality into its own function
CollinBeczak Apr 22, 2024
0f6f4eb
add bundling user restrictions and test back
CollinBeczak Apr 23, 2024
b3a2911
add missing param to test
CollinBeczak Apr 23, 2024
2719505
remove caching manager
CollinBeczak Apr 26, 2024
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
44 changes: 32 additions & 12 deletions app/org/maproulette/framework/controller/TaskBundleController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ class TaskBundleController @Inject() (
*/
def createTaskBundle(): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val name = (request.body \ "name").asOpt[String].getOrElse("")
val name = (request.body \ "name").asOpt[String].getOrElse("")
val primaryId = (request.body \ "primaryId").asOpt[Long]
val taskIds = (request.body \ "taskIds").asOpt[List[Long]] match {
case Some(tasks) => tasks
case None => throw new InvalidException("No task ids provided for task bundle")
}
val bundle = this.serviceManager.taskBundle.createTaskBundle(user, name, taskIds)
val bundle = this.serviceManager.taskBundle.createTaskBundle(user, name, primaryId, taskIds)
Created(Json.toJson(bundle))
}
}
Expand All @@ -253,8 +254,25 @@ class TaskBundleController @Inject() (
* @param id The id for the bundle
* @return Task Bundle
*/
def getTaskBundle(id: Long): Action[AnyContent] = Action.async { implicit request =>
def getTaskBundle(id: Long, lockTasks: Boolean): Action[AnyContent] = Action.async {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
Ok(Json.toJson(this.serviceManager.taskBundle.getTaskBundle(user, id, lockTasks)))
}
}

/**
* Resets the bundle to the tasks provided, and unlock all tasks removed from current bundle
*
* @param bundleId The id of the bundle
* @param taskIds The task ids the bundle will reset to
*/
def resetTaskBundle(
id: Long,
taskIds: List[Long]
): Action[AnyContent] = Action.async { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
this.serviceManager.taskBundle.resetTaskBundle(user, id, taskIds)
Ok(Json.toJson(this.serviceManager.taskBundle.getTaskBundle(user, id)))
}
}
Expand All @@ -266,24 +284,26 @@ class TaskBundleController @Inject() (
* @param taskIds List of task ids to remove
* @return Task Bundle
*/
def unbundleTasks(id: Long, taskIds: List[Long]): Action[AnyContent] = Action.async {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
this.serviceManager.taskBundle.unbundleTasks(user, id, taskIds)
Ok(Json.toJson(this.serviceManager.taskBundle.getTaskBundle(user, id)))
}
def unbundleTasks(
id: Long,
taskIds: List[Long],
preventTaskIdUnlocks: List[Long]
): Action[AnyContent] = Action.async { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
this.serviceManager.taskBundle.unbundleTasks(user, id, taskIds, preventTaskIdUnlocks)
Ok(Json.toJson(this.serviceManager.taskBundle.getTaskBundle(user, id)))
}
}

/**
* Delete bundle.
*
* @param id The id for the bundle
* @param primaryId optional task id to no unlock after deleting this bundle
*/
def deleteTaskBundle(id: Long, primaryId: Option[Long] = None): Action[AnyContent] =
def deleteTaskBundle(id: Long): Action[AnyContent] =
Action.async { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
this.serviceManager.taskBundle.deleteTaskBundle(user, id, primaryId)
this.serviceManager.taskBundle.deleteTaskBundle(user, id)
Ok
}
}
Expand Down
17 changes: 17 additions & 0 deletions app/org/maproulette/framework/mixins/SearchParametersMixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ trait SearchParametersMixin {
this.filterChallengeStatus(params),
this.filterChallengeRequiresLocal(params),
this.filterBoundingGeometries(params),
this.filterBundleId(params),
// For efficiency can only query on task properties with a parent challenge id
this.filterTaskProps(params),
this.filterChallenges(params),
Expand Down Expand Up @@ -324,6 +325,22 @@ trait SearchParametersMixin {
}
}

/**
* Filters by bundle id
* @param params with inverting on 'bid'
*/
def filterBundleId(params: SearchParameters): FilterGroup = {
params.taskParams.bundleId match {
case Some(bid) =>
FilterGroup(
List(
CustomParameter(s"${Task.TABLE}.${Task.FIELD_BUNDLE_ID} = $bid")
)
)
case _ => FilterGroup(List())
}
}

/**
* Filters by tasks.priority
* @param params with inverting on 'priorities'
Expand Down
Loading
Loading