Mercurial > hg > soundsoftware-site
comparison app/models/news.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | bb32da3bea34 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
32 :author_key => :author_id | 32 :author_key => :author_id |
33 acts_as_watchable | 33 acts_as_watchable |
34 | 34 |
35 after_create :add_author_as_watcher | 35 after_create :add_author_as_watcher |
36 | 36 |
37 scope :visible, lambda {|*args| { | 37 scope :visible, lambda {|*args| |
38 :include => :project, | 38 includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) |
39 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args) | 39 } |
40 }} | |
41 | 40 |
42 safe_attributes 'title', 'summary', 'description' | 41 safe_attributes 'title', 'summary', 'description' |
43 | 42 |
44 def visible?(user=User.current) | 43 def visible?(user=User.current) |
45 !user.nil? && user.allowed_to?(:view_news, project) | 44 !user.nil? && user.allowed_to?(:view_news, project) |
46 end | 45 end |
47 | 46 |
48 # Returns true if the news can be commented by user | 47 # Returns true if the news can be commented by user |
49 def commentable?(user=User.current) | 48 def commentable?(user=User.current) |
50 user.allowed_to?(:comment_news, project) | 49 user.allowed_to?(:comment_news, project) |
50 end | |
51 | |
52 def recipients | |
53 project.users.select {|user| user.notify_about?(self)}.map(&:mail) | |
51 end | 54 end |
52 | 55 |
53 # returns latest news for projects visible by user | 56 # returns latest news for projects visible by user |
54 def self.latest(user = User.current, count = 5) | 57 def self.latest(user = User.current, count = 5) |
55 visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all | 58 visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all |