From c3b5abbb4bebc9f7c8e73aad25eaa01b204e5adc Mon Sep 17 00:00:00 2001 From: Steven Grimm <1248649+sgrimm@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:21:15 -0800 Subject: [PATCH] SW-6182 Populate planting site countries as system user (#2565) The admin UI function to populate the countries of existing planting sites added in commit d2cfe32e 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. --- .../backend/admin/AdminPlantingSitesController.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt b/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt index c34f155d2865..492f4cbe39b6 100644 --- a/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt +++ b/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt @@ -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 @@ -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() @@ -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"