-
Notifications
You must be signed in to change notification settings - Fork 53
/
bookmark.rb
66 lines (52 loc) · 1.36 KB
/
bookmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# encoding: utf-8
# == Schema Information
#
# Table name: bookmarks
#
# id :integer not null, primary key
# title :string(160) not null
# cached_slug :string(165)
# owner_id :integer
# link :string(1024)
# lang :string(2) not null
# created_at :datetime
# updated_at :datetime
#
# The users can post on theirs bookmarks.
# They can be used for sharing interesting,
# stuff found on other websites.
#
class Bookmark < Content
self.table_name = "bookmarks"
self.type = "Lien"
belongs_to :owner, class_name: 'User'
validates :title, presence: { message: "Le titre est obligatoire" },
length: { maximum: 100, message: "Le titre est trop long" }
validates :link, presence: { message: "Vous ne pouvez pas poster un lien vide" }
def create_node(attrs={})
attrs[:cc_licensed] = false
super
end
def label_for_expand
"Discuter"
end
def alternative_formats
false
end
### SEO ###
extend FriendlyId
friendly_id
def should_generate_new_friendly_id?
title_changed?
end
### ACL ###
def creatable_by?(account)
account.karma > 0
end
def updatable_by?(account)
account.moderator? || account.admin?
end
def destroyable_by?(account)
account.moderator? || account.admin?
end
end