@@ -1,56 +1,49 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Document < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" |
|
21 | 21 | acts_as_attachable :delete_permission => :manage_documents |
|
22 | 22 | |
|
23 | 23 | acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project |
|
24 | 24 | acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"}, |
|
25 | 25 | :author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil }, |
|
26 | 26 | :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}} |
|
27 | 27 | acts_as_activity_provider :find_options => {:include => :project} |
|
28 | 28 | |
|
29 | 29 | validates_presence_of :project, :title, :category |
|
30 | 30 | validates_length_of :title, :maximum => 60 |
|
31 | 31 | |
|
32 | 32 | def visible?(user=User.current) |
|
33 | 33 | !user.nil? && user.allowed_to?(:view_documents, project) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def after_initialize |
|
37 | 37 | if new_record? |
|
38 | 38 | self.category ||= DocumentCategory.default |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def updated_on |
|
43 | 43 | unless @updated_on |
|
44 | 44 | a = attachments.find(:first, :order => 'created_on DESC') |
|
45 | 45 | @updated_on = (a && a.created_on) || created_on |
|
46 | 46 | end |
|
47 | 47 | @updated_on |
|
48 | 48 | end |
|
49 | ||
|
50 | # Returns the mail adresses of users that should be notified | |
|
51 | def recipients | |
|
52 | notified = project.notified_users | |
|
53 | notified.reject! {|user| !visible?(user)} | |
|
54 | notified.collect(&:mail) | |
|
55 | end | |
|
56 | 49 | end |
@@ -1,105 +1,98 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Message < ActiveRecord::Base |
|
19 | 19 | belongs_to :board |
|
20 | 20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
21 | 21 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" |
|
22 | 22 | acts_as_attachable |
|
23 | 23 | belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' |
|
24 | 24 | |
|
25 | 25 | acts_as_searchable :columns => ['subject', 'content'], |
|
26 | 26 | :include => {:board => :project}, |
|
27 | 27 | :project_key => 'project_id', |
|
28 | 28 | :date_column => "#{table_name}.created_on" |
|
29 | 29 | acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, |
|
30 | 30 | :description => :content, |
|
31 | 31 | :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, |
|
32 | 32 | :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : |
|
33 | 33 | {:id => o.parent_id, :anchor => "message-#{o.id}"})} |
|
34 | 34 | |
|
35 | 35 | acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, |
|
36 | 36 | :author_key => :author_id |
|
37 | 37 | acts_as_watchable |
|
38 | 38 | |
|
39 | 39 | attr_protected :locked, :sticky |
|
40 | 40 | validates_presence_of :board, :subject, :content |
|
41 | 41 | validates_length_of :subject, :maximum => 255 |
|
42 | 42 | |
|
43 | 43 | after_create :add_author_as_watcher |
|
44 | 44 | |
|
45 | 45 | def visible?(user=User.current) |
|
46 | 46 | !user.nil? && user.allowed_to?(:view_messages, project) |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def validate_on_create |
|
50 | 50 | # Can not reply to a locked topic |
|
51 | 51 | errors.add_to_base 'Topic is locked' if root.locked? && self != root |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def after_create |
|
55 | 55 | if parent |
|
56 | 56 | parent.reload.update_attribute(:last_reply_id, self.id) |
|
57 | 57 | end |
|
58 | 58 | board.reset_counters! |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def after_update |
|
62 | 62 | if board_id_changed? |
|
63 | 63 | Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id]) |
|
64 | 64 | Board.reset_counters!(board_id_was) |
|
65 | 65 | Board.reset_counters!(board_id) |
|
66 | 66 | end |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def after_destroy |
|
70 | 70 | board.reset_counters! |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def sticky=(arg) |
|
74 | 74 | write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0) |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def sticky? |
|
78 | 78 | sticky == 1 |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def project |
|
82 | 82 | board.project |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def editable_by?(usr) |
|
86 | 86 | usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))) |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def destroyable_by?(usr) |
|
90 | 90 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | # Returns the mail adresses of users that should be notified | |
|
94 | def recipients | |
|
95 | notified = project.notified_users | |
|
96 | notified.reject! {|user| !visible?(user)} | |
|
97 | notified.collect(&:mail) | |
|
98 | end | |
|
99 | ||
|
100 | 93 | private |
|
101 | 94 | |
|
102 | 95 | def add_author_as_watcher |
|
103 | 96 | Watcher.create(:watchable => self.root, :user => author) |
|
104 | 97 | end |
|
105 | 98 | end |
@@ -1,47 +1,40 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class News < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
21 | 21 | has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" |
|
22 | 22 | |
|
23 | 23 | validates_presence_of :title, :description |
|
24 | 24 | validates_length_of :title, :maximum => 60 |
|
25 | 25 | validates_length_of :summary, :maximum => 255 |
|
26 | 26 | |
|
27 | 27 | acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project |
|
28 | 28 | acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} |
|
29 | 29 | acts_as_activity_provider :find_options => {:include => [:project, :author]}, |
|
30 | 30 | :author_key => :author_id |
|
31 | 31 | |
|
32 | 32 | def visible?(user=User.current) |
|
33 | 33 | !user.nil? && user.allowed_to?(:view_news, project) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | # Returns the mail adresses of users that should be notified | |
|
37 | def recipients | |
|
38 | notified = project.notified_users | |
|
39 | notified.reject! {|user| !visible?(user)} | |
|
40 | notified.collect(&:mail) | |
|
41 | end | |
|
42 | ||
|
43 | 36 | # returns latest news for projects visible by user |
|
44 | 37 | def self.latest(user = User.current, count = 5) |
|
45 | 38 | find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
46 | 39 | end |
|
47 | 40 | end |
@@ -1,76 +1,83 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module Redmine |
|
19 | 19 | module Acts |
|
20 | 20 | module Event |
|
21 | 21 | def self.included(base) |
|
22 | 22 | base.extend ClassMethods |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | module ClassMethods |
|
26 | 26 | def acts_as_event(options = {}) |
|
27 | 27 | return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods) |
|
28 | 28 | default_options = { :datetime => :created_on, |
|
29 | 29 | :title => :title, |
|
30 | 30 | :description => :description, |
|
31 | 31 | :author => :author, |
|
32 | 32 | :url => {:controller => 'welcome'}, |
|
33 | 33 | :type => self.name.underscore.dasherize } |
|
34 | 34 | |
|
35 | 35 | cattr_accessor :event_options |
|
36 | 36 | self.event_options = default_options.merge(options) |
|
37 | 37 | send :include, Redmine::Acts::Event::InstanceMethods |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | module InstanceMethods |
|
42 | 42 | def self.included(base) |
|
43 | 43 | base.extend ClassMethods |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | %w(datetime title description author type).each do |attr| |
|
47 | 47 | src = <<-END_SRC |
|
48 | 48 | def event_#{attr} |
|
49 | 49 | option = event_options[:#{attr}] |
|
50 | 50 | if option.is_a?(Proc) |
|
51 | 51 | option.call(self) |
|
52 | 52 | elsif option.is_a?(Symbol) |
|
53 | 53 | send(option) |
|
54 | 54 | else |
|
55 | 55 | option |
|
56 | 56 | end |
|
57 | 57 | end |
|
58 | 58 | END_SRC |
|
59 | 59 | class_eval src, __FILE__, __LINE__ |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def event_date |
|
63 | 63 | event_datetime.to_date |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def event_url(options = {}) |
|
67 | 67 | option = event_options[:url] |
|
68 | 68 | (option.is_a?(Proc) ? option.call(self) : send(option)).merge(options) |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | # Returns the mail adresses of users that should be notified | |
|
72 | def recipients | |
|
73 | notified = project.notified_users | |
|
74 | notified.reject! {|user| !visible?(user)} | |
|
75 | notified.collect(&:mail) | |
|
76 | end | |
|
77 | ||
|
71 | 78 | module ClassMethods |
|
72 | 79 | end |
|
73 | 80 | end |
|
74 | 81 | end |
|
75 | 82 | end |
|
76 | 83 | end |
General Comments 0
You need to be logged in to leave comments.
Login now