diff --git a/app/org/maproulette/controllers/api/TaskController.scala b/app/org/maproulette/controllers/api/TaskController.scala index 2b8eb55d2..039ec3648 100644 --- a/app/org/maproulette/controllers/api/TaskController.scala +++ b/app/org/maproulette/controllers/api/TaskController.scala @@ -719,24 +719,35 @@ class TaskController @Inject() ( ) p success Ok(Json.toJson(true)) case _ => - None - changeService.submitOsmChange( - change, - element.comment, - user.osmProfile.requestToken, - Some(taskId) - ) onComplete { - case Success(res) => { - this.customTaskStatus( - taskId, - TaskStatusSet(Task.STATUS_FIXED), - user, - tags, - requestReview - ) - p success Ok(res) - } - case Failure(f) => p failure f + // Get the parent challenge to retrieve the changeset source + this.dal.retrieveById(taskId) match { + case Some(task) => + val challengeSource = this.dalManager.challenge + .retrieveById(task.parent) + .map(_.general.checkinSource) + .getOrElse("") + + changeService.submitOsmChange( + change, + element.comment, + user.osmProfile.requestToken, + Some(taskId), + Some(challengeSource) + ) onComplete { + case Success(res) => { + this.customTaskStatus( + taskId, + TaskStatusSet(Task.STATUS_FIXED), + user, + tags, + requestReview + ) + p success Ok(res) + } + case Failure(f) => p failure f + } + case None => + p failure new NotFoundException(s"Task with $taskId not found") } } p.future diff --git a/app/org/maproulette/provider/osm/ChangesetProvider.scala b/app/org/maproulette/provider/osm/ChangesetProvider.scala index 4b38aac4b..f3a5db10b 100644 --- a/app/org/maproulette/provider/osm/ChangesetProvider.scala +++ b/app/org/maproulette/provider/osm/ChangesetProvider.scala @@ -68,17 +68,21 @@ class ChangesetProvider @Inject() ( * * @param changes The changes to be submitted to OSM * @param changeSetComment The changeset comment to be associated with the change + * @param accessToken The OAuth access token for authentication + * @param taskId Optional taskId to associate with this changeset + * @param source Optional source to be associated with the changeset * @return future that will return the OSMChange that was submitted to the OSM servers */ def submitOsmChange( changes: OSMChange, changeSetComment: String, accessToken: String, - taskId: Option[Long] = None + taskId: Option[Long] = None, + source: Option[String] = None )(implicit c: Option[Connection] = None): Future[Elem] = { val p = Promise[Elem]() // create the new changeset - this.createChangeset(changeSetComment, accessToken) onComplete { + this.createChangeset(changeSetComment, accessToken, source) onComplete { case Success(changesetId) => // retrieve the current version of the osm feature // conflate the current tags with provided tags @@ -248,15 +252,21 @@ class ChangesetProvider @Inject() ( * * @param comment The comment to associate with the changeset * @param accessToken The access token for the user + * @param source Optional source to be associated with the changeset * @return */ - def createChangeset(comment: String, accessToken: String): Future[Int] = { + def createChangeset( + comment: String, + accessToken: String, + source: Option[String] = None + ): Future[Int] = { // Changeset XML Element val newChangeSet = + {source.filter(_.nonEmpty).map(s => ).getOrElse(NodeSeq.Empty)} implicit val url = s"${config.getOSMServer}/api/0.6/changeset/create"