Skip to content

Commit

Permalink
add cooperative task bundling rules (#1063)
Browse files Browse the repository at this point in the history
* add cooperative task bundling rules

* remove cooperative tasks cannot be bundled test
  • Loading branch information
CollinBeczak authored Sep 4, 2023
1 parent 65034e2 commit d47f5c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
16 changes: 12 additions & 4 deletions app/org/maproulette/framework/service/TaskBundleService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ class TaskBundleService @Inject() (
throw new InvalidException("Must be at least one task to bundle.")
}

val challengeId = tasks.head.parent
val challengeId = tasks.head.parent
val cooperativeWork = tasks.head.cooperativeWork.isDefined

// Verify tasks
// 1. Must belong to same challenge
// 2. Cooperative tasks not allowed
// 2. Must be same task type as main task
for (task <- tasks) {
if (task.cooperativeWork.isDefined) {
throw new InvalidException("Cooperative tasks cannot be bundled.")
if (cooperativeWork && task.cooperativeWork.isDefined != cooperativeWork) {
throw new InvalidException(
"The main task type is Cooperative. All selected tasks must be Cooperative."
)
}
if (!cooperativeWork && task.cooperativeWork.isDefined != cooperativeWork) {
throw new InvalidException(
"The main task type is not Cooperative. All selected tasks must not be Cooperative."
)
}
if (task.parent != challengeId) {
throw new InvalidException(
Expand Down
7 changes: 0 additions & 7 deletions app/org/maproulette/models/dal/TaskDAL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,13 @@ class TaskDAL @Inject() (
var bundleUpdate = ""

// Find primary task in bundle if we are using a bundle
// Also check to make sure they aren't cooperative tasks
bundleId match {
case Some(b) =>
bundleUpdate = ", bundle_id = " + b
for (task <- tasks) {
primaryTaskId match {
case Some(p) =>
if (task.id == p) primaryTask = task
if (task.cooperativeWork != None) {
throw new InvalidException(
"Cannot set task status as part of a bundle on task: " +
task.id + " as it contains cooperative work."
)
}
case _ => // do nothing
}
}
Expand Down
15 changes: 0 additions & 15 deletions test/org/maproulette/framework/service/TaskBundleServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@ class TaskBundleServiceSpec(implicit val application: Application) extends Frame
}
}

"not create a task Bundle with cooperative tasks" taggedAs (TaskTag) in {
val task1 = taskDAL
.insert(
getTestTask(UUID.randomUUID().toString, challenge.id).copy(
cooperativeWork = Some("{\"meta\": {\"version\": 1} }")
),
User.superUser
)

// Cannot create a bundle with cooperative tasks
intercept[InvalidException] {
this.service.createTaskBundle(User.superUser, "bad bundle again", List(task1.id))
}
}

"get a task Bundle" taggedAs (TaskTag) in {
val task1 = taskDAL
.insert(
Expand Down

0 comments on commit d47f5c7

Please sign in to comment.