Showing survey for users and handling authorization

This commit is contained in:
Shyukri Shyukriev 2016-06-30 13:04:07 +02:00
parent 9ce4ba6f6b
commit 67bccf0195
6 changed files with 44 additions and 6 deletions

View file

@ -0,0 +1,13 @@
class SurveyController < ApplicationController
load_resource :conference, find_by: :short_title
load_and_authorize_resource
def show
end
def reply
end
end

View file

@ -92,6 +92,9 @@ class Ability
# can manage the commercials of their own events # can manage the commercials of their own events
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id) 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)
end end
# Abilities for signed in users with roles # Abilities for signed in users with roles

View file

@ -14,11 +14,12 @@
choices ) choices )
- if survey_question.mandatory - if survey_question.mandatory
%span.fa.fa-asterisk.text-danger %span.fa.fa-asterisk.text-danger
%p.pull-right - if can? :edit, @survey
= link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do %p.pull-right
%span.fa.fa-edit = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do
= link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do %span.fa.fa-edit
%span.fa.fa-times = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do
%span.fa.fa-times
.panel-body .panel-body
- if survey_question.boolean? - if survey_question.boolean?
%input{type: 'radio', name: 'radio'} %input{type: 'radio', name: 'radio'}

View file

@ -48,7 +48,7 @@
%ul %ul
- @conference.surveys.for_registration.each do |survey| - @conference.surveys.for_registration.each do |survey|
%li %li
= link_to survey.title, "#" = link_to survey.title, conference_survey_path(@conference.short_title, survey)
- if @registration.events.any? - if @registration.events.any?
.row .row

View file

@ -0,0 +1,18 @@
.row
.col-md-12
.page-header
%h1
Survey #{@survey.title}
- if can? :edit, @survey
= link_to 'Edit Survey', admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right'
%p.text-muted
From:
= @survey.start_date
to
= @survey.end_date
.row
.col-md-12
- @survey.survey_questions.each.with_index(1) do |survey_question, index|
.row
.col-md-12
= render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index }

View file

@ -96,6 +96,9 @@ Osem::Application.routes.draw do
end end
resources :conference, only: [:index, :show] do resources :conference, only: [:index, :show] do
resources :survey, only: [:show] do
post :reply
end
resource :program, only: [] do resource :program, only: [] do
resources :proposal, except: :destroy do resources :proposal, except: :destroy do
get 'commercials/render_commercial' => 'commercials#render_commercial' get 'commercials/render_commercial' => 'commercials#render_commercial'