Commit cc3284a0 authored by Rafael Ravedutti's avatar Rafael Ravedutti

Fix schedule index for citizens

Signed-off-by: Rafael Ravedutti's avatarRafael Ravedutti <rrlmachado@inf.ufpr.br>
parent b6a39567
Pipeline #17482 passed with stages
in 4 minutes and 2 seconds
...@@ -20,7 +20,7 @@ class SchedulePolicy < ApplicationPolicy ...@@ -20,7 +20,7 @@ class SchedulePolicy < ApplicationPolicy
permission = Professional.get_permission(user[1]) permission = Professional.get_permission(user[1])
if permission == "citizen" if permission == "citizen"
return nil return scope.where(citizen_id: citizen.id)
end end
professional = citizen.professional professional = citizen.professional
...@@ -29,7 +29,7 @@ class SchedulePolicy < ApplicationPolicy ...@@ -29,7 +29,7 @@ class SchedulePolicy < ApplicationPolicy
city_id = service_place.city_id city_id = service_place.city_id
city_hall_id = service_place.city_hall_id city_hall_id = service_place.city_hall_id
return case permission return case permission
when "adm_c3sl" when "adm_c3sl"
scope.all scope.all
...@@ -52,13 +52,13 @@ class SchedulePolicy < ApplicationPolicy ...@@ -52,13 +52,13 @@ class SchedulePolicy < ApplicationPolicy
end end
end end
def show? def show?
citizen = user[0] citizen = user[0]
permission = Professional.get_permission(user[1]) permission = Professional.get_permission(user[1])
if permission == "citizen" if permission == "citizen"
return ((record.citizen_id == citizen.id) or return ((record.citizen_id == citizen.id) or
(record.citizen.responsible_id == citizen.id)) (record.citizen.responsible_id == citizen.id))
end end
...@@ -75,11 +75,11 @@ class SchedulePolicy < ApplicationPolicy ...@@ -75,11 +75,11 @@ class SchedulePolicy < ApplicationPolicy
when permission == "adm_prefeitura" when permission == "adm_prefeitura"
return ((record.service_place.city_hall_id == service_place.city_hall_id)) return ((record.service_place.city_hall_id == service_place.city_hall_id))
when permission == "adm_local" when permission == "adm_local"
return ((record.service_place.id == service_place.id)) return ((record.service_place.id == service_place.id))
when permission == "atendendente_local" when permission == "atendendente_local"
return ((record.service_place.id == service_place.id)) return ((record.service_place.id == service_place.id))
when permission == "responsavel_atendimento" when permission == "responsavel_atendimento"
...@@ -117,7 +117,7 @@ class SchedulePolicy < ApplicationPolicy ...@@ -117,7 +117,7 @@ class SchedulePolicy < ApplicationPolicy
return ((record.service_place.id == service_place.id) and return ((record.service_place.id == service_place.id) and
(record.situation.description == "Agendado")) (record.situation.description == "Agendado"))
when permission == "atendendente_local" when permission == "atendendente_local"
return ((record.service_place.id == service_place.id) and return ((record.service_place.id == service_place.id) and
(record.situation.description == "Agendado")) (record.situation.description == "Agendado"))
...@@ -137,7 +137,7 @@ class SchedulePolicy < ApplicationPolicy ...@@ -137,7 +137,7 @@ class SchedulePolicy < ApplicationPolicy
# TODO: Check for permissions between schedule and citizen being scheduled. # TODO: Check for permissions between schedule and citizen being scheduled.
# It involves either the future relation between schedule and citizen or # It involves either the future relation between schedule and citizen or
# simply the location related to the shift which the schedule is related to. # simply the location related to the shift which the schedule is related to.
# (record.shift.service_place.city_id) # (record.shift.service_place.city_id)
# #
...@@ -157,7 +157,7 @@ class SchedulePolicy < ApplicationPolicy ...@@ -157,7 +157,7 @@ class SchedulePolicy < ApplicationPolicy
if permission == "citizen" if permission == "citizen"
dependants_ids = Citizen.where(responsible_id: citizen.id).pluck(:id) dependants_ids = Citizen.where(responsible_id: citizen.id).pluck(:id)
# Return false if the target is neither the current citizen nor one # Return false if the target is neither the current citizen nor one
# of his dependants # of his dependants
return (schedulee.id == citizen.id or (dependants_ids.include?(schedulee.id))) return (schedulee.id == citizen.id or (dependants_ids.include?(schedulee.id)))
end end
......
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