annotate app/helpers/attachments_helper.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents c86dacc2ef0a
children
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@441 3 # Redmine - project management software
Chris@1494 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@441 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@441 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@0 20 module AttachmentsHelper
Chris@0 21 # Displays view/delete links to the attachments of the given object
Chris@0 22 # Options:
Chris@0 23 # :author -- author names are not displayed if set to false
Chris@1115 24 # :thumbails -- display thumbnails if enabled in settings
Chris@0 25 def link_to_attachments(container, options = {})
Chris@1115 26 options.assert_valid_keys(:author, :thumbnails)
Chris@441 27
Chris@0 28 if container.attachments.any?
Chris@0 29 options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
Chris@1115 30 render :partial => 'attachments/links',
Chris@1115 31 :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)}
Chris@0 32 end
Chris@0 33 end
Chris@441 34
Chris@909 35 def render_api_attachment(attachment, api)
Chris@909 36 api.attachment do
Chris@909 37 api.id attachment.id
Chris@909 38 api.filename attachment.filename
Chris@909 39 api.filesize attachment.filesize
Chris@909 40 api.content_type attachment.content_type
Chris@909 41 api.description attachment.description
Chris@909 42 api.content_url url_for(:controller => 'attachments', :action => 'download', :id => attachment, :filename => attachment.filename, :only_path => false)
Chris@909 43 api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
Chris@909 44 api.created_on attachment.created_on
Chris@119 45 end
Chris@0 46 end
chris@967 47
chris@967 48 # Returns true if user agent appears (approximately) to be a search
chris@967 49 # bot or crawler
chris@967 50 def user_is_search_bot?
chris@967 51 agent = request.env['HTTP_USER_AGENT']
chris@967 52 agent and agent =~ /(bot|slurp|crawler|spider)\b/i
chris@967 53 end
Chris@0 54 end