Skip to content

Commit

Permalink
map delete button for personal maps
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Feb 2, 2025
1 parent 2decd81 commit 06a4de5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/controllers/maps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class MapsController < ApplicationController
before_action :set_global_js_values, only: %i[show]
before_action :set_map, only: %i[show properties destroy]
before_action :require_login, only: %i[my]
before_action :require_map_owner, only: %i[destroy]

layout "map", only: [ :show ]

Expand Down Expand Up @@ -58,16 +59,16 @@ def catchall
# :nocov:

def destroy
if @user&.admin? || (@map.user && @map.user == @user)
@map.destroy!
redirect_to admin_path, status: :see_other, notice: "Map was deleted."
else
redirect_to root_path
end
@map.destroy!
redirect_to my_path, status: :see_other, notice: "Map was deleted."
end

private

def require_map_owner
redirect_to maps_path unless @user&.admin? || (@map.user && @map.user == @user)
end

def set_global_js_values
gon.map_keys = Map.provider_keys
end
Expand Down

0 comments on commit 06a4de5

Please sign in to comment.