Skip to content

Commit

Permalink
SW-6182 Populate planting site countries as system user (#2565)
Browse files Browse the repository at this point in the history
The admin UI function to populate the countries of existing planting sites added
in commit d2cfe32 required that the user have write access to all planting sites
in all organizations, which admin users don't have. Run the operation as the
system user instead.
  • Loading branch information
sgrimm authored Nov 5, 2024
1 parent 6221bde commit c3b5abb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.fasterxml.jackson.module.kotlin.readValue
import com.terraformation.backend.api.RequireGlobalRole
import com.terraformation.backend.auth.currentUser
import com.terraformation.backend.customer.db.OrganizationStore
import com.terraformation.backend.customer.model.SystemUser
import com.terraformation.backend.customer.model.requirePermissions
import com.terraformation.backend.db.SRID
import com.terraformation.backend.db.default_schema.GlobalRole
import com.terraformation.backend.db.default_schema.OrganizationId
Expand Down Expand Up @@ -76,6 +78,7 @@ class AdminPlantingSitesController(
private val organizationStore: OrganizationStore,
private val plantingSiteStore: PlantingSiteStore,
private val plantingSiteImporter: PlantingSiteImporter,
private val systemUser: SystemUser,
) {
private val log = perClassLogger()

Expand Down Expand Up @@ -722,8 +725,10 @@ class AdminPlantingSitesController(

@PostMapping("/plantingSite/populateCountries")
fun populatePlantingSiteCountries(redirectAttributes: RedirectAttributes): String {
requirePermissions { populatePlantingSiteCountries() }

try {
plantingSiteStore.populateExistingSiteCountries()
systemUser.run { plantingSiteStore.populateExistingSiteCountries() }
redirectAttributes.successMessage = "Populated countries of existing planting sites"
} catch (e: Exception) {
redirectAttributes.failureMessage = "Failed to populate planting site countries: $e"
Expand Down

0 comments on commit c3b5abb

Please sign in to comment.