Module: Redmine::Acts::Attachable::InstanceMethods
- Defined in:
- lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #attach_saved_attachments ⇒ Object
- #attachments_deletable?(user = User.current) ⇒ Boolean
- #attachments_editable?(user = User.current) ⇒ Boolean
- #attachments_visible?(user = User.current) ⇒ Boolean
- #detach_saved_attachments ⇒ Object
- #save_attachments(attachments, author = User.current) ⇒ Object
- #saved_attachments ⇒ Object
- #unsaved_attachments ⇒ Object
- #warn_about_failed_attachments ⇒ Object
Class Method Details
.included(base) ⇒ Object
43 44 45 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 43 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#attach_saved_attachments ⇒ Object
115 116 117 118 119 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 115 def .each do || self. << end end |
#attachments_deletable?(user = User.current) ⇒ Boolean
57 58 59 60 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 57 def (user=User.current) (respond_to?(:visible?) ? visible?(user) : true) && user.allowed_to?(self.class.[:delete_permission], self.project) end |
#attachments_editable?(user = User.current) ⇒ Boolean
52 53 54 55 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 52 def (user=User.current) (respond_to?(:visible?) ? visible?(user) : true) && user.allowed_to?(self.class.[:edit_permission], self.project) end |
#attachments_visible?(user = User.current) ⇒ Boolean
47 48 49 50 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 47 def (user=User.current) (respond_to?(:visible?) ? visible?(user) : true) && user.allowed_to?(self.class.[:view_permission], self.project) end |
#detach_saved_attachments ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 121 def .each do || # TODO: use #reload instead, after upgrading to Rails 5 # (after_rollback is called when running transactional tests in Rails 4) .container = nil end end |
#save_attachments(attachments, author = User.current) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 70 def (, =User.current) if .is_a?(Hash) = .stringify_keys = .to_a.sort {|a, b| if a.first.to_i > 0 && b.first.to_i > 0 a.first.to_i <=> b.first.to_i elsif a.first.to_i > 0 1 elsif b.first.to_i > 0 -1 else a.first <=> b.first end } = .map(&:last) end if .is_a?(Array) @failed_attachment_count = 0 .each do || next unless .is_a?(Hash) a = nil if file = ['file'] next unless file.size > 0 a = Attachment.create(:file => file, :author => ) elsif token = ['token'].presence a = Attachment.find_by_token(token) unless a @failed_attachment_count += 1 next end a.filename = ['filename'] unless ['filename'].blank? a.content_type = ['content_type'] unless ['content_type'].blank? end next unless a a.description = ['description'].to_s.strip if a.new_record? << a else << a end end end {:files => , :unsaved => } end |
#saved_attachments ⇒ Object
62 63 64 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 62 def @saved_attachments ||= [] end |
#unsaved_attachments ⇒ Object
66 67 68 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 66 def @unsaved_attachments ||= [] end |
#warn_about_failed_attachments ⇒ Object
129 130 131 132 133 |
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 129 def if @failed_attachment_count && @failed_attachment_count > 0 errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count) end end |