geoblacklight 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa36bd32f32a6b289d92cab3606e6ba22437a021
4
- data.tar.gz: f09f5393f099ccb09019cfd66643ded169a26c58
3
+ metadata.gz: 6c66665cbabfb3ba8ad4f22cb69c5a34901502e1
4
+ data.tar.gz: f7cd3b0972dc89757282a8332e1f168bba7d0035
5
5
  SHA512:
6
- metadata.gz: 2cda324d88b1b06c40607b5d0d23a3133fdeb40fed7ad24939b0f9aec4bf3197b9150c5792f1cadf5f502923c064dfb7dc63c25dffd8d8a16ffba9c49fd5c67e
7
- data.tar.gz: 80fa4d0944f7218f785b2bb9b6756d2fbfe1edc1f21b5d59a241173d9315f1db1ce27dd7b5eaec5b2f42d1460ae02534be95b39706f2f32a92bac9f280ead698
6
+ metadata.gz: 2ba6e4f97b0b646b8a37a7e58c8fa1e986930512b27f746742131a5d47190dfcf6bb1302c1f91eff47648969d767dabaaf733c0f47ed83748f3a2fcfe2f0aab4
7
+ data.tar.gz: 43e761955b978e8acd896b36714eb2b48ea300db2427a75f4ee1ef10d49e4d8a49379d7d7f41df5ec9a021f511e9cb23ad8fb39695654fb2f74c90403bf7ee7f
@@ -3,6 +3,7 @@ class DownloadController < ApplicationController
3
3
 
4
4
  def show
5
5
  @response, @document = get_solr_response_for_doc_id
6
+ restricted_should_authenticate
6
7
  response = check_type
7
8
  validate response
8
9
  respond_to do |format|
@@ -12,9 +13,14 @@ class DownloadController < ApplicationController
12
13
  end
13
14
 
14
15
  def file
15
- send_file "tmp/downloads/#{params[:id]}.#{params[:format]}", type: 'application/zip', x_sendfile: true
16
+ # Grab the solr document to check if it should be public or not
17
+ @response, @document = get_solr_response_for_doc_id(file_name_to_id(params[:id]))
18
+ restricted_should_authenticate
19
+ send_file "tmp/cache/downloads/#{params[:id]}.#{params[:format]}", type: 'application/zip', x_sendfile: true
16
20
  end
17
21
 
22
+ private
23
+
18
24
  def check_type
19
25
  case params[:type]
20
26
  when 'shapefile'
@@ -32,4 +38,15 @@ class DownloadController < ApplicationController
32
38
  flash[:success] = view_context.link_to(t('geoblacklight.download.success', title: response), download_file_path(response))
33
39
  end
34
40
  end
41
+
42
+ # Checks whether a document is public, if not require user to authenticate
43
+ def restricted_should_authenticate
44
+ unless @document.public?
45
+ authenticate_user!
46
+ end
47
+ end
48
+
49
+ def file_name_to_id(file_name)
50
+ file_name.split('-')[0..-2].join('-')
51
+ end
35
52
  end
@@ -16,6 +16,14 @@ module GeoblacklightHelper
16
16
  content_tag(:i, '', :class => 'fa fa-download fa-fw') + ' ' + t('Metadata')
17
17
  end
18
18
 
19
+ def document_available?
20
+ @document.public? || (@document.same_institution? && current_user)
21
+ end
22
+
23
+ def document_downloadable?
24
+ document_available? && @document.downloadable?
25
+ end
26
+
19
27
  def abstract_truncator(abstract)
20
28
  if (abstract)
21
29
  if (abstract.length > 150)
@@ -48,10 +56,10 @@ module GeoblacklightHelper
48
56
  end
49
57
 
50
58
  def layer_access_image(access)
51
- case access
52
- when 'Restricted'
59
+ case access.downcase
60
+ when 'restricted'
53
61
  content_tag(:i, '', class: 'fa fa-lock fa-lg text-muted tooltip-icon', 'data-toggle' => 'tooltip', title: 'Restricted', style: 'width: 17px;')
54
- when 'Public'
62
+ when 'public'
55
63
  content_tag(:i, '', class: 'fa fa-unlock fa-lg text-muted tooltip-icon', 'data-toggle' => 'tooltip', title: 'Public')
56
64
  else
57
65
  ""
@@ -4,7 +4,7 @@
4
4
 
5
5
  <div class='row'>
6
6
  <div class="col-md-8">
7
- <%= content_tag :div, id: 'map', data: { map: 'item', 'catalog-path'=> catalog_index_path , 'map-bbox' => document[:solr_bbox], 'layer-id' => document[:layer_id_s], 'wms-url' => document[:solr_wms_url], available: document.available? } do %>
7
+ <%= content_tag :div, id: 'map', data: { map: 'item', 'catalog-path'=> catalog_index_path , 'map-bbox' => document[:solr_bbox], 'layer-id' => document[:layer_id_s], 'wms-url' => document[:solr_wms_url], available: document_available? } do %>
8
8
  <div id='control'>
9
9
  <div id='handle'></div>
10
10
  <div id='bottom'></div>
@@ -18,7 +18,7 @@
18
18
  <i class="fa fa-bookmark fa-fw"></i>&nbsp;Cite This
19
19
  </a>
20
20
  </ul>
21
- <% if document.downloadable? %>
21
+ <% if document_downloadable? %>
22
22
  <div class='btn-group'>
23
23
  <%= button_tag(type: 'button', class: 'btn btn-default dropdown-toggle', data: { toggle: 'dropdown' }) do %>
24
24
  Download <span class='caret'></span>
@@ -31,6 +31,8 @@
31
31
  <% end %>
32
32
  </ul>
33
33
  </div>
34
+ <% elsif document.restricted? && document.same_institution? %>
35
+ <%= link_to t('geoblacklight.tools.login_to_view'), new_user_session_path(referrer: request.original_url) %>
34
36
  <% end %>
35
37
  </div>
36
38
  </div>
@@ -2,4 +2,6 @@ en:
2
2
  geoblacklight:
3
3
  download:
4
4
  success: 'Your file %{title} is ready for download'
5
- error: 'Sorry, the requested file could not be downloaded'
5
+ error: 'Sorry, the requested file could not be downloaded'
6
+ tools:
7
+ login_to_view: 'Login to view and download'
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'blacklight', '~> 5.7.1'
21
+ spec.add_dependency 'blacklight', '~> 5.7.2'
22
22
  spec.add_dependency 'leaflet-rails', '~> 0.7.3'
23
23
  spec.add_dependency 'blacklight_range_limit', '~> 5.0.1'
24
24
  spec.add_dependency 'font-awesome-rails', '~> 4.1.0.0'
@@ -33,4 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'engine_cart', '~> 0.4.0'
34
34
  spec.add_development_dependency 'capybara', '~> 2.3.0'
35
35
  spec.add_development_dependency 'poltergeist', '~> 1.5.0'
36
+ spec.add_development_dependency 'factory_girl_rails'
37
+ spec.add_development_dependency 'database_cleaner'
36
38
  end
@@ -45,9 +45,7 @@ module Geoblacklight
45
45
  end
46
46
 
47
47
  def create_downloads_directory
48
- if !Dir.exists?('tmp/downloads')
49
- Dir.mkdir('tmp/downloads')
50
- end
48
+ FileUtils.mkdir_p("tmp/cache/downloads") unless File.directory?("tmp/cache/downloads")
51
49
  end
52
50
 
53
51
  # Necessary for bootstrap-sass 3.2
@@ -13,7 +13,7 @@ class Download
13
13
  end
14
14
 
15
15
  def file_path
16
- "#{Rails.root}/tmp/downloads/#{file_name}"
16
+ "#{Rails.root}/tmp/cache/downloads/#{file_name}"
17
17
  end
18
18
 
19
19
  def download_exists?
@@ -8,7 +8,11 @@ module Geoblacklight
8
8
  end
9
9
 
10
10
  def public?
11
- get(:dc_rights_s) == 'Public'
11
+ get(:dc_rights_s).downcase == 'public'
12
+ end
13
+
14
+ def restricted?
15
+ get(:dc_rights_s).downcase == 'restricted'
12
16
  end
13
17
 
14
18
  def downloadable?
@@ -20,7 +24,7 @@ module Geoblacklight
20
24
  end
21
25
 
22
26
  def same_institution?
23
- get(:dct_provenance_s) == Settings.Institution
27
+ get(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
24
28
  end
25
29
 
26
30
  def itemtype
@@ -1,3 +1,3 @@
1
1
  module Geoblacklight
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -22,7 +22,7 @@ namespace :geoblacklight do
22
22
  namespace :downloads do
23
23
  desc 'Delete all cached downloads'
24
24
  task delete: :environment do
25
- FileUtils.rm_rf Dir.glob("#{Rails.root}/tmp/downloads/*")
25
+ FileUtils.rm_rf Dir.glob("#{Rails.root}/tmp/cache/downloads/*")
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geoblacklight::DownloadController, type: :controller do
4
+ describe '#file' do
5
+ describe 'restricted file' do
6
+ it 'should redirect to login for authentication' do
7
+ get :file, id: 'stanford-jf841ys4828-shapefile', format: 'zip'
8
+ expect(response.status).to eq 401
9
+ end
10
+ end
11
+ describe 'public file' do
12
+ it 'should initiate download' do
13
+ expect(controller).to receive(:render)
14
+ expect(controller).to receive(:send_file)
15
+ get :file, id: 'mit-us-ma-e25zcta5dct-2000-shapefile', format: 'zip'
16
+ expect(response.status).to eq 200
17
+ end
18
+ end
19
+ end
20
+ describe '#show' do
21
+ describe 'restricted file' do
22
+ it 'should redirect to login for authentication' do
23
+ get 'show', id: 'stanford-jf841ys4828', format: 'json'
24
+ expect(response.status).to eq 401
25
+ end
26
+ end
27
+ describe 'public file' do
28
+ it 'should initiate download creation' do
29
+ get 'show', id: 'mit-us-ma-e25zcta5dct-2000'
30
+ expect(response.status).to eq 200
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ sequence(:email) { |n| "user#{n}@example.com" }
4
+ password 'password'
5
+ password_confirmation 'password'
6
+ end
7
+ end
@@ -1,18 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- feature 'Download layer', js: true do
4
- scenario 'clicking shapefile download button should trigger download' do
3
+ feature 'Download layer' do
4
+ scenario 'clicking shapefile download button should trigger download', js: true do
5
5
  expect_any_instance_of(ShapefileDownload).to receive(:get).and_return('mit-us-ma-e25zcta5dct-2000-shapefile.zip')
6
6
  visit catalog_path('mit-us-ma-e25zcta5dct-2000')
7
7
  find('button', text: 'Download').click
8
8
  find('a', text: 'Shapefile').click
9
9
  expect(page).to have_css('a', text: 'Your file mit-us-ma-e25zcta5dct-2000-shapefile.zip is ready for download')
10
10
  end
11
- scenario 'clicking kmz download button should trigger download' do
11
+ scenario 'clicking kmz download button should trigger download', js: true do
12
12
  expect_any_instance_of(KmzDownload).to receive(:get).and_return('mit-us-ma-e25zcta5dct-2000-kmz.kmz')
13
13
  visit catalog_path('mit-us-ma-e25zcta5dct-2000')
14
14
  find('button', text: 'Download').click
15
15
  find('a', text: 'KMZ').click
16
16
  expect(page).to have_css('a', text: 'Your file mit-us-ma-e25zcta5dct-2000-kmz.kmz is ready for download')
17
17
  end
18
+ scenario 'restricted layer should not have download available to non logged in user' do
19
+ visit catalog_path('stanford-jf841ys4828')
20
+ expect(page).to have_css 'a', text: 'Login to view and download'
21
+ expect(page).to_not have_css 'button', text: 'Download'
22
+ end
23
+ scenario 'restricted layer should have download available to logged in user' do
24
+ sign_in
25
+ visit catalog_path('stanford-jf841ys4828')
26
+ expect(page).to_not have_css 'a', text: 'Login to view and download'
27
+ expect(page).to have_css 'button', text: 'Download'
28
+ end
18
29
  end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  feature 'Layer inspection', js: true do
4
4
  scenario 'clicking map should trigger inspection' do
5
+ table_values = { values: [['Attribute']] }
6
+ expect_any_instance_of(WmsLayer).to receive(:get_feature_info).and_return(table_values)
5
7
  visit catalog_path('mit-us-ma-e25zcta5dct-2000')
6
8
  find('#map').click
7
9
  expect(page).to have_css('th', text: 'Attribute')
@@ -20,7 +20,7 @@ describe Download do
20
20
  end
21
21
  describe '#file_path' do
22
22
  it 'should return the path with name and extension' do
23
- expect(download.file_path).to eq "#{Rails.root}/tmp/downloads/#{download.file_name}"
23
+ expect(download.file_path).to eq "#{Rails.root}/tmp/cache/downloads/#{download.file_name}"
24
24
  end
25
25
  end
26
26
  describe '#download_exists?' do
@@ -21,13 +21,13 @@ describe Geoblacklight::SolrDocument do
21
21
  end
22
22
  describe '#public?' do
23
23
  describe 'a public document' do
24
- let(:document_attributes) { { dc_rights_s: 'Public' } }
24
+ let(:document_attributes) { { dc_rights_s: 'PUBLIC' } }
25
25
  it 'should be public' do
26
26
  expect(document.public?).to be_truthy
27
27
  end
28
28
  end
29
29
  describe 'a restricted resource' do
30
- let(:document_attributes) { { dc_rights_s: 'Restricted' } }
30
+ let(:document_attributes) { { dc_rights_s: 'RESTRICTED' } }
31
31
  it 'should not be public' do
32
32
  expect(document.public?).to be_falsey
33
33
  end
@@ -35,11 +35,15 @@ describe Geoblacklight::SolrDocument do
35
35
  end
36
36
  describe '#same_institution?' do
37
37
  describe 'within the same institution' do
38
- let(:document_attributes) { { dct_provenance_s: 'Stanford' } }
38
+ let(:document_attributes) { { dct_provenance_s: 'STANFORD' } }
39
39
  it 'should be true' do
40
40
  allow(Settings).to receive('Institution').and_return('Stanford')
41
41
  expect(document.same_institution?).to be_truthy
42
42
  end
43
+ it 'should match case inconsistencies' do
44
+ allow(Settings).to receive('Institution').and_return('StAnFord')
45
+ expect(document.same_institution).to be_truthy
46
+ end
43
47
  end
44
48
  describe 'within a different institution' do
45
49
  let(:document_attributes) { { dct_provenance_s: 'MIT' } }
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,14 @@
1
1
  ENV["RAILS_ENV"] ||= 'test'
2
2
 
3
+ require 'factory_girl'
4
+ require 'database_cleaner'
3
5
  require 'engine_cart'
4
6
  require 'coveralls'
5
7
  Coveralls.wear!('rails')
6
8
  EngineCart.load_application!
7
9
 
10
+ require 'rspec/rails'
11
+ require 'capybara/rspec'
8
12
  require 'capybara/poltergeist'
9
13
  Capybara.javascript_driver = :poltergeist
10
14
 
@@ -27,8 +31,26 @@ end
27
31
 
28
32
  require 'geoblacklight'
29
33
 
30
- require 'rspec/rails'
31
- require 'capybara/rspec'
34
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
35
+
36
+ FactoryGirl.definition_file_paths = [File.expand_path("../factories", __FILE__)]
37
+ FactoryGirl.find_definitions
32
38
 
33
39
  RSpec.configure do |config|
40
+ config.use_transactional_fixtures = false
41
+
42
+ config.before :each do
43
+ if Capybara.current_driver == :rack_test
44
+ DatabaseCleaner.strategy = :transaction
45
+ else
46
+ DatabaseCleaner.strategy = :truncation
47
+ end
48
+ DatabaseCleaner.start
49
+ end
50
+
51
+ config.after do
52
+ DatabaseCleaner.clean
53
+ end
54
+
55
+ config.include Devise::TestHelpers, type: :controller
34
56
  end
@@ -0,0 +1,20 @@
1
+ module Features
2
+ module SessionHelpers
3
+ def sign_up_with(email, password)
4
+ visit new_user_registration_path
5
+ fill_in 'Email', with: email
6
+ fill_in 'Password', with: password
7
+ click_button 'Sign up'
8
+ end
9
+
10
+ def sign_in
11
+ user = FactoryGirl.create(:user)
12
+ user.save
13
+ visit new_user_session_path
14
+ fill_in 'user_email', with: user.email
15
+ fill_in 'user_password', with: user.password
16
+ click_button 'Log in'
17
+ expect(page).to have_content 'Signed in successfully.'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../features/session_helpers.rb", __FILE__)
2
+
3
+ RSpec.configure do |config|
4
+ config.include Features::SessionHelpers, type: :feature
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoblacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Hardy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-10 00:00:00.000000000 Z
12
+ date: 2014-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 5.7.1
20
+ version: 5.7.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 5.7.1
27
+ version: 5.7.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: leaflet-rails
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +207,34 @@ dependencies:
207
207
  - - "~>"
208
208
  - !ruby/object:Gem::Version
209
209
  version: 1.5.0
210
+ - !ruby/object:Gem::Dependency
211
+ name: factory_girl_rails
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ - !ruby/object:Gem::Dependency
225
+ name: database_cleaner
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
210
238
  description: GeoBlacklight started at Stanford and its goal is to provide a world-class
211
239
  discovery platform for geospatial (GIS) holdings. It is an open collaborative project
212
240
  aiming to build off of the successes of the Blacklight Solr-powered discovery interface
@@ -281,6 +309,8 @@ files:
281
309
  - lib/geoblacklight/wms_layer.rb
282
310
  - lib/geoblacklight/wms_layer/feature_info_response.rb
283
311
  - lib/tasks/geoblacklight.rake
312
+ - spec/controllers/download_controller_spec.rb
313
+ - spec/factories/user.rb
284
314
  - spec/features/download_layer_spec.rb
285
315
  - spec/features/home_page_spec.rb
286
316
  - spec/features/layer_inspection_spec.rb
@@ -296,6 +326,8 @@ files:
296
326
  - spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb
297
327
  - spec/lib/geoblacklight/wms_layer_spec.rb
298
328
  - spec/spec_helper.rb
329
+ - spec/support/features.rb
330
+ - spec/support/features/session_helpers.rb
299
331
  - spec/test_app_templates/lib/generators/test_app_generator.rb
300
332
  - spec/views/catalog/_document_split.html.erb_spec.rb
301
333
  - spec/views/catalog/_index_split.html.erb_spec.rb
@@ -326,6 +358,8 @@ signing_key:
326
358
  specification_version: 4
327
359
  summary: A discovery platform for geospatial holdings
328
360
  test_files:
361
+ - spec/controllers/download_controller_spec.rb
362
+ - spec/factories/user.rb
329
363
  - spec/features/download_layer_spec.rb
330
364
  - spec/features/home_page_spec.rb
331
365
  - spec/features/layer_inspection_spec.rb
@@ -341,6 +375,8 @@ test_files:
341
375
  - spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb
342
376
  - spec/lib/geoblacklight/wms_layer_spec.rb
343
377
  - spec/spec_helper.rb
378
+ - spec/support/features.rb
379
+ - spec/support/features/session_helpers.rb
344
380
  - spec/test_app_templates/lib/generators/test_app_generator.rb
345
381
  - spec/views/catalog/_document_split.html.erb_spec.rb
346
382
  - spec/views/catalog/_index_split.html.erb_spec.rb