AutoCommit Mon Aug 10 13:03:04 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-10 13:03:04 +02:00
parent cb73bbfa43
commit 3835c0e773
6 changed files with 115 additions and 107 deletions

View File

@@ -33,6 +33,7 @@ class Survey::QuestionsController < ApplicationController
@template = Survey::Question.find(params[:id])
parent= params[:parent_type].constantize.find(params[:parent_id])
@survey_question = @template.copy_from_template_for(parent)
@survey_question.user=current_user
render action: :show
end
@@ -64,7 +65,7 @@ class Survey::QuestionsController < ApplicationController
# POST /survey/questions.json
def create
@survey_question = Survey::Question.new(params[:survey_question])
@survey_question.user=current_user
respond_to do |format|
if @survey_question.save
format.html { redirect_to @survey_question, notice: 'Question was successfully created.' }
@@ -78,7 +79,8 @@ class Survey::QuestionsController < ApplicationController
# PUT /survey/questions/1.json
def update
@survey_question = Survey::Question.find(params[:id])
@survey_question.user=current_user
@survey_question.save
respond_to do |format|
if @survey_question.update_attributes(params[:survey_question])
format.html { redirect_to @survey_question, notice: 'Question was successfully updated.' }

View File

@@ -11,10 +11,17 @@ class Ability
end
user ||= User.new # guest user (not logged in)
can :manage, Survey::Question
can :manage, Survey::Choice
if( user.has_role?("fetuser") || user.has_role?("fetadmin"))
can [:show,:answer, :create,:new, :create_from_template, :flag], Survey::Question
can [:edit, :update, :flag_delete], Survey::Question, :flag_locked=>false
can :flag_locked, Survey::Question, :user_id=>user.id
can [:show,:new], Survey::Choice
can [:edit,:update, :delete,:create], Survey::Choice, :question=>{:flag_locked=>false}
can :manage, Survey::Answer
end
if user.has_role?("fetadmin")
can [:delete,:flag_template], Survey::Question
end
#---------------------------------------------------
can [:index,:hide], Comment

View File

@@ -5,11 +5,11 @@ class Survey::Question < ActiveRecord::Base
has_many :choices, dependent: :destroy, class_name: "Survey::Choice"
has_many :answers, through: :choices
include IsCommentable
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1","locked"=>"fa fa-key"}
FLAG_CONFIRM={"delete"=> "Sicher loeschen?"}
scope :templates, ->{ where(flag_template: true)}
acts_as_flagable
belongs_to :user
def copy_from_template_for(parent)
unless self.flag_template
return nil

View File

@@ -1,10 +1,12 @@
<%= content_for :header do %>
<title>Fetsite - <%= @lva.full_name %></title>
<% set_meta_tags :og => {
:url=>lva_path(:theme=>nil) }
:url=>lva_path(:theme=>nil)
}
%>
<%= display_meta_tags %>
<% end %>
<div itemscope itemtype="schema.org/Article" >
<div class="container-fluid">
<%= render 'studien/tabs'%>
@@ -15,7 +17,6 @@
<%= render 'layouts/pretty_toolbar' %>
</div>
</div>
<div class="row-fluid">
<div class="span8">
<h1 itemprop="name"><%= @lva.full_name %></h1>
@@ -58,12 +59,10 @@
<li><b><%= link_to modul.name , modul_path(modul)%></b>
<ul>
<% modul.modulgruppen.each do |g| %>
<li><%= link_to g.studium.title_context , studium_path(g.studium)%> (<%=link_to g.name, modulgruppe_path(g)%>)</li>
<% end %>
</ul>
</li>
<% end %>
</ul>
</div>
@@ -71,13 +70,10 @@
<h2> <%= I18n.t "lecturers.lecturers" %> </h2>
<% @lva.lecturers.each do |lec| %>
<%= render :partial=>'lecturers/lec_lva', :object=>lec %>
<% end %>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
@@ -86,7 +82,7 @@
</p>
<%= link_to t("beispiel.zip") , beispiel_sammlung_lva_path(@lva), class: :linkbox %>
<% @beispiele_all.each do |b| %>
<% cache("beispiel_" +I18n.locale.to_s+b.id.to_s+can?(:delete,b).to_s+"_"+can?(:edit,b).to_s + "_" + can?(:flag, b).to_s + "_" + can?(:like, b).to_s + "_" + b.updated_at.try(:utc).try(:to_s) + get_theme_help(current_user).to_s) do %>
<% cache("beispiel_" +I18n.locale.to_s+b.id.to_s+can?(:delete,b).to_s+"_"+can?(:edit,b).to_s + "_" + can?(:flag, b).to_s+ can?(:comment, b).to_s + "_" + can?(:like, b).to_s + "_" + b.updated_at.try(:utc).try(:to_s) + get_theme_help(current_user).to_s) do %>
<%= render b%>
<% end %>
<% end %>

View File

@@ -2,7 +2,7 @@
<%= div_tag_for(choice) do %>
<%
if current_user.nil?
unless can?(:answer,choice.question)
t=choice.text
else
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
@@ -13,7 +13,7 @@ end
%>
<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true
<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true if can? :edit, choice
%>
<%= link_to fa_icon("trash"), survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true , method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to fa_icon("trash"), survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true , method: :delete, data: { confirm: 'Are you sure?' } if can? :delete,choice %>
<% end %>

View File

@@ -1,4 +1,4 @@
<% if current_user.nil? %>
<% unless can?(:answer,question) %>
<%= div_tag_for(question) do%>
<%= render partial: "survey/questions/answeredquestion", object: question unless question.flag_delete%>
<% end %>
@@ -7,16 +7,19 @@
<div >
<b><%= question.title%></b>
<%= question.text %>
<%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true %>
<%= flag_link(question, "delete")%>
<%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true if can? :edit, question %>
<%= flag_link(question, "locked") %>
<%= flag_link(question, "template") %>
<%= flag_link(question, "delete") %>
<% unless question.flag_delete %>
<ul class="choice-list">
<% question.choices.each do |c| %>
<li><%= render c %></li>
<% end %>
</ul>
<%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true%>
<%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true if can? :edit, question %>
<% end %>
</div>
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0 unless question.flag_delete %>