sufia 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,46 +0,0 @@
|
|
1
|
-
<% render_req = true if render_req.blank? %>
|
2
|
-
<div class="control-group">
|
3
|
-
<% vals = generic_file.send(key) %>
|
4
|
-
<% # not an arry lets just shove it in one %>
|
5
|
-
<% vals = [vals] unless vals.is_a?(Array) %>
|
6
|
-
<%# if vals is zero we create an empty array to loop over for output %>
|
7
|
-
<% vals = [''] if vals.count == 0 %>
|
8
|
-
<% label = GenericFile::get_label(key) %>
|
9
|
-
<% vals.each_with_index do |v, index| %>
|
10
|
-
<% req = render_req && (index == 0) && (["title", "creator", "tag", "rights"].include?(key)) %>
|
11
|
-
<% if req %>
|
12
|
-
<% tmp = '<span class="error">*</span>' + label %>
|
13
|
-
<%= f.label key, tmp.html_safe, :class=>"control-label" if index == 0 %>
|
14
|
-
<% else %>
|
15
|
-
<%= f.label key, label, :class=>"control-label" if index == 0 %>
|
16
|
-
<% end %>
|
17
|
-
<div class="controls" <% if index == 0%> id="additional_<%= key %>_clone" <% end %>>
|
18
|
-
<% if key == "description" %>
|
19
|
-
<%= f.text_area :description, :name=>"generic_file[#{key}][]", :id => "generic_file_"+key, :value=>v, :class => "input-large" %>
|
20
|
-
<% elsif key == "rights" %>
|
21
|
-
<% choices = Sufia::Engine.config.cc_licenses %>
|
22
|
-
<% choices = {""=>""}.merge(choices) %>
|
23
|
-
<%= f.select "rights", options_for_select(choices, v) %>
|
24
|
-
<% elsif key == "resource_type" %>
|
25
|
-
<% if (index == 0) %>
|
26
|
-
<p class="help-block">You may select multiple types to apply<p>
|
27
|
-
<% choices = Sufia::Engine.config.resource_types.keys %>
|
28
|
-
<%= f.select "resource_type", options_for_select(choices, vals.to_a), {}, {:multiple=>true, :size=>7} %>
|
29
|
-
<%end%>
|
30
|
-
<% else %>
|
31
|
-
<%= f.text_field :title, :name=>"generic_file[#{key}][]", :id => "generic_file_"+key, :value=>v, :class => "input-large", :required => req %>
|
32
|
-
<% end %>
|
33
|
-
<% if index == 0 %>
|
34
|
-
<% if (key != "resource_type") %>
|
35
|
-
<button class="adder btn" name="additional_<%= key %>" id="additional_<%= key %>_submit">+<span class="accessible-hidden">add another <%= key %></span></button>
|
36
|
-
|
37
|
-
<% end %>
|
38
|
-
<a href="#" id="generic_file_<%= key %>_help" rel="popover" data-content="<%= Sufia::Engine.config.metadata_help['generic_file_' + key] %>" data-original-title="<%= label %>"><i class="icon-question-sign icon-large"></i></a>
|
39
|
-
<%= render :partial => "generic_files/rights_modal" if key == "rights" %>
|
40
|
-
<% elsif (key != "resource_type") %>
|
41
|
-
<button class="remover btn" name="additional_<%= key %>" id="additional_<%= key %>_submit">-<span class="accessible-hidden">add another <%= key %></span></button>
|
42
|
-
<% end %>
|
43
|
-
</div><!-- /controls -->
|
44
|
-
<div id="additional_<%= key %>_elements"></div>
|
45
|
-
<% end %>
|
46
|
-
</div><!-- /control-group -->
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
# Default strategy for signing in a user, based on his email and password in the database.
|
16
|
-
module Devise
|
17
|
-
module Strategies
|
18
|
-
class HttpHeaderAuthenticatable < ::Devise::Strategies::Base
|
19
|
-
|
20
|
-
# Called if the user doesn't already have a rails session cookie
|
21
|
-
def valid?
|
22
|
-
request.headers['REMOTE_USER'].present?
|
23
|
-
end
|
24
|
-
|
25
|
-
def authenticate!
|
26
|
-
remote_user = request.headers['REMOTE_USER']
|
27
|
-
if remote_user.present?
|
28
|
-
u = User.find_by_login(remote_user)
|
29
|
-
if u.nil?
|
30
|
-
u = User.create(:login => remote_user)
|
31
|
-
u.populate_attributes
|
32
|
-
end
|
33
|
-
success!(u)
|
34
|
-
else
|
35
|
-
fail!
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
Warden::Strategies.add(:http_header_authenticatable, Devise::Strategies::HttpHeaderAuthenticatable)
|
43
|
-
|
@@ -1,222 +0,0 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
# Use this hook to configure devise mailer, warden hooks and so forth.
|
16
|
-
# Many of these configuration options can be set straight in your model.
|
17
|
-
Devise.setup do |config|
|
18
|
-
# ==> Mailer Configuration
|
19
|
-
# Configure the e-mail address which will be shown in Devise::Mailer,
|
20
|
-
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
21
|
-
config.mailer_sender = "mjg36@psu.edu"
|
22
|
-
|
23
|
-
# Configure the class responsible to send e-mails.
|
24
|
-
# config.mailer = "Devise::Mailer"
|
25
|
-
|
26
|
-
# ==> ORM configuration
|
27
|
-
# Load and configure the ORM. Supports :active_record (default) and
|
28
|
-
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
29
|
-
# available as additional gems.
|
30
|
-
require 'devise/orm/active_record'
|
31
|
-
|
32
|
-
# ==> Configuration for any authentication mechanism
|
33
|
-
# Configure which keys are used when authenticating a user. The default is
|
34
|
-
# just :email. You can configure it to use [:username, :subdomain], so for
|
35
|
-
# authenticating a user, both parameters are required. Remember that those
|
36
|
-
# parameters are used only when authenticating and not when retrieving from
|
37
|
-
# session. If you need permissions, you should implement that in a before filter.
|
38
|
-
# You can also supply a hash where the value is a boolean determining whether
|
39
|
-
# or not authentication should be aborted when the value is not present.
|
40
|
-
config.authentication_keys = [ :login ]
|
41
|
-
|
42
|
-
# Configure parameters from the request object used for authentication. Each entry
|
43
|
-
# given should be a request method and it will automatically be passed to the
|
44
|
-
# find_for_authentication method and considered in your model lookup. For instance,
|
45
|
-
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
46
|
-
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
47
|
-
# config.request_keys = []
|
48
|
-
|
49
|
-
# Configure which authentication keys should be case-insensitive.
|
50
|
-
# These keys will be downcased upon creating or modifying a user and when used
|
51
|
-
# to authenticate or find a user. Default is :email.
|
52
|
-
config.case_insensitive_keys = [ :email ]
|
53
|
-
|
54
|
-
# Configure which authentication keys should have whitespace stripped.
|
55
|
-
# These keys will have whitespace before and after removed upon creating or
|
56
|
-
# modifying a user and when used to authenticate or find a user. Default is :email.
|
57
|
-
config.strip_whitespace_keys = [ :email ]
|
58
|
-
|
59
|
-
# Tell if authentication through request.params is enabled. True by default.
|
60
|
-
# config.params_authenticatable = true
|
61
|
-
|
62
|
-
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
63
|
-
# config.http_authenticatable = false
|
64
|
-
|
65
|
-
# If http headers should be returned for AJAX requests. True by default.
|
66
|
-
# config.http_authenticatable_on_xhr = true
|
67
|
-
|
68
|
-
# The realm used in Http Basic Authentication. "Application" by default.
|
69
|
-
# config.http_authentication_realm = "Application"
|
70
|
-
|
71
|
-
# It will change confirmation, password recovery and other workflows
|
72
|
-
# to behave the same regardless if the e-mail provided was right or wrong.
|
73
|
-
# Does not affect registerable.
|
74
|
-
# config.paranoid = true
|
75
|
-
|
76
|
-
# ==> Configuration for :database_authenticatable
|
77
|
-
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
78
|
-
# using other encryptors, it sets how many times you want the password re-encrypted.
|
79
|
-
#
|
80
|
-
# Limiting the stretches to just one in testing will increase the performance of
|
81
|
-
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
82
|
-
# a value less than 10 in other environments.
|
83
|
-
config.stretches = Rails.env.test? ? 1 : 10
|
84
|
-
|
85
|
-
# Setup a pepper to generate the encrypted password.
|
86
|
-
# config.pepper = "bdef20685f0d49bf989cdee73308234366b35b618048ac0871aaaaa4b07f8ce449cd49a16637b8cc1e2de2d71befe322e6496d295299af064309c0b87514bdd8"
|
87
|
-
|
88
|
-
# ==> Configuration for :confirmable
|
89
|
-
# A period that the user is allowed to access the website even without
|
90
|
-
# confirming his account. For instance, if set to 2.days, the user will be
|
91
|
-
# able to access the website for two days without confirming his account,
|
92
|
-
# access will be blocked just in the third day. Default is 0.days, meaning
|
93
|
-
# the user cannot access the website without confirming his account.
|
94
|
-
# config.confirm_within = 2.days
|
95
|
-
|
96
|
-
# Defines which key will be used when confirming an account
|
97
|
-
# config.confirmation_keys = [ :email ]
|
98
|
-
|
99
|
-
# ==> Configuration for :rememberable
|
100
|
-
# The time the user will be remembered without asking for credentials again.
|
101
|
-
# config.remember_for = 2.weeks
|
102
|
-
|
103
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
104
|
-
# config.remember_across_browsers = true
|
105
|
-
|
106
|
-
# If true, extends the user's remember period when remembered via cookie.
|
107
|
-
# config.extend_remember_period = false
|
108
|
-
|
109
|
-
# Options to be passed to the created cookie. For instance, you can set
|
110
|
-
# :secure => true in order to force SSL only cookies.
|
111
|
-
# config.cookie_options = {}
|
112
|
-
|
113
|
-
# ==> Configuration for :validatable
|
114
|
-
# Range for password length. Default is 6..128.
|
115
|
-
# config.password_length = 6..128
|
116
|
-
|
117
|
-
# Email regex used to validate email formats. It simply asserts that
|
118
|
-
# an one (and only one) @ exists in the given string. This is mainly
|
119
|
-
# to give user feedback and not to assert the e-mail validity.
|
120
|
-
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
121
|
-
|
122
|
-
# ==> Configuration for :timeoutable
|
123
|
-
# The time you want to timeout the user session without activity. After this
|
124
|
-
# time the user will be asked for credentials again. Default is 30 minutes.
|
125
|
-
# config.timeout_in = 30.minutes
|
126
|
-
|
127
|
-
# ==> Configuration for :lockable
|
128
|
-
# Defines which strategy will be used to lock an account.
|
129
|
-
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
130
|
-
# :none = No lock strategy. You should handle locking by yourself.
|
131
|
-
# config.lock_strategy = :failed_attempts
|
132
|
-
|
133
|
-
# Defines which key will be used when locking and unlocking an account
|
134
|
-
# config.unlock_keys = [ :email ]
|
135
|
-
|
136
|
-
# Defines which strategy will be used to unlock an account.
|
137
|
-
# :email = Sends an unlock link to the user email
|
138
|
-
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
139
|
-
# :both = Enables both strategies
|
140
|
-
# :none = No unlock strategy. You should handle unlocking by yourself.
|
141
|
-
# config.unlock_strategy = :both
|
142
|
-
|
143
|
-
# Number of authentication tries before locking an account if lock_strategy
|
144
|
-
# is failed attempts.
|
145
|
-
# config.maximum_attempts = 20
|
146
|
-
|
147
|
-
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
148
|
-
# config.unlock_in = 1.hour
|
149
|
-
|
150
|
-
# ==> Configuration for :recoverable
|
151
|
-
#
|
152
|
-
# Defines which key will be used when recovering the password for an account
|
153
|
-
# config.reset_password_keys = [ :email ]
|
154
|
-
|
155
|
-
# Time interval you can reset your password with a reset password key.
|
156
|
-
# Don't put a too small interval or your users won't have the time to
|
157
|
-
# change their passwords.
|
158
|
-
config.reset_password_within = 2.hours
|
159
|
-
|
160
|
-
# ==> Configuration for :encryptable
|
161
|
-
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
162
|
-
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
163
|
-
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
164
|
-
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
165
|
-
# REST_AUTH_SITE_KEY to pepper)
|
166
|
-
# config.encryptor = :sha512
|
167
|
-
|
168
|
-
# ==> Configuration for :token_authenticatable
|
169
|
-
# Defines name of the authentication token params key
|
170
|
-
# config.token_authentication_key = :auth_token
|
171
|
-
|
172
|
-
# If true, authentication through token does not store user in session and needs
|
173
|
-
# to be supplied on each request. Useful if you are using the token as API token.
|
174
|
-
# config.stateless_token = false
|
175
|
-
|
176
|
-
# ==> Scopes configuration
|
177
|
-
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
178
|
-
# "users/sessions/new". It's turned off by default because it's slower if you
|
179
|
-
# are using only default views.
|
180
|
-
# config.scoped_views = false
|
181
|
-
|
182
|
-
# Configure the default scope given to Warden. By default it's the first
|
183
|
-
# devise role declared in your routes (usually :user).
|
184
|
-
# config.default_scope = :user
|
185
|
-
|
186
|
-
# Configure sign_out behavior.
|
187
|
-
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
188
|
-
# The default is true, which means any logout action will sign out all active scopes.
|
189
|
-
# config.sign_out_all_scopes = true
|
190
|
-
|
191
|
-
# ==> Navigation configuration
|
192
|
-
# Lists the formats that should be treated as navigational. Formats like
|
193
|
-
# :html, should redirect to the sign in page when the user does not have
|
194
|
-
# access, but formats like :xml or :json, should return 401.
|
195
|
-
#
|
196
|
-
# If you have any extra navigational formats, like :iphone or :mobile, you
|
197
|
-
# should add them to the navigational formats lists.
|
198
|
-
#
|
199
|
-
# The :"*/*" and "*/*" formats below is required to match Internet
|
200
|
-
# Explorer requests.
|
201
|
-
# config.navigational_formats = [:"*/*", "*/*", :html]
|
202
|
-
|
203
|
-
# The default HTTP method used to sign out a resource. Default is :delete.
|
204
|
-
config.sign_out_via = :get
|
205
|
-
|
206
|
-
# ==> OmniAuth
|
207
|
-
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
208
|
-
# up on your models and hooks.
|
209
|
-
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
210
|
-
|
211
|
-
# ==> Warden configuration
|
212
|
-
# If you want to use other strategies, that are not supported by Devise, or
|
213
|
-
# change the failure app, you can configure them inside the config.warden block.
|
214
|
-
#
|
215
|
-
# config.warden do |manager|
|
216
|
-
# manager.intercept_401 = false
|
217
|
-
# manager.default_strategies(:scope => :user).unshift :http_header_authenticatable
|
218
|
-
# end
|
219
|
-
config.warden do |manager|
|
220
|
-
manager.failure_app = RedirectToWebAccessFailure
|
221
|
-
end
|
222
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
class RedirectToWebAccessFailure < Devise::FailureApp
|
16
|
-
def redirect_url
|
17
|
-
Rails.application.config.login_url+ (request.env["ORIGINAL_FULLPATH"].blank? ? '' : request.env["ORIGINAL_FULLPATH"])
|
18
|
-
end
|
19
|
-
|
20
|
-
def respond
|
21
|
-
if http_auth?
|
22
|
-
http_auth
|
23
|
-
else
|
24
|
-
redirect
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Sufia
|
2
|
-
module HttpHeaderAuth
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
## Force the session to be restarted on every request. The ensures that when the REMOTE_USER header is not set, the user will be logged out.
|
7
|
-
prepend_before_filter :clear_session_user
|
8
|
-
before_filter :filter_notify
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.get_vhost_by_host(config)
|
12
|
-
hosts_vhosts_map = config.hosts_vhosts_map
|
13
|
-
hostname = Socket.gethostname
|
14
|
-
vhost = hosts_vhosts_map[hostname] || "https://#{hostname}/"
|
15
|
-
service = URI.parse(vhost).host
|
16
|
-
port = URI.parse(vhost).port
|
17
|
-
service << "-#{port}" unless port == 443
|
18
|
-
return [service, vhost]
|
19
|
-
end
|
20
|
-
def clear_session_user
|
21
|
-
if request.nil?
|
22
|
-
logger.warn "Request is Nil, how weird!!!"
|
23
|
-
return
|
24
|
-
end
|
25
|
-
|
26
|
-
# only logout if the REMOTE_USER is not set in the HTTP headers and a user is set within warden
|
27
|
-
# logout clears the entire session including flash messages
|
28
|
-
request.env['warden'].logout unless user_logged_in?
|
29
|
-
end
|
30
|
-
# Override devise method
|
31
|
-
def user_signed_in?
|
32
|
-
env['warden'] and env['warden'].user and remote_user_set?
|
33
|
-
end
|
34
|
-
|
35
|
-
def remote_user_set?
|
36
|
-
# Unicorn seems to translate REMOTE_USER into HTTP_REMOTE_USER
|
37
|
-
if Rails.env.development?
|
38
|
-
request.env['HTTP_REMOTE_USER'].present?
|
39
|
-
else
|
40
|
-
request.env['REMOTE_USER'].present?
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def filter_notify
|
45
|
-
# remove error inserted since we are not showing a page before going to web access, this error message always shows up a page too late.
|
46
|
-
# for the moment just remove it always. If we show a transition page in the future we may want to display it then.
|
47
|
-
if flash[:alert].present?
|
48
|
-
flash[:alert] = [flash[:alert]].flatten.reject do |item|
|
49
|
-
# first remove the bogus message
|
50
|
-
item == 'You need to sign in or sign up before continuing.'
|
51
|
-
# Also, remove extraneous paperclip errors for weird file types
|
52
|
-
item =~ /is not recognized by the 'identify' command/
|
53
|
-
end
|
54
|
-
# then make the flash nil if that was the only message in the flash
|
55
|
-
flash[:alert] = nil if flash[:alert].blank?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'spec_helper'
|
16
|
-
|
17
|
-
describe 'host_to_vhost' do
|
18
|
-
it "should return the proper vhost on fedora1test" do
|
19
|
-
Socket.stub(:gethostname).and_return('fedora1test')
|
20
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[0].should == 'scholarsphere-integration.dlt.psu.edu-8443'
|
21
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[1].should == 'https://scholarsphere-integration.dlt.psu.edu:8443/'
|
22
|
-
end
|
23
|
-
it "should return the proper vhost on fedora2test" do
|
24
|
-
Socket.stub(:gethostname).and_return('fedora2test')
|
25
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[0].should == 'scholarsphere-test.dlt.psu.edu'
|
26
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[1].should == 'https://scholarsphere-test.dlt.psu.edu/'
|
27
|
-
end
|
28
|
-
it "should return the proper vhost on ss1stage" do
|
29
|
-
Socket.stub(:gethostname).and_return('ss1stage')
|
30
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[0].should == 'scholarsphere-staging.dlt.psu.edu'
|
31
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[1].should == 'https://scholarsphere-staging.dlt.psu.edu/'
|
32
|
-
end
|
33
|
-
it "should return the proper vhost on dev" do
|
34
|
-
Socket.stub(:gethostname).and_return('some1host')
|
35
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[0].should == 'some1host'
|
36
|
-
Sufia::HttpHeaderAuth.get_vhost_by_host(Sufia.config)[1].should == 'https://some1host/'
|
37
|
-
end
|
38
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'spec_helper'
|
16
|
-
|
17
|
-
describe SessionsController do
|
18
|
-
describe "routing" do
|
19
|
-
it "should send /logout to sessions#destroy" do
|
20
|
-
#pending "This is a customization that PSU did in their own routes file, not default devise"
|
21
|
-
{ get: '/logout' }.should route_to( controller: 'sessions', action: 'destroy')
|
22
|
-
@routes.url_helpers.destroy_user_session_path.should == '/logout'
|
23
|
-
end
|
24
|
-
it "should send /login to sessions#new" do
|
25
|
-
#pending "This is a customization that PSU did in their own routes file, not default devise"
|
26
|
-
{ get: '/login' }.should route_to( controller: 'sessions', action: 'new')
|
27
|
-
@routes.url_helpers.new_user_session_path.should == '/login'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
describe "#destroy" do
|
31
|
-
it "should redirect to the central logout page and destroy the cookie" do
|
32
|
-
request.env['COSIGN_SERVICE'] = 'cosign-gamma-ci.dlt.psu.edu'
|
33
|
-
cookies.should_receive(:delete).with('cosign-gamma-ci.dlt.psu.edu')
|
34
|
-
get :destroy
|
35
|
-
response.should redirect_to Sufia::Engine.config.logout_url
|
36
|
-
end
|
37
|
-
end
|
38
|
-
describe "#new" do
|
39
|
-
it "should redirect to the central login page" do
|
40
|
-
get :new
|
41
|
-
response.should redirect_to Sufia::Engine.config.login_url
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|