Commit b7a585ad authored by Rafael Ravedutti's avatar Rafael Ravedutti

Allow C3SL administrator to upload citizens from any city

Signed-off-by: Rafael Ravedutti's avatarRafael Ravedutti <rrlmachado@inf.ufpr.br>
parent 86d2866b
Pipeline #16435 passed with stages
in 5 minutes and 38 seconds
......@@ -84,6 +84,9 @@ module Api::V1
# Current citizen id
citizen_id = citizen[:id]
# Permission
permission = Professional.get_permission(current_user[1])
# City for current permission
city_id = citizen.professional.professionals_service_places.find(
current_user[1]).service_place.city_id
......@@ -114,7 +117,7 @@ module Api::V1
upload_object.save()
# Create sidekiq job for uploading the citizens
CitizenUploadWorker.perform_async(upload_object.id, content, city_id)
CitizenUploadWorker.perform_async(upload_object.id, content, permission, city_id)
render json: {
errors: ["Citizens scheduled to be imported!"]
......
......@@ -3,7 +3,7 @@ class CitizenUploadWorker
require 'csv'
sidekiq_options :queue => :citizens_upload
def perform(upload_id, content, city_id)
def perform(upload_id, content, permission, city_id)
# Batch size for upload
batch_size = 100
......@@ -72,7 +72,7 @@ class CitizenUploadWorker
# Citizen remaining info is added when .valid? method is called
if citizen.valid? and account.valid?
if citizen.city_id != city_id
if permission != "adm_c3sl" and citizen.city_id != city_id
# If there was a permission error, store it in the errors hash
errors[line_number.to_s] = "Permission denied for this city!"
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment