Mercurial > hg > soundsoftware-site
comparison .svn/pristine/a3/a345da33b5d730db2fa4453ba2e9a3bfdd694d8f.svn-base @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 module Redmine | |
19 module Acts | |
20 module Attachable | |
21 def self.included(base) | |
22 base.extend ClassMethods | |
23 end | |
24 | |
25 module ClassMethods | |
26 def acts_as_attachable(options = {}) | |
27 cattr_accessor :attachable_options | |
28 self.attachable_options = {} | |
29 attachable_options[:view_permission] = options.delete(:view_permission) || "view_#{self.name.pluralize.underscore}".to_sym | |
30 attachable_options[:delete_permission] = options.delete(:delete_permission) || "edit_#{self.name.pluralize.underscore}".to_sym | |
31 | |
32 has_many :attachments, options.merge(:as => :container, | |
33 :order => "#{Attachment.table_name}.created_on", | |
34 :dependent => :destroy) | |
35 attr_accessor :unsaved_attachments | |
36 after_initialize :initialize_unsaved_attachments | |
37 send :include, Redmine::Acts::Attachable::InstanceMethods | |
38 end | |
39 end | |
40 | |
41 module InstanceMethods | |
42 def self.included(base) | |
43 base.extend ClassMethods | |
44 end | |
45 | |
46 def attachments_visible?(user=User.current) | |
47 (respond_to?(:visible?) ? visible?(user) : true) && | |
48 user.allowed_to?(self.class.attachable_options[:view_permission], self.project) | |
49 end | |
50 | |
51 def attachments_deletable?(user=User.current) | |
52 (respond_to?(:visible?) ? visible?(user) : true) && | |
53 user.allowed_to?(self.class.attachable_options[:delete_permission], self.project) | |
54 end | |
55 | |
56 def initialize_unsaved_attachments | |
57 @unsaved_attachments ||= [] | |
58 end | |
59 | |
60 module ClassMethods | |
61 end | |
62 end | |
63 end | |
64 end | |
65 end |