Class: News

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Redmine::SafeAttributes
Defined in:
app/models/news.rb

Overview

Redmine - project management software Copyright (C) 2006-2016 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Since:

  • 0.4.0

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Class Method Details

.latest(user = User.current, count = 5) ⇒ Object

returns latest news for projects visible by user



83
84
85
# File 'app/models/news.rb', line 83

def self.latest(user = User.current, count = 5)
  visible(user).preload(:author, :project).order("#{News.table_name}.created_on DESC").limit(count).to_a
end

Instance Method Details

#cc_for_added_newsObject

Returns the email addresses that should be cc'd when a new news is added

Since:

  • 2.5.0



78
79
80
# File 'app/models/news.rb', line 78

def cc_for_added_news
  notified_watchers_for_added_news.map(&:mail)
end

#commentable?(user = User.current) ⇒ Boolean

Returns true if the news can be commented by user

Returns:

  • (Boolean)

Since:

  • 1.4.0



53
54
55
# File 'app/models/news.rb', line 53

def commentable?(user=User.current)
  user.allowed_to?(:comment_news, project)
end

#notified_usersObject

Since:

  • 3.0.0



57
58
59
# File 'app/models/news.rb', line 57

def notified_users
  project.users.select {|user| user.notify_about?(self) && user.allowed_to?(:view_news, project)}
end

#notified_watchers_for_added_newsObject

Returns the users that should be cc'd when a new news is added

Since:

  • 3.0.0



66
67
68
69
70
71
72
73
74
75
# File 'app/models/news.rb', line 66

def notified_watchers_for_added_news
  watchers = []
  if m = project.enabled_module('news')
    watchers = m.notified_watchers
    unless project.is_public?
      watchers = watchers.select {|user| project.users.include?(user)}
    end
  end
  watchers
end

#recipientsObject

Since:

  • 0.9.0



61
62
63
# File 'app/models/news.rb', line 61

def recipients
  notified_users.map(&:mail)
end

#visible?(user = User.current) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.9.0



48
49
50
# File 'app/models/news.rb', line 48

def visible?(user=User.current)
  !user.nil? && user.allowed_to?(:view_news, project)
end