Add more options for surveys
* Survey period constraints * Add abilities * Enforce required questions * Update survey_submssion updated_at * Do a full match of possible answer and user reply
This commit is contained in:
parent
c278e547ce
commit
683f62a27c
36 changed files with 219 additions and 74 deletions
|
|
@ -55,6 +55,8 @@ class Ability
|
|||
can [:show, :events], Schedule do |schedule|
|
||||
schedule.program.schedule_public
|
||||
end
|
||||
|
||||
can [:index, :show], Survey, surveyable_type: 'Conference'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -104,8 +106,18 @@ class Ability
|
|||
# can manage the commercials of their own events
|
||||
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
||||
|
||||
# can view and reply a survey
|
||||
can [:show, :reply], Survey, surveyable_type: 'Conference', surveyable_id: user.registrations.pluck(:conference_id)
|
||||
# can view and reply to a survey
|
||||
can [:index, :show, :reply], Survey, surveyable_type: 'Conference'
|
||||
can [:index, :show, :reply], Survey, surveyable_type: 'Registration', surveyable_id: user.registrations.pluck(:conference_id)
|
||||
|
||||
# TODO: this needs to check for more, eg.
|
||||
# if survey target is after_conference, check whether or not the conference is over
|
||||
# if not, do not allow replies.
|
||||
|
||||
# do not allow replies before the start_date or after the end_date of survey
|
||||
cannot :reply, Survey do |survey|
|
||||
survey.start_date > Time.current || survey.end_date < Time.current
|
||||
end
|
||||
|
||||
can [:destroy], Openid
|
||||
|
||||
|
|
|
|||
|
|
@ -1235,4 +1235,3 @@ class Conference < ApplicationRecord
|
|||
result
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/ClassLength
|
||||
|
|
|
|||
|
|
@ -268,6 +268,18 @@ class Event < ApplicationRecord
|
|||
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns true or false, if the event is already over or not
|
||||
#
|
||||
# ====Returns
|
||||
# * +true+ -> If the event is over
|
||||
# * +false+ -> If the event is not over yet
|
||||
def ended?
|
||||
event_schedule = event_schedules.find_by(schedule_id: selected_schedule_id)
|
||||
return false unless event_schedule
|
||||
event_schedule.end_time < Time.current
|
||||
end
|
||||
|
||||
def conference
|
||||
program.conference
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Survey < ActiveRecord::Base
|
||||
belongs_to :surveyable, polymorphic: true
|
||||
has_many :survey_questions
|
||||
has_many :survey_submissions
|
||||
has_many :survey_questions, dependent: :destroy
|
||||
has_many :survey_submissions, dependent: :destroy
|
||||
|
||||
enum target: [:after_conference, :during_registration]
|
||||
validates :title, presence: true
|
||||
|
||||
def active?
|
||||
return false unless start_date && end_date
|
||||
now = Time.now.in_time_zone(surveyable.timezone)
|
||||
now >= start_date && now <= end_date
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SurveyQuestion < ActiveRecord::Base
|
||||
belongs_to :survey
|
||||
has_many :survey_replies
|
||||
has_many :survey_replies, dependent: :destroy
|
||||
|
||||
# Order of this list should not be changed without proper action!
|
||||
enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric]
|
||||
|
|
@ -23,15 +25,15 @@ class SurveyQuestion < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def possible_answers=(value)
|
||||
self[:possible_answers] = choice? ? value : nil
|
||||
self[:possible_answers] = value if choice?
|
||||
end
|
||||
|
||||
def min_choices=(value)
|
||||
self[:min_choices] = choice? ? value : nil
|
||||
self[:min_choices] = value if choice?
|
||||
end
|
||||
|
||||
def max_choices=(value)
|
||||
self[:max_choices] = choice? ? value : nil
|
||||
self[:max_choices] = value if choice?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SurveyReply < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey_question
|
||||
serialize :text
|
||||
|
||||
validates :user_id, :survey_question_id, presence: true
|
||||
validates :survey_question_id, uniqueness: { scope: :user_id }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SurveySubmission < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue