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

fix isArchived and isGlobal filtering in extendFind endpoint #1164

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
32 changes: 16 additions & 16 deletions app/org/maproulette/framework/mixins/SearchParametersMixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -700,31 +700,31 @@ trait SearchParametersMixin {
* challengeParams.archived value is true
*/
def filterChallengeArchived(params: SearchParameters): FilterGroup = {
if (params.challengeParams.archived.getOrElse("false") == "false") {
FilterGroup(
List(
FilterParameter.conditional(
Challenge.FIELD_ARCHIVED,
value = "false",
Operator.EQ,
useValueDirectly = true,
includeOnlyIfTrue = true,
table = Some("c")
params.challengeParams.archived match {
case Some(false) =>
FilterGroup(
List(
FilterParameter.conditional(
Challenge.FIELD_ARCHIVED,
value = "false",
Operator.EQ,
useValueDirectly = true,
includeOnlyIfTrue = true,
table = Some("c")
)
)
)
)
} else {
FilterGroup(List())
case _ => FilterGroup(List())
}
}

/**
* Filters by c.is_global. Will only include if
* challengeParams.filterGlobal value is true
* challengeParams.filterGlobal value is false
*/
def filterChallengeGlobal(params: SearchParameters): FilterGroup = {
params.challengeParams.filterGlobal match {
case Some(v) if v =>
params.challengeParams.global match {
case false =>
FilterGroup(
List(
FilterParameter.conditional(
Expand Down
17 changes: 9 additions & 8 deletions app/org/maproulette/models/dal/ChallengeDAL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,15 @@ class ChallengeDAL @Inject() (
this.cacheManager.withOptionCaching { () =>
val insertedChallenge =
this.withMRTransaction { implicit c =>
SQL"""INSERT INTO challenges (name, owner_id, parent_id, difficulty, description, is_global, info_link, blurb,
SQL"""INSERT INTO challenges (name, owner_id, parent_id, difficulty, description, info_link, blurb,
instruction, enabled, featured, checkin_comment, checkin_source,
overpass_ql, remote_geo_json, overpass_target_type, status, status_message, default_priority, high_priority_rule,
medium_priority_rule, low_priority_rule, default_zoom, min_zoom, max_zoom,
default_basemap, default_basemap_id, custom_basemap, updatetasks, exportable_properties,
osm_id_property, task_bundle_id_property, last_task_refresh, data_origin_date, preferred_tags, preferred_review_tags,
limit_tags, limit_review_tags, task_styles, requires_local, is_archived, review_setting, dataset_url, require_confirmation, task_widget_layout)
VALUES (${challenge.name}, ${challenge.general.owner}, ${challenge.general.parent}, ${challenge.general.difficulty},
${challenge.description}, ${challenge.isGlobal}, ${challenge.infoLink}, ${challenge.general.blurb}, ${challenge.general.instruction},
${challenge.description}, ${challenge.infoLink}, ${challenge.general.blurb}, ${challenge.general.instruction},
${challenge.general.enabled}, ${challenge.general.featured},
${challenge.general.checkinComment}, ${challenge.general.checkinSource}, ${challenge.creation.overpassQL}, ${challenge.creation.remoteGeoJson},
${challenge.creation.overpassTargetType}, ${challenge.status},
Expand Down Expand Up @@ -595,7 +595,6 @@ class ChallengeDAL @Inject() (
val parentId = (updates \ "parentId").asOpt[Long].getOrElse(cachedItem.general.parent)
val difficulty =
(updates \ "difficulty").asOpt[Int].getOrElse(cachedItem.general.difficulty)
val isGlobal = (updates \ "isGlobal").asOpt[Boolean].getOrElse(cachedItem.isGlobal)
val description =
(updates \ "description").asOpt[String].getOrElse(cachedItem.description.getOrElse(""))
val infoLink =
Expand Down Expand Up @@ -716,7 +715,7 @@ class ChallengeDAL @Inject() (
.getOrElse(cachedItem.extra.presets.getOrElse(null))

val updatedChallenge =
SQL"""UPDATE challenges SET name = $name, owner_id = $ownerId, parent_id = $parentId, difficulty = $difficulty, is_global = $isGlobal,
SQL"""UPDATE challenges SET name = $name, owner_id = $ownerId, parent_id = $parentId, difficulty = $difficulty,
description = $description, info_link = $infoLink, blurb = $blurb, instruction = $instruction,
enabled = $enabled, featured = $featured, checkin_comment = $checkinComment, checkin_source = $checkinSource, overpass_ql = $overpassQL,
remote_geo_json = $remoteGeoJson, overpass_target_type = $overpassTargetType, status = $status, status_message = $statusMessage, default_priority = $defaultPriority,
Expand Down Expand Up @@ -1864,12 +1863,14 @@ class ChallengeDAL @Inject() (
case _ =>
}

if (searchParameters.challengeParams.archived == false) {
this.appendInWhereClause(whereClause, s"c.is_archived = false")
searchParameters.challengeParams.archived match {
case Some(false) => this.appendInWhereClause(whereClause, s"c.is_archived = false")
case _ =>
}

if (searchParameters.challengeParams.filterGlobal == true) {
this.appendInWhereClause(whereClause, s"c.is_global = false")
searchParameters.challengeParams.global match {
case false => this.appendInWhereClause(whereClause, s"c.is_global = false")
case _ =>
}

searchParameters.challengeParams.requiresLocal match {
Expand Down
6 changes: 3 additions & 3 deletions app/org/maproulette/session/SearchParameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case class SearchChallengeParameters(
challengeStatus: Option[List[Int]] = None,
requiresLocal: Option[Int] = Some(SearchParameters.CHALLENGE_REQUIRES_LOCAL_EXCLUDE),
archived: Option[Boolean] = None,
filterGlobal: Option[Boolean] = None
global: Boolean = true
)

case class SearchReviewParameters(
Expand Down Expand Up @@ -441,8 +441,8 @@ object SearchParameters {
this.getIntParameter(request.getQueryString("cLocal"), Some(params.challengeParams.requiresLocal.getOrElse(SearchParameters.CHALLENGE_REQUIRES_LOCAL_EXCLUDE))),
//includeArchived
this.getBooleanParameter(request.getQueryString("ca"), params.challengeParams.archived),
//filterGlobal
this.getBooleanParameter(request.getQueryString("fg"), params.challengeParams.filterGlobal)
//includeGlobal
this.getBooleanParameter(request.getQueryString("cg"), Some(params.challengeParams.global)).getOrElse(true)
),
new SearchTaskParameters(
//taskTags
Expand Down