Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 473
- Log:
Add simple topic title blacklist.
- Author:
- rool
- Date:
- Thu Jan 31 09:48:46 +0000 2019
- Size:
- 1372 Bytes
1 | class Post < ActiveRecord::Base |
2 | belongs_to :forum, :counter_cache => true |
3 | belongs_to :user, :counter_cache => true |
4 | belongs_to :topic, :counter_cache => true |
5 | |
6 | format_attribute :body |
7 | before_create { |r| r.forum_id = r.topic.forum_id } |
8 | after_create { |r| Topic.update_all(['replied_at = ?, replied_by = ?, last_post_id = ?', r.created_at, r.user_id, r.id], ['id = ?', r.topic_id]) } |
9 | after_destroy { |r| t = Topic.find(r.topic_id) ; Topic.update_all(['replied_at = ?, replied_by = ?, last_post_id = ?', t.posts.last.created_at, t.posts.last.user_id, t.posts.last.id], ['id = ?', t.id]) if t.posts.last } |
10 | |
11 | validates_presence_of :user_id, :body |
12 | validate :body_cannot_contain_blacklisted_strings |
13 | |
14 | attr_accessible :body |
15 | |
16 | def editable_by?(user) |
17 | user && (user.id == user_id || user.admin? || user.moderator_of?(topic.forum_id)) |
18 | end |
19 | |
20 | def to_xml(options = {}) |
21 | options[:except] ||= [] |
22 | options[:except] << :topic_title << :forum_name |
23 | super |
24 | end |
25 | |
26 | def body_cannot_contain_blacklisted_strings |
27 | downcase_body = body.downcase rescue '' |
28 | blacklist = Blacklist.find(:first).list rescue '' |
29 | prohibited = false |
30 | |
31 | blacklist.split("\n").each do |item| |
32 | if downcase_body.include?(item) |
33 | prohibited = true |
34 | break |
35 | end |
36 | end |
37 | |
38 | errors.add(:body, "contains prohibited text") if prohibited == true |
39 | end |
40 | end |