Commit b8b43dc2 authored by Rafael Ravedutti's avatar Rafael Ravedutti

Allow removal of city halls

Signed-off-by: Rafael Ravedutti's avatarRafael Ravedutti <rrlmachado@inf.ufpr.br>
parent 6ac9e86d
Pipeline #16014 passed with stages
in 4 minutes and 47 seconds
......@@ -95,16 +95,30 @@ module Api::V1
end
# DELETE /city_halls/1
#def destroy
# if @city_hall.nil?
# render json: {
# errors: ["City hall #{params[:id]} does not exist."]
# }, status: 404
# else
# @city_hall.active = false
# @city_hall.save!
# end
#end
def destroy
if @city_hall.nil?
render json: {
errors: ["City hall #{params[:id]} does not exist."]
}, status: 404
else
begin
authorize @city_hall, :destroy?
rescue
render json: {
errors: ["You're not allowed to destroy this city hall."]
}, status: 403
return
end
@city_hall.active = false
if @city_hall.save!
render json: @city_hall, status: :ok
else
render json: @city_hall.errors, status: :unprocessable_entity
end
end
end
# GET /city_hall/1/picture
def picture
......
......@@ -125,7 +125,7 @@ class CityHall < ApplicationRecord
def create_city_hall
address = Address.get_address(self.cep)
self.active = true
# self.active = true
if not address.nil?
self.city_id = address.city_id
self.address_street = address.address
......
......@@ -64,6 +64,15 @@ class CityHallPolicy < ApplicationPolicy
return picture_access_policy(user)
end
def destroy?
permission = Professional.get_permission(user[1])
if permission == "adm_c3sl"
return true
end
return false
end
private
......
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