Class: Event
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Event
- Defined in:
- app/models/event.rb
Overview
Event is, in some way, the root of the model's hierarchy since any Request and any Reimbursement are always associated with an event
Most attributes are self-explanatory except, maybe, the one boolean called 'validated'. This attribute is used to control which users can create, update and destroy the event.
Instance Attribute Summary collapse
- #country_code ⇒ String
- #created_at ⇒ DateTime
- #description ⇒ Text
- #end_date ⇒ Date
- #name ⇒ String
- #reimbursement_creation_deadline ⇒ DateTime
- #request_creation_deadline ⇒ DateTime
- #shipment_type ⇒ String
- #start_date ⇒ Date
- #updated_at ⇒ DateTime
- #url ⇒ String
- #validated ⇒ Boolean
- #visa_letters ⇒ Boolean
Has many collapse
-
#event_emails ⇒ ActiveRecord::Relation<EventEmail>
Mails for an event.
-
#event_organizers ⇒ ActiveRecord::Relation<EventOrganizer>
Event Organizers for the event.
-
#requests ⇒ ActiveRecord::Relation<Request>
Requests for attending the event.
-
#shipments ⇒ ActiveRecord::Relation<Shipment>
Shipment requests for merchandising.
-
#travel_sponsorships ⇒ ActiveRecord::Relation<TravelSponsorship>
Travel requests for an event.
Belongs to collapse
-
#budget ⇒ Budget
Budget to use as a limit for approved amounts.
Class Method Summary collapse
-
.validation_attributes ⇒ Array
List of attributed that can only by accessed by users who have validation permissions on the event.
Instance Method Summary collapse
-
#accepting_reimbursements? ⇒ Boolean
Check if new reimbursements can be created based on reimbursement_creation_deadline.
-
#accepting_requests? ⇒ Boolean
Check if new requests can be created based on request_creation_deadline and start_date.
-
#accepting_shipments? ⇒ Boolean
Check if new shipment can be created based on shipment_type and start_date.
-
#can_be_destroyed? ⇒ Boolean
Checks whether a user should be allowed to completely delete the event.
-
#editable_by_requesters? ⇒ Boolean
Checks whether the event can be freely updated or destroyed by all users.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes
Instance Attribute Details
#country_code ⇒ String
Validations:
25 |
# File 'app/models/event.rb', line 25 validates :name, :start_date, :end_date, :country_code, presence: true |
#created_at ⇒ DateTime
111 |
# File 'db/schema.rb', line 111 t.datetime "created_at" |
#description ⇒ Text
105 |
# File 'db/schema.rb', line 105 t.text "description" |
#end_date ⇒ Date
Validations:
- Presence
- Date ({ after_or_equal_to: :start_date })
25 |
# File 'app/models/event.rb', line 25 validates :name, :start_date, :end_date, :country_code, presence: true |
#name ⇒ String
Validations:
25 |
# File 'app/models/event.rb', line 25 validates :name, :start_date, :end_date, :country_code, presence: true |
#reimbursement_creation_deadline ⇒ DateTime
115 |
# File 'db/schema.rb', line 115 t.datetime "reimbursement_creation_deadline" |
#request_creation_deadline ⇒ DateTime
114 |
# File 'db/schema.rb', line 114 t.datetime "request_creation_deadline" |
#shipment_type ⇒ String
117 |
# File 'db/schema.rb', line 117 t.string "shipment_type" |
#start_date ⇒ Date
Validations:
25 |
# File 'app/models/event.rb', line 25 validates :name, :start_date, :end_date, :country_code, presence: true |
#updated_at ⇒ DateTime
112 |
# File 'db/schema.rb', line 112 t.datetime "updated_at" |
#url ⇒ String
107 |
# File 'db/schema.rb', line 107 t.string "url" |
#validated ⇒ Boolean
110 |
# File 'db/schema.rb', line 110 t.boolean "validated" |
#visa_letters ⇒ Boolean
113 |
# File 'db/schema.rb', line 113 t.boolean "visa_letters" |
Class Method Details
.validation_attributes ⇒ Array
List of attributed that can only by accessed by users who have validation permissions on the event.
94 95 96 |
# File 'app/models/event.rb', line 94 def self.validation_attributes %i[validated visa_letters request_creation_deadline reimbursement_creation_deadline shipment_type] end |
Instance Method Details
#accepting_reimbursements? ⇒ Boolean
Check if new reimbursements can be created based on reimbursement_creation_deadline
68 69 70 71 72 73 74 |
# File 'app/models/event.rb', line 68 def accepting_reimbursements? if reimbursement_creation_deadline Time.zone.now < reimbursement_creation_deadline else true end end |
#accepting_requests? ⇒ Boolean
Check if new requests can be created based on request_creation_deadline and start_date
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/event.rb', line 51 def accepting_requests? return false unless Rails.configuration.site['travel_sponsorships']['enabled'] if request_creation_deadline Time.zone.now < request_creation_deadline else begin (Date.today < start_date) rescue false end end end |
#accepting_shipments? ⇒ Boolean
Check if new shipment can be created based on shipment_type and start_date
80 81 82 83 84 85 86 87 88 |
# File 'app/models/event.rb', line 80 def accepting_shipments? return false unless Rails.configuration.site['shipments']['enabled'] begin (!shipment_type.blank? && Date.today < start_date) rescue false end end |
#budget ⇒ Budget
Budget to use as a limit for approved amounts
23 |
# File 'app/models/event.rb', line 23 belongs_to :budget, optional: true |
#can_be_destroyed? ⇒ Boolean
Checks whether a user should be allowed to completely delete the event.
43 44 45 |
# File 'app/models/event.rb', line 43 def can_be_destroyed? requests.empty? && shipments.empty? end |
#editable_by_requesters? ⇒ Boolean
Checks whether the event can be freely updated or destroyed by all users.
36 37 38 |
# File 'app/models/event.rb', line 36 def editable_by_requesters? !validated end |
#event_emails ⇒ ActiveRecord::Relation<EventEmail>
Mails for an event
19 |
# File 'app/models/event.rb', line 19 has_many :event_emails |
#event_organizers ⇒ ActiveRecord::Relation<EventOrganizer>
Event Organizers for the event
21 |
# File 'app/models/event.rb', line 21 has_many :event_organizers |
#requests ⇒ ActiveRecord::Relation<Request>
Requests for attending the event
13 |
# File 'app/models/event.rb', line 13 has_many :requests, inverse_of: :event, dependent: :restrict_with_exception |
#shipments ⇒ ActiveRecord::Relation<Shipment>
Shipment requests for merchandising
15 |
# File 'app/models/event.rb', line 15 has_many :shipments, inverse_of: :event, dependent: :restrict_with_exception |
#travel_sponsorships ⇒ ActiveRecord::Relation<TravelSponsorship>
Travel requests for an event
17 |
# File 'app/models/event.rb', line 17 has_many :travel_sponsorships, inverse_of: :event, dependent: :restrict_with_exception |