forked from bofh/fetsite
abilities und beispiel delete
This commit is contained in:
@@ -2,58 +2,34 @@
|
||||
class Ability
|
||||
include CanCan::Ability
|
||||
def initialize(user)
|
||||
# Define abilities for the passed in user here. For example:
|
||||
#
|
||||
# if user.admin?
|
||||
# can :manage, :all
|
||||
# else
|
||||
# can :read, :all
|
||||
# end
|
||||
# The first argument to `can` is the action you are giving the user permission to do.
|
||||
# If you pass :manage it will apply to every action. Other common actions here are
|
||||
# :read, :create, :update and :destroy.
|
||||
#
|
||||
# The second argument is the resource the user can perform the action on. If you pass
|
||||
# :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
|
||||
#
|
||||
# The third argument is an optional hash of conditions to further filter the objects.
|
||||
# For example, here the user can only update published articles.
|
||||
#
|
||||
# can :update, Article, :published => true
|
||||
#
|
||||
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilitiescan :manage, :all
|
||||
|
||||
user ||= User.new # guest user (not logged in)
|
||||
|
||||
|
||||
# For Debug allow everything
|
||||
# Remove this line in production environment and for testing user management
|
||||
# can :manage, :all
|
||||
can :addfetuser, User
|
||||
can :addfetadmin, User
|
||||
|
||||
# Rechteverwaltung fuer Studien Modul
|
||||
can [:show, :index], Studium
|
||||
can [:show, :index], Modulgruppe
|
||||
can [:show, :index], Modul
|
||||
can [:show, :index], Lva
|
||||
can [:create, :show], Beispiel
|
||||
|
||||
can [:show,:index], Gallery
|
||||
can [:show, :index,:faqs], Themengruppe
|
||||
can [:show], Thema, :isdraft=>false
|
||||
can [:create], Beispiel
|
||||
|
||||
can [:show, :index], Fetprofile
|
||||
can [:show, :index],Gremium
|
||||
# Rechteverwaltung fuer Studien Modul
|
||||
|
||||
|
||||
|
||||
# Rechteverwaltung Kalender
|
||||
can [:show, :index], Calendar, :public => true
|
||||
can [:showics], Calendar
|
||||
can [:show], Calentry
|
||||
|
||||
if( user.has_role?("fetuser") || user.has_role?("fetadmin"))
|
||||
can :manage,:all
|
||||
can :manage, Modulgruppe
|
||||
can :showdraft , Thema
|
||||
can :showintern, Thema
|
||||
can :showintern, Neuigkeit
|
||||
can :showintern, Rubrik
|
||||
can [:show,:index], Calendar
|
||||
can [:edit, :update,:new,:create,:verwalten], Calendar
|
||||
can [:edit, :update,:new,:create,:verwalten], Calentry
|
||||
@@ -81,6 +57,10 @@ class Ability
|
||||
can [:show,:index], Rubrik, :public=>true
|
||||
|
||||
can :show, Neuigkeit, :rubrik=>{:public=>true}
|
||||
if user.has_role?("fetadmin")
|
||||
can :addfetuser, User
|
||||
can :addfetadmin, User
|
||||
end
|
||||
|
||||
if user.has_role?("newsadmin") || user.has_role?( "fetadmin") || user.has_role?( "fetuser")
|
||||
can :manage, Rubrik
|
||||
|
||||
@@ -22,9 +22,11 @@ class Neuigkeit < ActiveRecord::Base
|
||||
translates :title,:text, :versioning=>{:gem=>:paper_trail, :options=>{:fallbacks_for_empty_translations => true}}
|
||||
|
||||
has_many :calentries, as: :object
|
||||
has_many :nlinks
|
||||
|
||||
mount_uploader :picture, PictureUploader
|
||||
default_scope order(:datum).reverse_order
|
||||
#scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date)}
|
||||
|
||||
default_scope order(:datum).reverse_order
|
||||
scope :recent, -> { published.limit(10)}
|
||||
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
|
||||
scope :public, ->{includes(:rubrik).where("rubriken.public"=>true)}
|
||||
@@ -34,7 +36,9 @@ class Neuigkeit < ActiveRecord::Base
|
||||
LINKTYPES=["Thema", "Gallery", "Lva","Studium","Fetprofile", "Gremium"]
|
||||
accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
|
||||
before_validation :sanitize
|
||||
has_many :nlinks
|
||||
|
||||
|
||||
|
||||
def self.published
|
||||
where("datum <= ? AND datum IS NOT NULL", Time.now.to_date)
|
||||
end
|
||||
@@ -55,9 +59,9 @@ class Neuigkeit < ActiveRecord::Base
|
||||
def reverse_publish
|
||||
self.datum = nil
|
||||
end
|
||||
def name
|
||||
self.title
|
||||
end
|
||||
def name
|
||||
self.title
|
||||
end
|
||||
def text_first_words
|
||||
md = /<p>(?<text>[^\<\>]*)/.match Sanitize.clean(self.text,:elements=>['p'])
|
||||
words=md[:text].split(" ") unless md.nil?
|
||||
@@ -68,15 +72,15 @@ end
|
||||
|
||||
end
|
||||
end
|
||||
def has_calentries?
|
||||
!self.calentries.nil? && !self.calentries.empty?
|
||||
end
|
||||
private
|
||||
def sanitize
|
||||
self.calentries.each do |calentry|
|
||||
calentry.calendar= self.rubrik.calendar
|
||||
calentry.typ=1
|
||||
calentry.object=self
|
||||
end
|
||||
end
|
||||
def has_calentries?
|
||||
!self.calentries.nil? && !self.calentries.empty?
|
||||
end
|
||||
private
|
||||
def sanitize
|
||||
self.calentries.each do |calentry|
|
||||
calentry.calendar= self.rubrik.calendar
|
||||
calentry.typ=1
|
||||
calentry.object=self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user