Skip to content

Commit

Permalink
Ticket Request logical delete + CSV generation
Browse files Browse the repository at this point in the history
 * With RSpecs
  • Loading branch information
kigster committed May 17, 2024
1 parent 73823b9 commit c0207bf
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 154 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ group :test do
gem 'timecop'
gem 'timeout'
end

gem 'paranoia', '~> 2.6'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ GEM
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.24.0)
paranoia (2.6.3)
activerecord (>= 5.1, < 7.2)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
Expand Down Expand Up @@ -504,6 +506,7 @@ DEPENDENCIES
mini_magick
mini_racer
newrelic_rpm
paranoia (~> 2.6)
pg
propshaft
protected_attributes_continued
Expand Down
25 changes: 14 additions & 11 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ def index
end

def download
temp_csv = Tempfile.new('csv')
csv_file = Tempfile.new('csv')

raise ArgumentError('Tempfile is nil') if temp_csv.nil? || temp_csv.path.nil?

CSV.open(temp_csv.path, 'wb') do |csv|
csv << (%w[name email] + TicketRequest.columns.map(&:name))
TicketRequest.where(event_id: @event).find_each do |ticket_request|
csv << ([ticket_request.user.name, ticket_request.user.email] +
ticket_request.attributes.values)
CSV.open(csv_file.path, 'w',
write_headers: true,
headers: TicketRequest.csv_header) do |csv|
TicketRequest.for_csv(@event).each do |row|
csv << row
end
end

temp_csv.close
send_file(temp_csv.path,
filename: "#{@event.name} Ticket Requests.csv",
send_file(csv_file.path,
filename: "#{@event.to_param}-ticket-requests.csv",
type: 'text/csv')
rescue StandardError => e
flash.now[:error] = "Error creating CSV file: #{e.message}"
render_flash(flash)
end

def show
Expand Down Expand Up @@ -189,7 +189,10 @@ def update
end

def destroy
Rails.logger.error("destroy# params: #{permitted_params}".colorize(:yellow))

unless @event.admin?(current_user) || current_user == @ticket_request.user
Rails.logger.error("ATTEMPT TO DELETE TICKET REQUEST #{@ticket_request} by #{current_user}".colorize(:red))
flash.now[:error] = 'You do not have sufficient privileges to delete this request.'
return render_flash(flash)
end
Expand Down
12 changes: 8 additions & 4 deletions app/models/eald_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
#
# Table name: eald_payments
#
# id :integer not null, primary key
# id :bigint not null, primary key
# amount_charged_cents :integer not null
# early_arrival_passes :integer default(0), not null
# email :string(255) not null
# late_departure_passes :integer default(0), not null
# name :string(255) not null
# created_at :datetime
# updated_at :datetime
# event_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# event_id :bigint
# stripe_charge_id :string not null
#
# Indexes
#
# index_eald_payments_on_event_id (event_id)
#
class EaldPayment < ApplicationRecord
include PaymentsHelper

Expand Down
10 changes: 5 additions & 5 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Table name: events
#
# id :integer not null, primary key
# id :bigint not null, primary key
# adult_ticket_price :decimal(8, 2)
# allow_donations :boolean default(FALSE), not null
# allow_financial_assistance :boolean default(FALSE), not null
Expand All @@ -17,17 +17,17 @@
# max_cabin_requests :integer
# max_cabins_per_request :integer
# max_kid_tickets_per_request :integer
# name :string(255)
# photo :string(255)
# name :string
# photo :string
# require_mailing_address :boolean default(FALSE), not null
# slug :text
# start_time :datetime
# ticket_requests_end_time :datetime
# ticket_sales_end_time :datetime
# ticket_sales_start_time :datetime
# tickets_require_approval :boolean default(TRUE), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
class Event < ApplicationRecord
has_many :event_admins
Expand Down
10 changes: 5 additions & 5 deletions app/models/event_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#
# Table name: event_admins
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# event_id :integer
# user_id :integer
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# event_id :bigint
# user_id :bigint
#
# Indexes
#
Expand Down
12 changes: 8 additions & 4 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#
# Table name: jobs
#
# id :integer not null, primary key
# id :bigint not null, primary key
# description :string(512) not null
# name :string(100) not null
# created_at :datetime
# updated_at :datetime
# event_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# event_id :bigint not null
#
# Indexes
#
# index_jobs_on_event_id (event_id)
#
class Job < ApplicationRecord
belongs_to :event
Expand Down
8 changes: 4 additions & 4 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#
# Table name: payments
#
# id :integer not null, primary key
# explanation :string(255)
# id :bigint not null, primary key
# explanation :string
# status :string(1) default("N"), not null
# created_at :datetime
# updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# stripe_charge_id :string(255)
# stripe_payment_id :string
# ticket_request_id :integer not null
Expand Down
10 changes: 5 additions & 5 deletions app/models/price_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#
# Table name: price_rules
#
# id :integer not null, primary key
# id :bigint not null, primary key
# price :decimal(8, 2)
# trigger_value :integer
# type :string(255)
# created_at :datetime
# updated_at :datetime
# event_id :integer
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# event_id :bigint
#
# Indexes
#
Expand Down
10 changes: 5 additions & 5 deletions app/models/price_rule/kids_equal_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#
# Table name: price_rules
#
# id :integer not null, primary key
# id :bigint not null, primary key
# price :decimal(8, 2)
# trigger_value :integer
# type :string(255)
# created_at :datetime
# updated_at :datetime
# event_id :integer
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# event_id :bigint
#
# Indexes
#
Expand Down
15 changes: 10 additions & 5 deletions app/models/shift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
#
# Table name: shifts
#
# id :integer not null, primary key
# id :bigint not null, primary key
# name :string(70)
# created_at :datetime
# updated_at :datetime
# time_slot_id :integer not null
# user_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# time_slot_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_shifts_on_time_slot_id (time_slot_id)
# index_shifts_on_user_id (user_id)
#
class Shift < ApplicationRecord
belongs_to :time_slot
Expand Down
6 changes: 3 additions & 3 deletions app/models/site_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
# Table name: site_admins
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
#
class SiteAdmin < ApplicationRecord
Expand Down
Loading

0 comments on commit c0207bf

Please sign in to comment.