Class: Event

Inherits:
ApplicationRecord show all
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

Has many collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Attribute Details

#country_codeString

Returns:

  • (String)

Validations:



25
# File 'app/models/event.rb', line 25

validates :name, :start_date, :end_date, :country_code, presence: true

#created_atDateTime

Returns:

  • (DateTime)


111
# File 'db/schema.rb', line 111

t.datetime "created_at"

#descriptionText

Returns:

  • (Text)


105
# File 'db/schema.rb', line 105

t.text "description"

#end_dateDate

Returns:

  • (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

#nameString

Returns:

  • (String)

Validations:



25
# File 'app/models/event.rb', line 25

validates :name, :start_date, :end_date, :country_code, presence: true

#reimbursement_creation_deadlineDateTime

Returns:

  • (DateTime)


115
# File 'db/schema.rb', line 115

t.datetime "reimbursement_creation_deadline"

#request_creation_deadlineDateTime

Returns:

  • (DateTime)


114
# File 'db/schema.rb', line 114

t.datetime "request_creation_deadline"

#shipment_typeString

Returns:

  • (String)


117
# File 'db/schema.rb', line 117

t.string "shipment_type"

#start_dateDate

Returns:

  • (Date)

Validations:



25
# File 'app/models/event.rb', line 25

validates :name, :start_date, :end_date, :country_code, presence: true

#updated_atDateTime

Returns:

  • (DateTime)


112
# File 'db/schema.rb', line 112

t.datetime "updated_at"

#urlString

Returns:

  • (String)


107
# File 'db/schema.rb', line 107

t.string "url"

#validatedBoolean

Returns:

  • (Boolean)


110
# File 'db/schema.rb', line 110

t.boolean "validated"

#visa_lettersBoolean

Returns:

  • (Boolean)


113
# File 'db/schema.rb', line 113

t.boolean "visa_letters"

Class Method Details

.validation_attributesArray

List of attributed that can only by accessed by users who have validation permissions on the event.

Returns:

  • (Array)

    a list of the restricted attribute names as symbols



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

Returns:

  • (Boolean)

    true if accepting new reimbursements



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

Returns:

  • (Boolean)

    true if accepting new requests



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

Returns:

  • (Boolean)

    true if accepting new shipments



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

#budgetBudget

Budget to use as a limit for approved amounts

Returns:

See Also:



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.

Returns:

  • (Boolean)

    true if allowed



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.

Returns:

  • (Boolean)

    true if any user can modify the object, false if only authorized users can do it



36
37
38
# File 'app/models/event.rb', line 36

def editable_by_requesters?
  !validated
end

#event_emailsActiveRecord::Relation<EventEmail>

Mails for an event

Returns:

See Also:



19
# File 'app/models/event.rb', line 19

has_many :event_emails

#event_organizersActiveRecord::Relation<EventOrganizer>

Event Organizers for the event

Returns:

See Also:



21
# File 'app/models/event.rb', line 21

has_many :event_organizers

#requestsActiveRecord::Relation<Request>

Requests for attending the event

Returns:

  • (ActiveRecord::Relation<Request>)

See Also:



13
# File 'app/models/event.rb', line 13

has_many :requests, inverse_of: :event, dependent: :restrict_with_exception

#shipmentsActiveRecord::Relation<Shipment>

Shipment requests for merchandising

Returns:

See Also:



15
# File 'app/models/event.rb', line 15

has_many :shipments, inverse_of: :event, dependent: :restrict_with_exception

#travel_sponsorshipsActiveRecord::Relation<TravelSponsorship>

Travel requests for an event

Returns:

See Also:



17
# File 'app/models/event.rb', line 17

has_many :travel_sponsorships, inverse_of: :event, dependent: :restrict_with_exception