<commit_before>(SELECT
  block.geom,
  block.id,
  turf.group_id,
  core_group.slug AS group_slug,
  CASE
    WHEN (block.is_available AND reservation.id IS NULL
          AND (turf.id IS NULL
               OR trustedmapper.id IS NOT NULL
               OR core_group.admin_id = <%= user_id %>)) THEN 'available'
    -- If a blockface is currently reserved, we should make it look
    -- 'available'.  We use a GeoJSON layer in the UI for the user's
    -- reserved blockfaces, and when a blockface is deselected we want to
    -- be able to reselect it
    WHEN (block.is_available
          AND reservation.user_id IS NOT DISTINCT FROM <%= user_id %>) THEN 'available'
    ELSE 'unavailable'
  END AS survey_type,
  CASE
    WHEN NOT block.is_available THEN 'unavailable'
    WHEN (core_group.id IS NOT NULL
          AND NOT core_group.allows_individual_mappers) THEN 'unavailable'
    WHEN reservation.id IS NOT NULL AND reservation.user_id <> <%= user_id %> THEN 'reserved'
    -- We should only allow requesting access to active groups that you are
    -- not already a trusted mapper or admin of
    WHEN (turf.id IS NOT NULL
          AND (core_group.is_active = TRUE
               AND trustedmapper.id IS NULL
               AND core_group.admin_id <> <%= user_id %>)) THEN 'group_territory'
    -- If a group is inactive, it is unavailable unless you are an admin or
    -- a trusted mapper of that group
    WHEN (turf.id IS NOT NULL
          AND core_group.is_active = FALSE
          AND trustedmapper.id IS NULL
          AND core_group.admin_id <> <%= user_id %>) THEN 'unavailable'
    ELSE 'none'
  END AS restriction
  FROM survey_blockface AS block
  LEFT OUTER JOIN survey_territory AS turf
    ON block.id = turf.blockface_id
  LEFT JOIN core_group ON core_group.id = turf.group_id
  LEFT OUTER JOIN survey_blockfacereservation AS reservation
    ON (block.id = reservation.blockface_id<commit_msg>Don't let non trusted mappers reserve blocks owned by inactive groups<commit_after>(SELECT
  block.geom,
  block.id,
  turf.group_id,
  core_group.slug AS group_slug,
  CASE
    WHEN (block.is_available AND reservation.id IS NULL
          AND (turf.id IS NULL
               OR trustedmapper.id IS NOT NULL
               OR core_group.admin_id = <%= user_id %>)) THEN 'available'
    -- If a blockface is currently reserved, we should make it look
    -- 'available'.  We use a GeoJSON layer in the UI for the user's
    -- reserved blockfaces, and when a blockface is deselected we want to
    -- be able to reselect it
    WHEN (block.is_available
          AND reservation.user_id IS NOT DISTINCT FROM <%= user_id %>) THEN 'available'
    ELSE 'unavailable'
  END AS survey_type,
  CASE
    WHEN NOT block.is_available THEN 'unavailable'
    WHEN (core_group.id IS NOT NULL
          AND NOT core_group.allows_individual_mappers) THEN 'unavailable'
    WHEN reservation.id IS NOT NULL AND reservation.user_id <> <%= user_id %> THEN 'reserved'
    -- Designate as "group_territory" if block belongs to a group and the user
    -- is neither a trusted mapper nor a group admin.
    -- Don't filter out inactive groups or else non trusted mappers will be
    -- able to reserve blocks in the "expert" group.
    WHEN (turf.id IS NOT NULL
          AND trustedmapper.id IS NULL
          AND core_group.admin_id <> <%= user_id %>) THEN 'group_territory'
    ELSE 'none'
  END AS restriction
  FROM survey_blockface AS block
  LEFT OUTER JOIN survey_territory AS turf
    ON block.id = turf.blockface_id
  LEFT JOIN core_group ON core_group.id = turf.group_id
  LEFT OUTER JOIN survey_blockfacereservation AS reservation
    ON (block.id = reservation.blockface_id
{'fraction_non_alphanumeric': 0.06809549647314161, 'fraction_numerical': 0.0, 'mean_word_length': 2.8010309278350514, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3726047', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1070, 'n_words': 422}