From 3835c0e773452e05a21d6cd1c4c7e7bffd0b644f Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 10 Aug 2015 13:03:04 +0200 Subject: [PATCH] AutoCommit Mon Aug 10 13:03:04 CEST 2015 --- .../survey/questions_controller.rb | 6 +- app/models/ability.rb | 15 +- app/models/survey/question.rb | 4 +- app/views/lvas/show.html.erb | 178 +++++++++--------- app/views/survey/choices/_choice.html.erb | 6 +- app/views/survey/questions/_question.html.erb | 13 +- 6 files changed, 115 insertions(+), 107 deletions(-) diff --git a/app/controllers/survey/questions_controller.rb b/app/controllers/survey/questions_controller.rb index b7cbad3..e6a96ce 100644 --- a/app/controllers/survey/questions_controller.rb +++ b/app/controllers/survey/questions_controller.rb @@ -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.' } diff --git a/app/models/ability.rb b/app/models/ability.rb index 324c256..6dfe69d 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -11,10 +11,17 @@ class Ability end user ||= User.new # guest user (not logged in) - can :manage, Survey::Question - can :manage, Survey::Choice - can :manage, Survey::Answer - + 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 diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index 26ad1b3..9500d05 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -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 diff --git a/app/views/lvas/show.html.erb b/app/views/lvas/show.html.erb index ce4a8e8..d4cb37f 100755 --- a/app/views/lvas/show.html.erb +++ b/app/views/lvas/show.html.erb @@ -1,10 +1,12 @@ <%= content_for :header do %> -Fetsite - <%= @lva.full_name %> -<% set_meta_tags :og => { - :url=>lva_path(:theme=>nil) } -%> -<%= display_meta_tags %> + Fetsite - <%= @lva.full_name %> + <% set_meta_tags :og => { + :url=>lva_path(:theme=>nil) + } + %> + <%= display_meta_tags %> <% end %> +
<%= render 'studien/tabs'%> @@ -12,115 +14,109 @@
- <%= render 'layouts/pretty_toolbar' %> + <%= render 'layouts/pretty_toolbar' %>
-
-

<%= @lva.full_name %>

- - -
-

<%= I18n.t('lva.pruefungsinfo')%>

-
- <%= @lva.pruefungsinformation.to_s.html_safe %> -
- -

<%= I18n.t('lva.lernaufwand')%>

-
- <%= @lva.lernaufwand %> -
- -

<%= I18n.t('lva.desc')%>

-
- <%= @lva.desc.to_s.html_safe %> -
-
+

<%= @lva.full_name %>

+ + +
+

<%= I18n.t('lva.pruefungsinfo')%>

+
+ <%= @lva.pruefungsinformation.to_s.html_safe %> +
+ +

<%= I18n.t('lva.lernaufwand')%>

+
+ <%= @lva.lernaufwand %> +
+ +

<%= I18n.t('lva.desc')%>

+
+ <%= @lva.desc.to_s.html_safe %> +
+
-
-
    -
  • <%= I18n.t('lva.lvanr')%>: <%=@lva.lvanr %>
  • -
  • ECTS: <%=@lva.ects %>
  • -
  • <%= I18n.t('lva.stunden')%>: <%=@lva.stunden %>
  • -
-

<%= I18n.t('lva.module')%>

-
    - <% @lva.modul.each do |modul| %> -
  • <%= link_to modul.name , modul_path(modul)%> -
      - <% modul.modulgruppen.each do |g| %> - -
    • <%= link_to g.studium.title_context , studium_path(g.studium)%> (<%=link_to g.name, modulgruppe_path(g)%>)
    • - <% end %> -
    -
  • - - <% end %> -
-
-
-

<%= I18n.t "lecturers.lecturers" %>

- <% @lva.lecturers.each do |lec| %> - <%= render :partial=>'lecturers/lec_lva', :object=>lec %> - - <% end %> -
+
+
    +
  • <%= I18n.t('lva.lvanr')%>: <%=@lva.lvanr %>
  • +
  • ECTS: <%=@lva.ects %>
  • +
  • <%= I18n.t('lva.stunden')%>: <%=@lva.stunden %>
  • +
+

<%= I18n.t('lva.module')%>

+
    + <% @lva.modul.each do |modul| %> +
  • <%= link_to modul.name , modul_path(modul)%> +
      + <% modul.modulgruppen.each do |g| %> +
    • <%= link_to g.studium.title_context , studium_path(g.studium)%> (<%=link_to g.name, modulgruppe_path(g)%>)
    • + <% end %> +
    +
  • + <% end %> +
+
+
+

<%= I18n.t "lecturers.lecturers" %>

+ <% @lva.lecturers.each do |lec| %> + <%= render :partial=>'lecturers/lec_lva', :object=>lec %> + <% end %> +
- - -
+
-

<%= I18n.t("lva.bspe") %>

-

<%= I18n.t("lva.ratebsp")%> <%= link_to ffi1_icon("facebook1") + I18n.t('home.fblogin'), user_omniauth_authorize_path(:facebook) ,class: :linkbox %> -

- <%= 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 %> - <%= render b%> - <% end %> - <% end %> +

<%= I18n.t("lva.bspe") %>

+

<%= I18n.t("lva.ratebsp")%> <%= link_to ffi1_icon("facebook1") + I18n.t('home.fblogin'), user_omniauth_authorize_path(:facebook) ,class: :linkbox %> +

+ <%= 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?(: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 %>
- <% unless @lva.nlinks.empty? %> -

<%= I18n.t("rubrik.title") %>

- <% @lva.nlinks.each do |l| %> - <%= render l.neuigkeit %> - <% end %> - <% end %> + <% unless @lva.nlinks.empty? %> +

<%= I18n.t("rubrik.title") %>

+ <% @lva.nlinks.each do |l| %> + <%= render l.neuigkeit %> + <% end %> + <% end %>
<% cache("lva_beispiel_form_bulk_"+@lva.id.to_s+I18n.locale.to_s+@lva.updated_at.to_i.to_s) do %> -
-
- <%= render 'beispiele/form_bulk' %> -
-
+
+
+ <%= render 'beispiele/form_bulk' %> +
+
<% end %> <% unless @crawlobjects.nil? %> -
-
- <% @crawlobjects.each do |co| %> - <%= render co %> - <% end %> -
-
+
+
+ <% @crawlobjects.each do |co| %> + <%= render co %> + <% end %> +
+
<% end %>
diff --git a/app/views/survey/choices/_choice.html.erb b/app/views/survey/choices/_choice.html.erb index 7f75eb8..8cbab19 100644 --- a/app/views/survey/choices/_choice.html.erb +++ b/app/views/survey/choices/_choice.html.erb @@ -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 %> diff --git a/app/views/survey/questions/_question.html.erb b/app/views/survey/questions/_question.html.erb index a4afc45..b0a4366 100644 --- a/app/views/survey/questions/_question.html.erb +++ b/app/views/survey/questions/_question.html.erb @@ -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 @@
<%= question.title%> <%= question.text %> - <%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true %> - <%= flag_link(question, "delete")%> - <%= flag_link(question, "template")%> + <%= 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 %>
    <% question.choices.each do |c| %>
  • <%= render c %>
  • <% end %>
- <%= 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 %>
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0 unless question.flag_delete %>