sufia 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README.md +6 -2
- data/app/assets/javascripts/sufia.js +1 -0
- data/app/assets/javascripts/sufia/trophy.js +26 -0
- data/app/assets/stylesheets/sufia.css.scss +1 -0
- data/app/assets/stylesheets/trophy.css +7 -0
- data/app/controllers/batch_controller.rb +1 -1
- data/app/controllers/batch_edits_controller.rb +3 -3
- data/app/controllers/single_use_link_controller.rb +9 -17
- data/app/controllers/users_controller.rb +33 -4
- data/app/helpers/generic_file_helper.rb +57 -5
- data/{lib/devise/models/http_header_authenticatable.rb → app/helpers/trophy_helper.rb} +11 -13
- data/app/models/datastreams/batch_rdf_datastream.rb +0 -1
- data/app/models/datastreams/generic_file_rdf_datastream.rb +0 -1
- data/app/models/trophy.rb +12 -0
- data/app/views/_user_util_links.html.erb +1 -1
- data/app/views/batch/edit.html.erb +2 -2
- data/app/views/batch_edits/{_delete_selected → _delete_selected.html.erb} +1 -1
- data/app/views/batch_edits/_metadata.html.erb +16 -15
- data/app/views/batch_edits/edit.html.erb +15 -23
- data/app/views/catalog/_recent_document.html.erb +2 -5
- data/app/views/dashboard/_index_partials/_default_group.html.erb +1 -1
- data/app/views/dashboard/_index_partials/_list_files.html.erb +7 -3
- data/app/views/dashboard/index.html.erb +7 -7
- data/app/views/error/404.html.erb +1 -1
- data/app/views/error/500.html.erb +1 -1
- data/app/views/generic_files/_descriptions.html.erb +3 -18
- data/app/views/generic_files/_field_form.html.erb +17 -0
- data/app/views/generic_files/_rights_modal.html.erb +1 -1
- data/app/views/generic_files/edit_fields/_default.html.erb +7 -0
- data/app/views/generic_files/edit_fields/_description.html.erb +6 -0
- data/app/views/generic_files/edit_fields/_rights.html.erb +8 -0
- data/app/views/generic_files/edit_fields/_suffix.html.erb +9 -0
- data/app/views/generic_files/edit_fields/_type.html.erb +9 -0
- data/app/views/single_use_link/show.html.erb +5 -11
- data/app/views/static/versions.html.erb +14 -0
- data/app/views/users/_trophy_edit.html.erb +21 -0
- data/app/views/users/edit.html.erb +3 -0
- data/app/views/users/index.html.erb +1 -1
- data/app/views/users/show.html.erb +9 -2
- data/config/locales/sufia.en.yml +24 -0
- data/config/routes.rb +8 -6
- data/features/support/cleanup.rb +2 -2
- data/lib/generators/sufia/sufia_generator.rb +1 -1
- data/lib/generators/sufia/templates/config/sufia.rb +0 -37
- data/lib/generators/sufia/templates/migrations/create_trophies.rb +10 -0
- data/lib/sufia/downloads_controller_behavior.rb +7 -9
- data/lib/sufia/files_controller_behavior.rb +4 -4
- data/lib/sufia/generic_file.rb +21 -27
- data/lib/sufia/jobs/batch_update_job.rb +1 -1
- data/lib/sufia/user.rb +23 -1
- data/lib/sufia/version.rb +1 -1
- data/lib/tasks/fixtures.rake +2 -3
- data/spec/controllers/generic_files_controller_spec.rb +7 -0
- data/spec/controllers/single_use_link_controller_spec.rb +0 -2
- data/spec/controllers/users_controller_spec.rb +28 -2
- data/spec/helpers/generic_file_helper_spec.rb +21 -0
- data/spec/models/generic_file_spec.rb +21 -5
- data/spec/models/trophy_spec.rb +26 -0
- data/spec/models/user_spec.rb +2 -2
- data/spec/routing/route_spec.rb +11 -11
- data/spec/support/Gemfile +2 -4
- data/sufia.gemspec +1 -0
- metadata +35 -15
- data/app/controllers/sessions_controller.rb +0 -30
- data/app/views/batch/_metadata.html.erb +0 -195
- data/app/views/generic_files/_field_form +0 -46
- data/lib/devise/strategies/http_header_authenticatable.rb +0 -43
- data/lib/generators/sufia/templates/config/devise.rb +0 -222
- data/lib/redirect_to_web_access_failure.rb +0 -27
- data/lib/sufia/http_header_auth.rb +0 -60
- data/spec/config/host_to_vhost_spec.rb +0 -38
- data/spec/controllers/sessions_controller_spec.rb +0 -44
data/config/routes.rb
CHANGED
@@ -8,7 +8,7 @@ Sufia::Engine.routes.draw do
|
|
8
8
|
|
9
9
|
# Route path-less requests to the index view of catalog
|
10
10
|
root :to => "catalog#index"
|
11
|
-
|
11
|
+
|
12
12
|
# "Recently added files" route for catalog index view
|
13
13
|
match "catalog/recent" => "catalog#recent", :as => :catalog_recent
|
14
14
|
|
@@ -26,11 +26,6 @@ Sufia::Engine.routes.draw do
|
|
26
26
|
# Downloads controller route
|
27
27
|
resources :downloads, :only => "show"
|
28
28
|
|
29
|
-
# Login/logout route to destroy session
|
30
|
-
# can just be in the PSU scholarsphere
|
31
|
-
match 'logout' => 'sessions#destroy', :as => :destroy_user_session
|
32
|
-
match 'login' => 'sessions#new', :as => :new_user_session
|
33
|
-
|
34
29
|
# Messages
|
35
30
|
match 'notifications' => 'mailbox#index', :as => :mailbox
|
36
31
|
match 'notifications/delete_all' => 'mailbox#delete_all', :as => :mailbox_delete_all
|
@@ -41,6 +36,10 @@ Sufia::Engine.routes.draw do
|
|
41
36
|
match 'users/:uid' => 'users#show', :as => :profile
|
42
37
|
match 'users/:uid/edit' => 'users#edit', :as => :edit_profile
|
43
38
|
match 'users/:uid/update' => 'users#update', :as => :update_profile, :via => :put
|
39
|
+
match "users/:uid/trophy" => "users#toggle_trophy", :as => :update_trophy_user, :via => :post
|
40
|
+
|
41
|
+
|
42
|
+
|
44
43
|
match 'users/:uid/follow' => 'users#follow', :as => :follow_user
|
45
44
|
match 'users/:uid/unfollow' => 'users#unfollow', :as => :unfollow_user
|
46
45
|
|
@@ -82,6 +81,9 @@ Sufia::Engine.routes.draw do
|
|
82
81
|
|
83
82
|
# Static page routes (workaround)
|
84
83
|
match ':action' => 'static#:action', :constraints => { :action => /about|help|terms|zotero|mendeley|agreement|subject_libraries|versions/ }, :as => :static
|
84
|
+
|
85
|
+
# Catch-all (for routing errors)
|
86
|
+
match '*error' => 'errors#routing'
|
85
87
|
|
86
88
|
end
|
87
89
|
|
data/features/support/cleanup.rb
CHANGED
@@ -35,7 +35,7 @@ This generator makes the following changes to your application:
|
|
35
35
|
# Can't get this any more DRY, because we need this order.
|
36
36
|
%w{acts_as_follower_migration.rb add_social_to_users.rb create_single_use_links.rb add_ldap_attrs_to_user.rb
|
37
37
|
add_avatars_to_users.rb create_checksum_audit_logs.rb create_version_committers.rb
|
38
|
-
add_groups_to_users.rb create_local_authorities.rb}.each do |f|
|
38
|
+
add_groups_to_users.rb create_local_authorities.rb create_trophies.rb}.each do |f|
|
39
39
|
better_migration_template f
|
40
40
|
end
|
41
41
|
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'sufia/http_header_auth'
|
3
|
-
|
4
|
-
# TODO move this method to HttpAuth initializer
|
5
1
|
# Returns an array containing the vhost 'CoSign service' value and URL
|
6
2
|
Sufia.config do |config|
|
7
3
|
config.id_namespace = "sufia"
|
@@ -13,21 +9,6 @@ Sufia.config do |config|
|
|
13
9
|
|
14
10
|
config.max_days_between_audits = 7
|
15
11
|
|
16
|
-
# TODO move these to an HttpAuth initializer
|
17
|
-
# Map hostnames onto vhosts
|
18
|
-
config.hosts_vhosts_map = {
|
19
|
-
'fedora1test' => 'https://scholarsphere-integration.dlt.psu.edu:8443/',
|
20
|
-
'fedora2test' => 'https://scholarsphere-test.dlt.psu.edu/',
|
21
|
-
'ss1stage' => 'https://scholarsphere-staging.dlt.psu.edu/',
|
22
|
-
'ss2stage' => 'https://scholarsphere-staging.dlt.psu.edu/',
|
23
|
-
'ss1prod' => 'https://scholarsphere.psu.edu/',
|
24
|
-
'ss2prod' => 'https://scholarsphere.psu.edu/'
|
25
|
-
}
|
26
|
-
|
27
|
-
# TODO move these to an HttpAuth initializer
|
28
|
-
config.logout_url = "https://webaccess.psu.edu/cgi-bin/logout?#{Sufia::HttpHeaderAuth.get_vhost_by_host(config)[1]}"
|
29
|
-
config.login_url = "https://webaccess.psu.edu?cosign-#{Sufia::HttpHeaderAuth.get_vhost_by_host(config)[0]}&#{Sufia::HttpHeaderAuth.get_vhost_by_host(config)[1]}"
|
30
|
-
|
31
12
|
config.cc_licenses = {
|
32
13
|
'Attribution 3.0 United States' => 'http://creativecommons.org/licenses/by/3.0/us/',
|
33
14
|
'Attribution-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-sa/3.0/us/',
|
@@ -65,24 +46,6 @@ Sufia.config do |config|
|
|
65
46
|
"Other" => "Other",
|
66
47
|
}
|
67
48
|
|
68
|
-
# reflect a field name change (should one happen) in the generic file datastream
|
69
|
-
config.metadata_help = {
|
70
|
-
"generic_file_resource_type" => "Pre-defined categories to describe the type of file content being uploaded, such as \"article\" or \"dataset.\" More than one type may be selected.",
|
71
|
-
"generic_file_title" => "A name for the file to aid in identifying it. Defaults to the file name, though a more descriptive title is encouraged. <em>This is a required field</em>.",
|
72
|
-
"generic_file_tag" => "Words or phrases you select to describe what the file is about. These are used to search for content. <em>This is a required field</em>.",
|
73
|
-
"generic_file_subject" => "Headings or index terms describing what the file is about; these <em>do</em> need to conform to an existing vocabulary. Currently ScholarSphere supports Library of Congress Subject Headings.",
|
74
|
-
"generic_file_creator" => "The person or group responsible for the file being uploaded. Usually this is the author of the content. Personal names should be entered with the last name first, e.g. \"Smith, John.\" <em>This is a required field</em>.",
|
75
|
-
"generic_file_related_url" => "A link to a website or other specific content (audio, video, PDF document) related to the file. An example is the URL of a research project from which the file was derived.",
|
76
|
-
"generic_file_based_near" => "A place name related to the file, such as its site of publication, or the city, state, or country the file's contents are about. Calls upon the GeoNames web service (<a href=\"http://www.geonames.org\">http://www.geonames.org</a>).",
|
77
|
-
"generic_file_contributor" => "A person or group you want to recognize for playing a role in the creation of the file, but not the primary role. If there is a specific role you would like noted, include it in parentheses, e.g. \"Jones, Mary (advisor).\"",
|
78
|
-
"generic_file_date_created" => "The date on which the file was generated. Dates are accepted in the form YYYY-MM-DD, e.g. 1776-07-04.",
|
79
|
-
"generic_file_description" => "Free-text notes about the file itself. Examples include abstracts of a paper, citation information for a journal article, or a tag indicating a larger collection to which the file belongs.",
|
80
|
-
"generic_file_identifier" => "A unique handle describing the file. An example would be a DOI for a journal article, or an ISBN or OCLC number for a book.",
|
81
|
-
"generic_file_language" => " The language of the file content.",
|
82
|
-
"generic_file_publisher" => "The person or group making the file available. Generally this is Penn State or the Penn State University Libraries.",
|
83
|
-
"generic_file_rights" => "Licensing and distribution information governing access to the file. Select from the provided drop-down list. <em>This is a required field</em>."
|
84
|
-
}
|
85
|
-
|
86
49
|
config.permission_levels = {
|
87
50
|
"Choose Access"=>"none",
|
88
51
|
"View/Download" => "read",
|
@@ -26,10 +26,9 @@ module Sufia
|
|
26
26
|
|
27
27
|
def show
|
28
28
|
if can? :read, params["id"]
|
29
|
-
|
30
|
-
|
31
|
-
send_content (
|
32
|
-
return
|
29
|
+
asset = ActiveFedora::Base.find(params[:id], :cast=>true)
|
30
|
+
# we can now examine @asset and determine if we should send_content, or some other action.
|
31
|
+
send_content (asset)
|
33
32
|
else
|
34
33
|
logger.info "Can not read #{params['id']}"
|
35
34
|
redirect_to "/assets/NoAccess.png"
|
@@ -38,17 +37,16 @@ module Sufia
|
|
38
37
|
|
39
38
|
protected
|
40
39
|
|
41
|
-
def send_content (
|
42
|
-
@asset = ActiveFedora::Base.find(id, :cast=>true)
|
40
|
+
def send_content (asset)
|
43
41
|
opts = {}
|
44
42
|
ds = nil
|
45
|
-
opts[:filename] = params["filename"] ||
|
43
|
+
opts[:filename] = params["filename"] || asset.label
|
46
44
|
opts[:disposition] = 'inline'
|
47
45
|
if params.has_key?(:datastream_id)
|
48
46
|
opts[:filename] = params[:datastream_id]
|
49
|
-
ds =
|
47
|
+
ds = asset.datastreams[params[:datastream_id]]
|
50
48
|
end
|
51
|
-
ds = default_content_ds(
|
49
|
+
ds = default_content_ds(asset) if ds.nil?
|
52
50
|
raise ActionController::RoutingError.new('Not Found') if ds.nil?
|
53
51
|
data = ds.content
|
54
52
|
opts[:type] = ds.mimeType
|
@@ -55,7 +55,7 @@ module Sufia
|
|
55
55
|
|
56
56
|
# routed to /files/:id/edit
|
57
57
|
def edit
|
58
|
-
@terms = @generic_file.
|
58
|
+
@terms = @generic_file.terms_for_editing
|
59
59
|
@groups = current_user.groups
|
60
60
|
end
|
61
61
|
|
@@ -199,8 +199,8 @@ module Sufia
|
|
199
199
|
add_posted_blob_to_asset(@generic_file,file, file_name)
|
200
200
|
|
201
201
|
@generic_file.apply_depositor_metadata(user_key)
|
202
|
-
@generic_file.date_uploaded =
|
203
|
-
@generic_file.date_modified =
|
202
|
+
@generic_file.date_uploaded = Date.today
|
203
|
+
@generic_file.date_modified = Date.today
|
204
204
|
@generic_file.relative_path = relative_path if relative_path
|
205
205
|
@generic_file.creator = current_user.name
|
206
206
|
|
@@ -217,7 +217,7 @@ module Sufia
|
|
217
217
|
logger.warn "GenericFilesController::create_and_save_generic_file Caught RSOLR error #{error.inspect}"
|
218
218
|
save_tries+=1
|
219
219
|
# fail for good if the tries is greater than 3
|
220
|
-
|
220
|
+
raise error if save_tries >=3
|
221
221
|
sleep 0.01
|
222
222
|
retry
|
223
223
|
end
|
data/lib/sufia/generic_file.rb
CHANGED
@@ -37,6 +37,12 @@ module Sufia
|
|
37
37
|
around_save :characterize_if_changed, :retry_warming
|
38
38
|
end
|
39
39
|
|
40
|
+
def delete
|
41
|
+
self.cleanup_trophies
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
|
40
46
|
def pdf?
|
41
47
|
["application/pdf"].include? self.mime_type
|
42
48
|
end
|
@@ -85,6 +91,11 @@ module Sufia
|
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
94
|
+
def cleanup_trophies
|
95
|
+
Trophy.destroy_all(generic_file_id: self.noid)
|
96
|
+
end
|
97
|
+
|
98
|
+
|
88
99
|
def related_files
|
89
100
|
relateds = begin
|
90
101
|
self.batch.generic_files
|
@@ -104,9 +115,6 @@ module Sufia
|
|
104
115
|
solr_doc["noid_s"] = noid
|
105
116
|
solr_doc["file_format_t"] = file_format
|
106
117
|
solr_doc["file_format_facet"] = solr_doc["file_format_t"]
|
107
|
-
# remap dates as a valid xml date not to_s
|
108
|
-
solr_doc['generic_file__date_uploaded_dt'] = Time.parse(date_uploaded).utc.to_s.sub(' ','T').sub(' UTC','Z') rescue Time.new(date_uploaded).utc.to_s.sub(' ','T').sub(' UTC','Z') unless date_uploaded.blank?
|
109
|
-
solr_doc['generic_file__date_modified_dt'] = Time.parse(date_modified).utc.to_s.sub(' ','T').sub(' UTC','Z') rescue Time.new(date_modified).utc.to_s.sub(' ','T').sub(' UTC','Z') unless date_modified.blank?
|
110
118
|
return solr_doc
|
111
119
|
end
|
112
120
|
|
@@ -140,15 +148,13 @@ module Sufia
|
|
140
148
|
}
|
141
149
|
end
|
142
150
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
151
|
-
terms
|
151
|
+
def terms_for_editing
|
152
|
+
terms_for_display -
|
153
|
+
[:part_of, :date_modified, :date_uploaded, :format, :resource_type]
|
154
|
+
end
|
155
|
+
|
156
|
+
def terms_for_display
|
157
|
+
self.descMetadata.class.config.keys
|
152
158
|
end
|
153
159
|
|
154
160
|
def get_values
|
@@ -156,11 +162,10 @@ module Sufia
|
|
156
162
|
values = {}
|
157
163
|
terms.each do |t|
|
158
164
|
next if t.empty?
|
159
|
-
|
160
|
-
|
161
|
-
values[key] = self.send(key) if self.respond_to?(key)
|
165
|
+
next if ['part_of', 'date_modified', 'date_uploaded'].include?(t)
|
166
|
+
values[t] = self.send(key) if self.respond_to?(key)
|
162
167
|
end
|
163
|
-
|
168
|
+
values
|
164
169
|
end
|
165
170
|
|
166
171
|
# Is this file in the middle of being processed by a batch?
|
@@ -170,16 +175,5 @@ module Sufia
|
|
170
175
|
return (!self.batch.status.empty?) && (self.batch.status.count == 1) && (self.batch.status[0] == "processing")
|
171
176
|
end
|
172
177
|
|
173
|
-
module ClassMethods
|
174
|
-
# TODO this could probably be better handled by i18n
|
175
|
-
@@FIELD_LABEL_MAP = {"based_near"=>"Location", 'description'=>"Abstract or Summary", 'tag'=>"Keyword", 'date_created'=>"Date Created", 'related_url'=>"Related URL"}
|
176
|
-
|
177
|
-
def get_label(key)
|
178
|
-
label = @@FIELD_LABEL_MAP[key]
|
179
|
-
label = key.gsub('_',' ').titleize if label.blank?
|
180
|
-
return label
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
178
|
end
|
185
179
|
end
|
@@ -70,7 +70,7 @@ class BatchUpdateJob
|
|
70
70
|
save_tries += 1
|
71
71
|
logger.warn "BatchUpdateJob caught RSOLR error on #{gf.pid}: #{error.inspect}"
|
72
72
|
# fail for good if the tries is greater than 3
|
73
|
-
|
73
|
+
raise error if save_tries >=3
|
74
74
|
sleep 0.01
|
75
75
|
retry
|
76
76
|
end #
|
data/lib/sufia/user.rb
CHANGED
@@ -63,7 +63,24 @@ module Sufia::User
|
|
63
63
|
|
64
64
|
# Redefine this for more intuitive keys in Redis
|
65
65
|
def to_param
|
66
|
-
|
66
|
+
# hack because rails doesn't like periods in urls.
|
67
|
+
user_key.gsub(/\./, '-dot-')
|
68
|
+
end
|
69
|
+
|
70
|
+
# method needed for trophies
|
71
|
+
def trophies
|
72
|
+
trophies = Trophy.where(user_id:self.id)
|
73
|
+
return trophies
|
74
|
+
end
|
75
|
+
|
76
|
+
#method to get the trophy ids without the namespace included
|
77
|
+
def trophy_ids
|
78
|
+
trophies=[]
|
79
|
+
trophies.each do |t|
|
80
|
+
@trophies << GenericFile.find("#{Sufia::Engine.config.id_namespace}:#{t.generic_file_id}")
|
81
|
+
|
82
|
+
end
|
83
|
+
return trophies
|
67
84
|
end
|
68
85
|
|
69
86
|
# method needed for messaging
|
@@ -108,6 +125,11 @@ module Sufia::User
|
|
108
125
|
def batchuser_key
|
109
126
|
'batchuser@example.com'
|
110
127
|
end
|
128
|
+
|
129
|
+
def from_url_component(component)
|
130
|
+
User.find_by_user_key(component.gsub(/-dot-/, '.'))
|
131
|
+
end
|
132
|
+
|
111
133
|
end
|
112
134
|
|
113
135
|
end
|
data/lib/sufia/version.rb
CHANGED
data/lib/tasks/fixtures.rake
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# The files should be named id_[fixture id] which should relates to the id within the foxml sufia:[fixture id] where
|
22
22
|
# [fixture id] is some alpha numeric id ('test1')
|
23
23
|
#
|
24
|
-
# There are 2 sets of data needed to attach to a
|
24
|
+
# There are 2 sets of data needed to attach to a sufia fixture, 1 the data file, and 2 the metadata.
|
25
25
|
# It is important that the meta-data contains the appropriate id, or solor will not index it!
|
26
26
|
#
|
27
27
|
# Usage: rake sufia:fixtures:create [DIR=<fixture dir>] [FIXTURE_ID=<fixture id>] [FIXTURE_TITLE=<fixture title>] [FIXTURE_USER=<fixture user>]
|
@@ -38,7 +38,7 @@
|
|
38
38
|
# DEFAULT: archivist1
|
39
39
|
#
|
40
40
|
#
|
41
|
-
# Creates new fixture files including the erb, descMeta, and text for loading into
|
41
|
+
# Creates new fixture files including the erb, descMeta, and text for loading into sufia.
|
42
42
|
# The Files are named based on the sufia: id_<fixture id>.foxml.erb, id_<fixture id>.descMeta.txt, and id_<fixture id>.txt
|
43
43
|
# The foxml.erb file references the descMeta.txt and .txt file. You can edit the erb to point to other data and/or edit the
|
44
44
|
# .descMeta.txt and/or .txt file to contain the data you wish.
|
@@ -228,7 +228,6 @@ namespace :sufia do
|
|
228
228
|
User.create(email: 'archivist1@example.com')#, display_name: 'Captain Archivist')
|
229
229
|
# Then, set this user as the depositor of test4 to appease this damn failing cuke
|
230
230
|
gf = GenericFile.find('sufia:test4')
|
231
|
-
gf.terms_of_service = '1'
|
232
231
|
gf.apply_depositor_metadata('archivist1@example.com')
|
233
232
|
gf.save
|
234
233
|
end
|
@@ -161,6 +161,13 @@ describe GenericFilesController do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
it "should error out of create and save after on continuos rsolr error" do
|
165
|
+
GenericFile.any_instance.stub(:save).and_raise(RSolr::Error::Http.new({},{}))
|
166
|
+
|
167
|
+
file = fixture_file_upload('/world.png','image/png')
|
168
|
+
xhr :post, :create, :files=>[file], :Filename=>"The world", :batch_id => "sample:batch_id", :permission=>{"group"=>{"public"=>"read"} }, :terms_of_service=>"1"
|
169
|
+
response.body.should include("Error occurred while creating generic file.")
|
170
|
+
end
|
164
171
|
|
165
172
|
end
|
166
173
|
|
@@ -51,14 +51,14 @@ describe UsersController do
|
|
51
51
|
it "redirects to show profile when user attempts to edit another profile" do
|
52
52
|
get :edit, uid: @another_user.user_key
|
53
53
|
response.should redirect_to(@routes.url_helpers.profile_path(URI.escape(@another_user.user_key,'@.')))
|
54
|
-
flash[:alert].should include("
|
54
|
+
flash[:alert].should include("Permission denied: cannot access this page.")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
describe "#update" do
|
58
58
|
it "should not allow other users to update" do
|
59
59
|
post :update, uid: @another_user.user_key, user: { avatar: nil }
|
60
60
|
response.should redirect_to(@routes.url_helpers.profile_path(URI.escape(@another_user.user_key,'@.')))
|
61
|
-
flash[:alert].should include("
|
61
|
+
flash[:alert].should include("Permission denied: cannot access this page.")
|
62
62
|
end
|
63
63
|
it "should set an avatar and redirect to profile" do
|
64
64
|
@user.avatar.file?.should be_false
|
@@ -173,4 +173,30 @@ describe UsersController do
|
|
173
173
|
flash[:alert].should include("You cannot follow or unfollow yourself")
|
174
174
|
end
|
175
175
|
end
|
176
|
+
describe "#toggle_trophy" do
|
177
|
+
before do
|
178
|
+
@file = GenericFile.new()
|
179
|
+
@file.apply_depositor_metadata(@user.user_key)
|
180
|
+
@file.save
|
181
|
+
@file_id = @file.pid.split(":").last
|
182
|
+
end
|
183
|
+
after do
|
184
|
+
@file.delete
|
185
|
+
end
|
186
|
+
it "should trophy a file" do
|
187
|
+
post :toggle_trophy, {uid: @user.user_key, file_id: @file_id}
|
188
|
+
JSON.parse(response.body)['user_id'].should == @user.id
|
189
|
+
JSON.parse(response.body)['generic_file_id'].should == @file_id
|
190
|
+
end
|
191
|
+
it "should not trophy a file for a different user" do
|
192
|
+
post :toggle_trophy, {uid: @another_user.user_key, file_id: @file_id}
|
193
|
+
response.should_not be_success
|
194
|
+
end
|
195
|
+
it "should not trophy a file with no edit privs" do
|
196
|
+
sign_out @user
|
197
|
+
sign_in @another_user
|
198
|
+
post :toggle_trophy, {uid: @another_user.user_key, file_id: @file_id}
|
199
|
+
response.should_not be_success
|
200
|
+
end
|
201
|
+
end
|
176
202
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GenericFileHelper do
|
4
|
+
it "draws add button" do
|
5
|
+
helper.add_field(:test).should ==
|
6
|
+
"<button class=\"adder btn\" id=\"additional_test_submit\" name=\"additional_test\">+<span class=\"accessible-hidden\">add another test</span></button>"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "draws subtract button" do
|
10
|
+
helper.subtract_field(:test).should ==
|
11
|
+
"<button class=\"remover btn\" id=\"additional_test_submit\" name=\"additional_test\">-<span class=\"accessible-hidden\">add another test</span></button>"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "draws help_icon" do
|
15
|
+
helper.help_icon(:tag).should ==
|
16
|
+
"<a href=\"#\" data-content=\"Words or phrases you select to describe what the file is about. These are used to search for content. <em>This is a required field</em>.\" data-original-title=\"Keyword\" id=\"generic_file_tag_help\" rel=\"popover\"><i class=\"icon-question-sign icon-large\"></i></a>"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|