diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 436163b..b88554a 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,7 +36,12 @@ if user_signed_in? flash[:error] = "Not authorized to view this page" session[:user_return_to] = nil - redirect_to root_url + respond_to do |format| + format.html {redirect_to root_url} + format.js {render text:"alert(\"Not authorized to do this\");", status: 401} + end + + else flash[:error] = "You must first login to view this page" diff --git a/app/controllers/beispiele_controller.rb b/app/controllers/beispiele_controller.rb index ce72054..4e372af 100755 --- a/app/controllers/beispiele_controller.rb +++ b/app/controllers/beispiele_controller.rb @@ -5,15 +5,15 @@ class BeispieleController < ApplicationController include LikeVoteable acts_as_flagable def index - unless params[:lva_id].nil? - @beispiele= Lva.find(params[:lva_id]).beispiele.accessible_by(current_ability, :show) - else - @beispiele = Beispiel.accessible_by(current_ability, :show) - end - respond_to do |format| - format.html # index.html.erb - format.json { render json: @beispiele } - end +# unless params[:lva_id].nil? +# @beispiele= Lva.find(params[:lva_id]).beispiele.accessible_by(current_ability, :show) +# else +# @beispiele = Beispiel.accessible_by(current_ability, :show) +# end +# respond_to do |format| +# format.html # index.html.erb +# format.json { render json: @beispiele } +# end end # GET /beispiele/1 diff --git a/app/models/ability.rb b/app/models/ability.rb index ca1e523..a4ad4db 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -36,14 +36,20 @@ cannot :destroy, Comment can [:show], Modulgruppe can [:show, :index], Modul can [:show, :index, :beispiel_sammlung], Lva - can [:create, :show], Beispiel + can [:create, :show], Beispiel, flag_delete: false if loggedin can :like, Beispiel can :dislike, Beispiel end - if (user.has_role?("moderator",Beispiel)) + if ((user.has_role?("moderator",Beispiel)) || user.has_role?("fetuser") || user.has_role?("fetadmin")) can :flag, Beispiel can [:edit, :update], Beispiel + can :flag, Beispiel + can :set_lecturer, Beispiel + can :flag_delete, Beispiel + can :flag_goodquality, Beispiel + can :flag_badquality, Beispiel + end if (user.has_role?("moderator",Lva)) can [:verwalten, :edit, :compare_tiss, :load_tiss, :update], Lva @@ -53,7 +59,9 @@ cannot :destroy, Comment can :manage, Modul can :manage, Lva can :manage, Studium - can :manage, Beispiel + #can :manage, Beispiel + can :comment, Beispiel + can :manage, Lecturer end diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index 83a1ee8..36d01e4 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -5,6 +5,8 @@ class Survey::Question < ActiveRecord::Base has_many :answers, through: :choices include IsCommentable + scope :templates, ->{ where(flag_template:true)} + def add_yesno_choices c=Survey::Choice.new(title: "Ja") c.save diff --git a/db/migrate/20150803060145_add_template_to_survey_question.rb b/db/migrate/20150803060145_add_template_to_survey_question.rb index c883955..5b17249 100644 --- a/db/migrate/20150803060145_add_template_to_survey_question.rb +++ b/db/migrate/20150803060145_add_template_to_survey_question.rb @@ -1,9 +1,26 @@ class AddTemplateToSurveyQuestion < ActiveRecord::Migration - def change - add_column :survey_questions, :flag_template, :boolean - add_column :survey_questions, :flag_deleted, :boolean - add_column :survey_questions, :flag_intern,:boolean + def up + add_column :survey_questions, :flag_template, :boolean, :default => 0 + add_column :survey_questions, :flag_delete, :boolean, :default => 0 + add_column :survey_questions, :flag_intern,:boolean, :default => 0 add_column :survey_questions, :user_id, :integer - add_column :survey_questions, :flag_locked, :boolean + add_column :survey_questions, :flag_locked, :boolean, :default => 0 + add_column :survey_questions, :flag_multiplechoice, :boolean, :default => 0 + add_column :survey_questions, :sort, :integer + add_column :survey_questions, :flag_hidden, :boolean, :default => 0 + add_column :survey_questions, :flag_emailed, :boolean, :default => 0 end +def down + + remove_column :survey_questions, :flag_template + remove_column :survey_questions, :flag_delete + remove_column :survey_questions, :flag_intern + remove_column :survey_questions, :user_id + remove_column :survey_questions, :flag_locked + remove_column :survey_questions, :flag_multiplechoice + remove_column :survey_questions, :sort + remove_column :survey_questions, :flag_hidden + remove_column :survey_questions, :flag_emailed + +end end diff --git a/db/migrate/20150804193027_add_flags_to_users.rb b/db/migrate/20150804193027_add_flags_to_users.rb new file mode 100644 index 0000000..646b19a --- /dev/null +++ b/db/migrate/20150804193027_add_flags_to_users.rb @@ -0,0 +1,6 @@ +class AddFlagsToUsers < ActiveRecord::Migration + def change + add_column :users, :flag_getemails, :boolean, default: 0 + add_column :users, :flag_delete, :boolean, default: 0 + end +end diff --git a/lib/flagable.rb b/lib/flagable.rb index d6f8dc7..f1b50f0 100644 --- a/lib/flagable.rb +++ b/lib/flagable.rb @@ -20,6 +20,7 @@ module Flagable @obj=controller_name.classify.constantize.find(params[:id]) lflag=("flag_"+params[:flag]).to_sym + authorize! lflag, @obj unless params[:flag].nil? || params[:flag].empty? || params[:value].nil? if @obj.respond_to?(lflag.to_s+"=") @obj.send(lflag.to_s+"=",params[:value]=="true")