mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
[bug] unable to add a file attachment to an event
This commit is contained in:
parent
8fab578615
commit
7a317b7e45
@ -7,6 +7,7 @@
|
||||
- Notify an user if the available disk space reaches a configured threshold
|
||||
- Invoices generated outside of production environment will be watermarked
|
||||
- Keep track of currently logged user on each generated invoice
|
||||
- Fix a bug: unable to add a file attachment to an event
|
||||
- Fix a security issue: updated to devise 4.6.0 to fix [CVE-2019-5421](https://github.com/plataformatec/devise/issues/4981)
|
||||
- Fix a security issue: updated Rails to 4.2.11.1 to fix [CVE-2019-5418](https://groups.google.com/forum/#!topic/rubyonrails-security/pFRKI96Sm8Q) and [CVE-2019-5419](https://groups.google.com/forum/#!topic/rubyonrails-security/GN7w9fFAQeI)
|
||||
- Removed deprecated Capistrano deployment system
|
||||
|
@ -96,7 +96,7 @@ class API::EventsController < API::ApiController
|
||||
:recurrence_end_at, :category_id, :event_theme_ids, :age_range_id,
|
||||
event_theme_ids: [],
|
||||
event_image_attributes: [:attachment],
|
||||
event_files_attributes: %i[id attachment_destroy],
|
||||
event_files_attributes: %i[id attachment _destroy],
|
||||
event_price_categories_attributes: %i[id price_category_id amount _destroy])
|
||||
EventService.process_params(event_preparams)
|
||||
end
|
||||
|
@ -1,5 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Event PDF attachements
|
||||
class EventFile < Asset
|
||||
mount_uploader :attachment, ProjectCaoUploader
|
||||
mount_uploader :attachment, EventFileUploader
|
||||
|
||||
validates :attachment, file_size: { maximum: 20.megabytes.to_i }
|
||||
end
|
||||
|
52
app/uploaders/event_file_uploader.rb
Normal file
52
app/uploaders/event_file_uploader.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# CarrierWave uploader for event attachments
|
||||
class EventFileUploader < CarrierWave::Uploader::Base
|
||||
# Include RMagick or MiniMagick support:
|
||||
# include CarrierWave::RMagick
|
||||
# include CarrierWave::MiniMagick
|
||||
include UploadHelper
|
||||
|
||||
# Choose what kind of storage to use for this uploader:
|
||||
storage :file
|
||||
after :remove, :delete_empty_dirs
|
||||
# storage :fog
|
||||
|
||||
# Override the directory where uploaded files will be stored.
|
||||
# This is a sensible default for uploaders that are meant to be mounted:
|
||||
def store_dir
|
||||
"#{base_store_dir}/#{model.id}"
|
||||
end
|
||||
|
||||
def base_store_dir
|
||||
"uploads/#{model.class.to_s.underscore}"
|
||||
end
|
||||
|
||||
# Provide a default URL as a default if there hasn't been a file uploaded:
|
||||
# def default_url
|
||||
# # For Rails 3.1+ asset pipeline compatibility:
|
||||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
||||
#
|
||||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||
# end
|
||||
|
||||
# Process files as they are uploaded:
|
||||
# process :scale => [200, 300]
|
||||
#
|
||||
# def scale(width, height)
|
||||
# # do something
|
||||
# end
|
||||
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
def extension_white_list
|
||||
%w[pdf]
|
||||
end
|
||||
|
||||
# Override the filename of the uploaded files:
|
||||
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
||||
# def filename
|
||||
# # "avatar.#{file.extension}" if original_filename
|
||||
# end
|
||||
end
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! event, :id, :title, :description, :age_range_id
|
||||
json.event_image event.event_image.attachment_url if event.event_image
|
||||
json.event_files_attributes event.event_files do |f|
|
||||
@ -6,18 +8,22 @@ json.event_files_attributes event.event_files do |f|
|
||||
json.attachment_url f.attachment_url
|
||||
end
|
||||
json.category_id event.category_id
|
||||
json.category do
|
||||
json.id event.category.id
|
||||
json.name event.category.name
|
||||
end if event.category
|
||||
if event.category
|
||||
json.category do
|
||||
json.id event.category.id
|
||||
json.name event.category.name
|
||||
end
|
||||
end
|
||||
json.event_theme_ids event.event_theme_ids
|
||||
json.event_themes event.event_themes do |e|
|
||||
json.name e.name
|
||||
end
|
||||
json.age_range_id event.age_range_id
|
||||
json.age_range do
|
||||
json.name event.age_range.name
|
||||
end if event.age_range
|
||||
if event.age_range
|
||||
json.age_range do
|
||||
json.name event.age_range.name
|
||||
end
|
||||
end
|
||||
json.start_date event.availability.start_at
|
||||
json.start_time event.availability.start_at
|
||||
json.end_date event.availability.end_at
|
||||
@ -25,7 +31,7 @@ json.end_time event.availability.end_at
|
||||
json.month t('date.month_names')[event.availability.start_at.month]
|
||||
json.month_id event.availability.start_at.month
|
||||
json.year event.availability.start_at.year
|
||||
json.all_day event.availability.start_at.hour == 0 ? 'true' : 'false'
|
||||
json.all_day event.availability.start_at.hour.zero? ? 'true' : 'false'
|
||||
json.availability do
|
||||
json.id event.availability.id
|
||||
json.start_at event.availability.start_at
|
||||
|
Loading…
x
Reference in New Issue
Block a user