feat: Add match edit and update actions with authorization
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EuchreCamp
|
||||
module Actions
|
||||
module Admin
|
||||
module Matches
|
||||
class Edit < EuchreCamp::Action
|
||||
include Deps[matches_repo: 'repositories.matches', players_repo: 'repositories.players']
|
||||
|
||||
def handle(request, response)
|
||||
match_id = request.params[:id]
|
||||
match = matches_repo.by_id(match_id)
|
||||
user = current_user(request)
|
||||
|
||||
# Check authorization
|
||||
if user
|
||||
# Check if user can edit this match (within 5 minutes or admin)
|
||||
unless EuchreCamp::Services::Authorization.can?(user, :edit_own_match_within_5_min, match) ||
|
||||
EuchreCamp::Services::Authorization.can?(user, :edit_any_record)
|
||||
response.flash[:error] = 'Match cannot be edited (too old or insufficient permissions)'
|
||||
response.redirect_to '/admin/matches'
|
||||
return
|
||||
end
|
||||
else
|
||||
response.flash[:error] = 'Please login to edit matches'
|
||||
response.redirect_to '/login'
|
||||
return
|
||||
end
|
||||
|
||||
# Get available players for the form
|
||||
all_players = players_repo.all
|
||||
|
||||
render_with_player(request, response,
|
||||
match: match,
|
||||
all_players: all_players
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user