This commit is contained in:
2014-07-30 10:15:40 +05:30
committed by Andreas Stephanides
parent 2b562fd7e0
commit 7d56d10431
35 changed files with 429 additions and 12 deletions

View File

@@ -4,6 +4,8 @@ class Ability
def initialize(user)
loggedin=!(user.nil?)
user ||= User.new # guest user (not logged in)
can :manage, Comment
#-----------------------------------------------------
# Rechteverwaltung fuer Studien Modul
can [:show, :index], Studium
@@ -97,6 +99,8 @@ class Ability
if user.has_role?("fetadmin")
can :addfetuser, User
can :addfetadmin, User
can :edit, User
can :manage, User
end
if user.has_role?("newsadmin") || user.has_role?( "fetadmin") || user.has_role?( "fetuser")

View File

@@ -16,7 +16,7 @@ class Beispiel < ActiveRecord::Base
attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum
acts_as_votable
belongs_to :lva
include IsCommentable
mount_uploader :beispieldatei, AttachmentUploader
validates :beispieldatei, :presence => true
validates :name, :presence => true
@@ -35,4 +35,7 @@ class Beispiel < ActiveRecord::Base
"delete_type" => "DELETE"
}
end
def divid
"beispiel_"+id.to_s
end
end

44
app/models/comment.rb Normal file
View File

@@ -0,0 +1,44 @@
class Comment < ActiveRecord::Base
attr_accessible :text,:anonym, :intern, :hidden
# commentable depth, official, intern, anonym
acts_as_votable
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
belongs_to :commentable, :polymorphic=> true
belongs_to :user
validate :text, :presence=>true
validate :user, :presence=>true
validate :commentable, :presence=>true
include IsCommentable
def self.build_for(set_commentable, user, text,attr={})
c = new
raise "Tried to build comment for non commentable" unless set_commentable.try(:is_commentable?)
c.user=user
c.text=text
c.assign_attributes(attr)
unless set_commentable.class.to_s == "Comment"
c.commentable=set_commentable
c.save
else
c.commentable=set_commentable.commentable
c.save
c.move_to_child_of(set_commentable)
end
c
end
def thumb_url
t_url= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil?
t_url
end
def divid
"comment_" + id.to_s
end
def formid
"comment_form_" + commentable_type + "_" + commentable_id.to_s
end
def self.formid_for(c)
"comment_form_" + c.class.to_s + "_" + c.id.to_s
end
end

View File

@@ -16,7 +16,7 @@
class Fetprofile < ActiveRecord::Base
attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache, :plz, :street, :city, :instant,:skype, :telnr, :hdynr, :birth_day, :birth_month, :birth_year,:geschlecht
has_many :memberships, dependent: :delete_all
has_many :memberships, dependent: :destroy
has_many :gremien, :through=> :membership
mount_uploader :picture, PictureUploader
has_paper_trail