Skip to content

Commit

Permalink
Record file downloads for completed forms and service forms
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 19, 2024
1 parent 1b7e6c5 commit caacb6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def process_action(*args)
head :not_acceptable
end

def record_file_download(attachment)
::Analytics::FileDownload.create(
user: current_user,
record: attachment.record,
name: attachment.name,
filename: attachment.filename,
byte_size: attachment.byte_size,
)
end

def route_not_found
raise ::ActionController::RoutingError, "Route does not exist"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def attach_completed_form
def download_completed_form
if @service_detail.completed_form.attached?
redirect_to @service_detail.completed_form.url(disposition: :attachment), allow_other_host: true
record_file_download(@service_detail.completed_form)
else
redirect_to organization_lottery_entrant_service_detail_path(@organization, @lottery, @service_detail),
notice: "No completed service form is attached"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lotteries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def attach_service_form
# GET /organizations/:organization_id/lotteries/:id/download_service_form
def download_service_form
if @lottery.service_form.attached?
@lottery.increment!(:service_form_download_count)
redirect_to @lottery.service_form.url(disposition: :attachment), allow_other_host: true
record_file_download(@lottery.service_form)
else
redirect_to setup_organization_lottery_path(@organization, @lottery), notice: "No service form is attached"
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/analytics/file_download.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class Analytics::FileDownload < ApplicationRecord
belongs_to :user
belongs_to :record, polymorphic: true
end

0 comments on commit caacb6e

Please sign in to comment.