AutoCommit Die Aug 4 22:03:01 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-04 22:03:01 +02:00
parent aa06d2195e
commit 9b1c35f499
7 changed files with 57 additions and 18 deletions

View File

@@ -36,7 +36,12 @@
if user_signed_in? if user_signed_in?
flash[:error] = "Not authorized to view this page" flash[:error] = "Not authorized to view this page"
session[:user_return_to] = nil 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 else
flash[:error] = "You must first login to view this page" flash[:error] = "You must first login to view this page"

View File

@@ -5,15 +5,15 @@ class BeispieleController < ApplicationController
include LikeVoteable include LikeVoteable
acts_as_flagable acts_as_flagable
def index def index
unless params[:lva_id].nil? # unless params[:lva_id].nil?
@beispiele= Lva.find(params[:lva_id]).beispiele.accessible_by(current_ability, :show) # @beispiele= Lva.find(params[:lva_id]).beispiele.accessible_by(current_ability, :show)
else # else
@beispiele = Beispiel.accessible_by(current_ability, :show) # @beispiele = Beispiel.accessible_by(current_ability, :show)
end # end
respond_to do |format| # respond_to do |format|
format.html # index.html.erb # format.html # index.html.erb
format.json { render json: @beispiele } # format.json { render json: @beispiele }
end # end
end end
# GET /beispiele/1 # GET /beispiele/1

View File

@@ -36,14 +36,20 @@ cannot :destroy, Comment
can [:show], Modulgruppe can [:show], Modulgruppe
can [:show, :index], Modul can [:show, :index], Modul
can [:show, :index, :beispiel_sammlung], Lva can [:show, :index, :beispiel_sammlung], Lva
can [:create, :show], Beispiel can [:create, :show], Beispiel, flag_delete: false
if loggedin if loggedin
can :like, Beispiel can :like, Beispiel
can :dislike, Beispiel can :dislike, Beispiel
end 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 :flag, Beispiel
can [:edit, :update], 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 end
if (user.has_role?("moderator",Lva)) if (user.has_role?("moderator",Lva))
can [:verwalten, :edit, :compare_tiss, :load_tiss, :update], Lva can [:verwalten, :edit, :compare_tiss, :load_tiss, :update], Lva
@@ -53,7 +59,9 @@ cannot :destroy, Comment
can :manage, Modul can :manage, Modul
can :manage, Lva can :manage, Lva
can :manage, Studium can :manage, Studium
can :manage, Beispiel #can :manage, Beispiel
can :comment, Beispiel
can :manage, Lecturer can :manage, Lecturer
end end

View File

@@ -5,6 +5,8 @@ class Survey::Question < ActiveRecord::Base
has_many :answers, through: :choices has_many :answers, through: :choices
include IsCommentable include IsCommentable
scope :templates, ->{ where(flag_template:true)}
def add_yesno_choices def add_yesno_choices
c=Survey::Choice.new(title: "Ja") c=Survey::Choice.new(title: "Ja")
c.save c.save

View File

@@ -1,9 +1,26 @@
class AddTemplateToSurveyQuestion < ActiveRecord::Migration class AddTemplateToSurveyQuestion < ActiveRecord::Migration
def change def up
add_column :survey_questions, :flag_template, :boolean add_column :survey_questions, :flag_template, :boolean, :default => 0
add_column :survey_questions, :flag_deleted, :boolean add_column :survey_questions, :flag_delete, :boolean, :default => 0
add_column :survey_questions, :flag_intern,:boolean add_column :survey_questions, :flag_intern,:boolean, :default => 0
add_column :survey_questions, :user_id, :integer 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 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 end

View File

@@ -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

View File

@@ -20,6 +20,7 @@ module Flagable
@obj=controller_name.classify.constantize.find(params[:id]) @obj=controller_name.classify.constantize.find(params[:id])
lflag=("flag_"+params[:flag]).to_sym lflag=("flag_"+params[:flag]).to_sym
authorize! lflag, @obj
unless params[:flag].nil? || params[:flag].empty? || params[:value].nil? unless params[:flag].nil? || params[:flag].empty? || params[:value].nil?
if @obj.respond_to?(lflag.to_s+"=") if @obj.respond_to?(lflag.to_s+"=")
@obj.send(lflag.to_s+"=",params[:value]=="true") @obj.send(lflag.to_s+"=",params[:value]=="true")