radiant-downloads-extension 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,16 +4,12 @@ class DownloadsController < ReaderActionController
4
4
 
5
5
  def show
6
6
  @download = Download.find(params[:id])
7
- if @download.available_to?(current_reader)
8
- response.headers['X-Accel-Redirect'] = @download.document.url
9
- response.headers["Content-Type"] = @download.document_content_type
10
- response.headers['Content-Disposition'] = "attachment; filename=#{@download.document_file_name}"
11
- response.headers['Content-Length'] = @download.document_file_size
12
- render :nothing => true
13
- else
14
- flash[:error] = "Sorry: you don't have permission to download that file."
15
- render :template => 'reader/permission_denied'
16
- end
7
+ raise ReaderError::AccessDenied, t("downloads_extension.permission_denied") unless @download.visible_to?(current_reader)
8
+ response.headers['X-Accel-Redirect'] = @download.document.url
9
+ response.headers["Content-Type"] = @download.document_content_type
10
+ response.headers['Content-Disposition'] = "attachment; filename=#{@download.document_file_name}"
11
+ response.headers['Content-Length'] = @download.document_file_size
12
+ render :nothing => true
17
13
  end
18
14
 
19
15
  end
@@ -1,9 +1,8 @@
1
1
  class Download < ActiveRecord::Base
2
2
 
3
- is_site_scoped if defined? ActiveRecord::SiteNotFound
3
+ has_groups
4
4
  belongs_to :created_by, :class_name => 'User'
5
5
  belongs_to :updated_by, :class_name => 'User'
6
- has_and_belongs_to_many :groups
7
6
  default_scope :order => 'updated_at DESC, created_at DESC'
8
7
 
9
8
  has_attached_file :document,
@@ -11,21 +10,7 @@ class Download < ActiveRecord::Base
11
10
  :path => ":rails_root/secure_downloads/:id/:basename:no_original_style.:extension"
12
11
 
13
12
  validates_attachment_presence :document
14
-
15
- def has_group?(group=nil)
16
- return true if groups and group.nil?
17
- return false if group.nil?
18
- return groups.include?(group)
19
- end
20
-
21
- def available_to?(reader=nil)
22
- permitted_groups = self.groups
23
- return true if permitted_groups.empty?
24
- return false if reader.nil?
25
- return true if reader.is_admin?
26
- return reader.in_any_of_these_groups?(permitted_groups)
27
- end
28
-
13
+
29
14
  def document_ok?
30
15
  self.document.exists?
31
16
  end
@@ -23,15 +23,7 @@
23
23
  = link_to @download.document_file_name, download_url(@download)
24
24
 
25
25
  - form.edit_access do
26
- %p.access
27
- = f.label :groups, "Available to"
28
- - Group.find(:all).each do |group|
29
- %span.checkbox
30
- = check_box_tag "download[group_ids][]", group.id, @download.has_group?(group)
31
- = group.name
32
- %br
33
- %span.formnote
34
- If no group is ticked, any logged-in reader can download this file.
26
+ = render :partial => "admin/groups/edit_access", :locals => {:groupee => @download}
35
27
 
36
28
  = javascript_tag "$('download_name').activate()"
37
29
 
@@ -5,3 +5,5 @@
5
5
  - main.edit_form do
6
6
  - form_for :download, :url => admin_download_path(@download), :html => { :method => "put", :multipart => true } do |f|
7
7
  = render :partial => 'form', :locals => { :f => f }
8
+ - main.edit_popups do
9
+ = render :partial => 'admin/groups/popup', :locals => {:groupee => @download}
@@ -5,3 +5,5 @@
5
5
  - main.edit_form do
6
6
  - form_for :download, :url => admin_downloads_path, :html => { :multipart => true } do |f|
7
7
  = render :partial => "form", :locals => { :f => f }
8
+ - main.edit_popups do
9
+ = render :partial => 'admin/groups/popup', :locals => {:groupee => @download}
@@ -0,0 +1,14 @@
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ download:
5
+ errors:
6
+ models:
7
+ download:
8
+ attributes:
9
+ config:
10
+ download:
11
+ download: "download"
12
+ downloads: "Downloads"
13
+ downloads_extension:
14
+ permission_denied: "You do not have permission to download the requested file."
@@ -8,7 +8,6 @@ class DownloadsExtension < Radiant::Extension
8
8
  url RadiantDownloadsExtension::URL
9
9
 
10
10
  def activate
11
- Group.send :include, DownloadGroup
12
11
  Page.send :include, DownloadTags
13
12
  UserActionObserver.instance.send :add_observer!, Download
14
13
 
data/lib/download_ui.rb CHANGED
@@ -21,7 +21,7 @@ module DownloadUI
21
21
  def load_default_download_regions
22
22
  OpenStruct.new.tap do |download|
23
23
  download.edit = Radiant::AdminUI::RegionSet.new do |edit|
24
- edit.main.concat %w{edit_header edit_form}
24
+ edit.main.concat %w{edit_header edit_form edit_popups}
25
25
  edit.form.concat %w{edit_title edit_description edit_document edit_access}
26
26
  edit.form_bottom.concat %w{edit_timestamp edit_buttons}
27
27
  end
@@ -1,5 +1,5 @@
1
1
  module RadiantDownloadsExtension
2
- VERSION = '0.5.4'
2
+ VERSION = '0.6.0'
3
3
  SUMMARY = %q{Secure file distribution for radiant readers}
4
4
  DESCRIPTION = %q{Controlled file access using nginx's local redirects. Requires reader extension.}
5
5
  URL = "http://radiant.spanner.org/downloads"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-downloads-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 4
10
- version: 0.5.4
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - William Ross
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-12 00:00:00 Z
18
+ date: 2011-10-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: paperclip
@@ -50,15 +50,14 @@ files:
50
50
  - app/views/admin/downloads/edit.html.haml
51
51
  - app/views/admin/downloads/index.html.haml
52
52
  - app/views/admin/downloads/new.html.haml
53
+ - config/locales/en.yml
53
54
  - config/routes.rb
54
55
  - db/migrate/001_create_downloads.rb
55
56
  - downloads_extension.rb
56
- - lib/download_group.rb
57
57
  - lib/download_tags.rb
58
58
  - lib/download_ui.rb
59
59
  - lib/radiant-downloads-extension.rb
60
60
  - lib/tasks/downloads_extension_tasks.rake
61
- - radiant-downloads-extension-0.5.3.gem
62
61
  - radiant-downloads-extension.gemspec
63
62
  - Rakefile
64
63
  - README.markdown
@@ -77,7 +76,7 @@ files:
77
76
  homepage: http://radiant.spanner.org/downloads
78
77
  licenses: []
79
78
 
80
- post_install_message: "\n Add this to your radiant project with a line in your Gemfile:\n\n gem 'radiant-downloads-extension', '~> 0.5.4'\n\n "
79
+ post_install_message: "\n Add this to your radiant project with a line in your Gemfile:\n\n gem 'radiant-downloads-extension', '~> 0.6.0'\n\n "
81
80
  rdoc_options: []
82
81
 
83
82
  require_paths:
@@ -1,7 +0,0 @@
1
- module DownloadGroup
2
- def self.included(base)
3
- base.class_eval {
4
- has_and_belongs_to_many :downloads
5
- }
6
- end
7
- end
Binary file