Skip to content

Commit

Permalink
fix task status issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Nov 12, 2024
1 parent 1692552 commit 7c24f85
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,10 @@ class TaskBundleController @Inject() (
*/
def unbundleTasks(
id: Long,
taskIds: List[Long],
preventTaskIdUnlocks: List[Long]
taskIds: List[Long]
): Action[AnyContent] = Action.async { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
this.serviceManager.taskBundle.unbundleTasks(user, id, taskIds, preventTaskIdUnlocks)
this.serviceManager.taskBundle.unbundleTasks(user, id, taskIds)
Ok(Json.toJson(this.serviceManager.taskBundle.getTaskBundle(user, id)))
}
}
Expand Down
32 changes: 17 additions & 15 deletions app/org/maproulette/framework/repository/TaskBundleRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ class TaskBundleRepository @Inject() (
val parameters = lockedTasks.map(task => Seq[NamedParameter]("taskId" -> task.id))
BatchSql(sqlInsertTaskBundles, parameters.head, parameters.tail: _*).execute()

// Lock each of the new tasks to indicate they are part of the bundle
for (task <- lockedTasks) {
try {
this.lockItem(user, task)
} catch {
case e: Exception => this.logger.warn(e.getMessage)
}
taskRepository.cacheManager.cache.remove(task.id)
}

Expand Down Expand Up @@ -134,7 +128,7 @@ class TaskBundleRepository @Inject() (
val tasksToRemove = currentTaskIds.filter(taskId => !taskIds.contains(taskId))

if (tasksToRemove.nonEmpty) {
this.unbundleTasks(user, bundleId, tasksToRemove, List.empty)
this.unbundleTasks(user, bundleId, tasksToRemove)
}

// Filter for tasks that need to be added back to the bundle.
Expand Down Expand Up @@ -226,8 +220,7 @@ class TaskBundleRepository @Inject() (
def unbundleTasks(
user: User,
bundleId: Long,
taskIds: List[Long],
preventTaskIdUnlocks: List[Long]
taskIds: List[Long]
): Unit = {
this.withMRConnection { implicit c =>
val tasks = this.retrieveTasks(
Expand Down Expand Up @@ -265,12 +258,10 @@ class TaskBundleRepository @Inject() (
)
.executeUpdate()

if (!preventTaskIdUnlocks.contains(task.id)) {
try {
this.unlockItem(user, task)
} catch {
case e: Exception => this.logger.warn(e.getMessage)
}
try {
this.unlockItem(user, task)
} catch {
case e: Exception => this.logger.warn(e.getMessage)
}
taskRepository.cacheManager.cache.remove(task.id)
case None => // do nothing
Expand Down Expand Up @@ -306,8 +297,19 @@ class TaskBundleRepository @Inject() (
.on("bundleId" -> bundleId)
.executeUpdate()

// Update cache for each task
tasks.foreach { task =>
if (!task.isBundlePrimary.getOrElse(false)) {
SQL(
"""UPDATE tasks
SET status = {status}
WHERE id = {taskId}
"""
).on(
"taskId" -> task.id,
"status" -> STATUS_CREATED
)
.executeUpdate()
try {
this.unlockItem(user, task)
} catch {
Expand Down
5 changes: 2 additions & 3 deletions app/org/maproulette/framework/service/TaskBundleService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class TaskBundleService @Inject() (
def unbundleTasks(
user: User,
bundleId: Long,
taskIds: List[Long],
preventTaskIdUnlocks: List[Long]
taskIds: List[Long]
)(): TaskBundle = {
val bundle = this.getTaskBundle(user, bundleId)

Expand All @@ -132,7 +131,7 @@ class TaskBundleService @Inject() (
)
}

this.repository.unbundleTasks(user, bundleId, taskIds, preventTaskIdUnlocks)
this.repository.unbundleTasks(user, bundleId, taskIds)
this.getTaskBundle(user, bundleId)
}

Expand Down
6 changes: 1 addition & 5 deletions conf/v2_route/bundle.api
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,5 @@ DELETE /taskBundle/:id @org.maproulette.framework.c
# in: query
# description: The list of task ids to remove from the bundle
# required: true
# - name: preventTaskIdUnlocks
# in: query
# description: The list of task ids to keep locked when removed from bundle
# required: true
###
POST /taskBundle/:id/unbundle @org.maproulette.framework.controller.TaskBundleController.unbundleTasks(id:Long, taskIds:List[Long], preventTaskIdUnlocks:List[Long])
POST /taskBundle/:id/unbundle @org.maproulette.framework.controller.TaskBundleController.unbundleTasks(id:Long, taskIds:List[Long])
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class TaskBundleServiceSpec(implicit val application: Application) extends Frame
primaryTaskId = Some(task1.id)
)

this.service.unbundleTasks(User.superUser, bundle.bundleId, List(task2.id), List(task1.id))()
this.service.unbundleTasks(User.superUser, bundle.bundleId, List(task2.id))()
val response = this.service.getTaskBundle(User.superUser, bundle.bundleId)
response.taskIds.length mustEqual 1
response.taskIds.head mustEqual task1.id
Expand Down Expand Up @@ -281,7 +281,7 @@ class TaskBundleServiceSpec(implicit val application: Application) extends Frame

// Random user is not allowed to delete this bundle
an[IllegalAccessException] should be thrownBy
this.service.unbundleTasks(randomUser, bundle.bundleId, List(task2.id), List())()
this.service.unbundleTasks(randomUser, bundle.bundleId, List(task2.id))()
}

}
Expand Down

0 comments on commit 7c24f85

Please sign in to comment.