app/models/inputs/asset_box.rb in effective_assets-1.9.0 vs app/models/inputs/asset_box.rb in effective_assets-1.9.1

- old
+ new

@@ -1,8 +1,8 @@ module Inputs class AssetBox - delegate :content_tag, :render, :to => :@template + delegate :content_tag, :render, :current_user, :to => :@template def initialize(object, object_name, template, method, opts) @object = object @object_name = object_name @template = template @@ -83,10 +83,18 @@ } ).html_safe end def uploader_html + # Check that we have permission to upload. + asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder') + + unless (EffectiveAssets.authorized?(@template.controller, :create, asset) rescue false) + @options[:btn_title] = 'Unable to upload. (cannot :create Effective::Asset)' + @options[:disabled] = true + end + render( :partial => 'asset_box_input/uploader', :locals => { :uid => @options[:uid], :limit => @options[:limit], @@ -95,11 +103,12 @@ :file_types => @options[:file_types], :progress_bar_partial => @options[:progress_bar_partial], :drop_files => @options[:uploader_drop_files], :drop_files_help_text => @options[:drop_files_help_text], :aws_acl => @options[:aws_acl], - :btn_label => @options[:btn_label] + :btn_label => @options[:btn_label], + :btn_title => @options[:btn_title] } ).html_safe end def filter_bar_html @@ -156,10 +165,11 @@ :table_filter_bar => false, :dialog => false, :dialog_url => @template.effective_assets.effective_assets_path, :disabled => false, :file_types => [:any], - :btn_label => "Upload..." + :btn_label => 'Upload...', + :btn_title => 'Click or drag & drop to upload a file' }.merge(opts).tap do |options| options[:method] = method.to_s options[:box] = method.to_s.pluralize options[:attachable_id] ||= (@object.try(:id) rescue nil) options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase