ucb_rails 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/app/controllers/ucb_rails/admin/force_exception_controller.rb +7 -0
- data/app/mailers/ucb_rails/test_mailer.rb +15 -0
- data/app/models/ucb_rails/configuration/configuration.rb +72 -0
- data/app/models/ucb_rails/configuration/email.rb +73 -0
- data/app/models/ucb_rails/configuration/exception_notification.rb +21 -0
- data/config/routes.rb +1 -0
- data/lib/generators/ucb_rails/templates/README +1 -0
- data/lib/generators/ucb_rails/templates/app/views/layouts/_developer.html.haml +1 -0
- data/lib/generators/ucb_rails/templates/config/config.yml.example +56 -0
- data/lib/generators/ucb_rails/templates/config/initializers/local/ucb_rails.rb +21 -6
- data/lib/ucb_rails.rb +2 -0
- data/lib/ucb_rails/version.rb +1 -1
- metadata +42 -4
@@ -0,0 +1,15 @@
|
|
1
|
+
module UcbRails
|
2
|
+
class TestMailer < ActionMailer::Base
|
3
|
+
layout false
|
4
|
+
|
5
|
+
# Verify email configuration, from irb (e.g.):
|
6
|
+
#
|
7
|
+
# TestMailer.test('email@example.com').deliver
|
8
|
+
def test(email)
|
9
|
+
subject = "#{UcbRails[:email_subject_prefix]} Test Email"
|
10
|
+
|
11
|
+
mail(to: email, subject: subject)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module UcbRails
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
# Manage configuration from file. Per environment or overall.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# # config/config.yml
|
8
|
+
# test:
|
9
|
+
# ldap:
|
10
|
+
# username: test_username
|
11
|
+
# password: test_password
|
12
|
+
#
|
13
|
+
# ldap:
|
14
|
+
# username: top_username
|
15
|
+
# password: top_password
|
16
|
+
#
|
17
|
+
# # in config/initializers/ucb_rails.rb (e.g.)
|
18
|
+
# config = UcbRails::Credentials.new
|
19
|
+
#
|
20
|
+
# # in production -- pulls from top level, since no 'production' key
|
21
|
+
# config.for('ldap') #=> { 'username' => 'top_username', 'password' => 'top_password' }
|
22
|
+
#
|
23
|
+
# # in test -- pulls from 'test' key
|
24
|
+
# config.for('ldap') #=> { 'username' => 'test_username', 'password' => 'test_password' }
|
25
|
+
class Configuration
|
26
|
+
FileNotFound = Class.new(StandardError)
|
27
|
+
KeyNotFound = Class.new(StandardError)
|
28
|
+
|
29
|
+
attr_accessor :config_filename, :config_yaml
|
30
|
+
|
31
|
+
def initialize(filename=Rails.root.join('config/config.yml'))
|
32
|
+
self.config_filename = filename.to_s
|
33
|
+
load_file
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return configuration value for _key_.
|
37
|
+
# @param key [String]
|
38
|
+
def for(key)
|
39
|
+
from_environment(key) || from_top_level(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return configuration value for _key_.
|
43
|
+
# @raise [UcbRails::Configuration::KeyNotFound] if _key_ not in configuration file.
|
44
|
+
def for!(key)
|
45
|
+
self.for(key) or raise(KeyNotFound, key.inspect)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def from_environment(key)
|
51
|
+
environmet_value && environmet_value[key]
|
52
|
+
end
|
53
|
+
|
54
|
+
def from_top_level(key)
|
55
|
+
config_yaml[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
def environmet_value
|
59
|
+
config_yaml[RailsEnvironment.rails_env]
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_file
|
63
|
+
if File.exists?(config_filename)
|
64
|
+
self.config_yaml = YAML.load_file(config_filename)
|
65
|
+
else
|
66
|
+
raise(FileNotFound, config_filename)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module UcbRails
|
2
|
+
module Configuration
|
3
|
+
class Email
|
4
|
+
ArgumentError = Class.new(StandardError)
|
5
|
+
|
6
|
+
attr_accessor :hash
|
7
|
+
|
8
|
+
def self.configure(config)
|
9
|
+
new(config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(configuration_hash)
|
13
|
+
return if configuration_hash.nil?
|
14
|
+
raise(ArgumentError, "expected a Hash, got: #{configuration_hash.inspect}") unless configuration_hash.is_a?(Hash)
|
15
|
+
|
16
|
+
self.hash = configuration_hash
|
17
|
+
process_configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process_configuration
|
23
|
+
process_default
|
24
|
+
process_delivery_method
|
25
|
+
process_default_url_options
|
26
|
+
process_raise_delivery_errors
|
27
|
+
process_sendmail_settings
|
28
|
+
process_smtp_settings
|
29
|
+
process_subject_prefix
|
30
|
+
end
|
31
|
+
|
32
|
+
# This merges values with existing values
|
33
|
+
def process_default
|
34
|
+
if hash.has_key?('default')
|
35
|
+
ActionMailer::Base.default hash['default']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def process_delivery_method
|
40
|
+
ActionMailer::Base.delivery_method = hash.fetch('delivery_method', :smtp).to_sym
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_default_url_options
|
44
|
+
if hash.has_key?('default_url_options')
|
45
|
+
ActionMailer::Base.default_url_options = hash.fetch('default_url_options')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def process_raise_delivery_errors
|
50
|
+
ActionMailer::Base.raise_delivery_errors = hash.fetch('raise_delivery_errors', true)
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_sendmail_settings
|
54
|
+
if hash.has_key?('sendmail_settings')
|
55
|
+
ActionMailer::Base.sendmail_settings = hash.fetch('sendmail_settings').symbolize_keys
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_smtp_settings
|
60
|
+
if hash.has_key?('smtp_settings')
|
61
|
+
ActionMailer::Base.smtp_settings = hash.fetch('smtp_settings').symbolize_keys
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_subject_prefix
|
66
|
+
prefix = hash.fetch('subject_prefix', '')
|
67
|
+
prefix = prefix.gsub("{env}", RailsEnvironment.short)
|
68
|
+
UcbRails.config.email_subject_prefix = prefix
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module UcbRails
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
class ExceptionNotification
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def configure(config)
|
9
|
+
return if config.blank?
|
10
|
+
|
11
|
+
config = config.symbolize_keys
|
12
|
+
config[:email].symbolize_keys!
|
13
|
+
config[:email][:email_prefix] = config[:email][:email_prefix].gsub("{env}", RailsEnvironment.short)
|
14
|
+
|
15
|
+
Rails.application.config.middleware.use ::ExceptionNotification::Rack, config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# You can have configuration per-environment by nesting under the
|
2
|
+
# environment key, or have a top level.
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
# ldap:
|
7
|
+
# username: <username>
|
8
|
+
# password: <password>
|
9
|
+
|
10
|
+
development:
|
11
|
+
|
12
|
+
# email:
|
13
|
+
# default:
|
14
|
+
# from: user@gmail.com
|
15
|
+
# default_url_options:
|
16
|
+
# host: example.com
|
17
|
+
# delivery_method: :smtp
|
18
|
+
# # delivery_method: :sendmail
|
19
|
+
# # delivery_method: :test
|
20
|
+
# # delivery_method: :file
|
21
|
+
# raise_delivery_errors: true
|
22
|
+
# # send_mail_settings:
|
23
|
+
# # location: "/usr/sbin/sendmail"
|
24
|
+
# # arguments: "-i -t"
|
25
|
+
# smtp_settings:
|
26
|
+
# address: smtp.gmail.com
|
27
|
+
# port: 587
|
28
|
+
# domain: gmail.com
|
29
|
+
# user_name: <username>
|
30
|
+
# password: <password>
|
31
|
+
# authentication: plain
|
32
|
+
# enable_starttls_auto: true
|
33
|
+
# subject_prefix: '[My App {env}] '
|
34
|
+
|
35
|
+
# exception_notification:
|
36
|
+
# email:
|
37
|
+
# email_prefix: '[My App - Error {env}] '
|
38
|
+
# sender_address: user@example.com
|
39
|
+
# exception_recipients:
|
40
|
+
# - user1@example.com
|
41
|
+
# - user2@example.com
|
42
|
+
|
43
|
+
# ldap:
|
44
|
+
# username: <username>
|
45
|
+
# password: <password>
|
46
|
+
|
47
|
+
test:
|
48
|
+
email:
|
49
|
+
default:
|
50
|
+
from: test-user@examle.com
|
51
|
+
default_url_options:
|
52
|
+
host: example.com
|
53
|
+
delivery_method: :test
|
54
|
+
raise_delivery_errors: true
|
55
|
+
subject_prefix: '[My App {env}] '
|
56
|
+
|
@@ -1,18 +1,33 @@
|
|
1
1
|
############################################################
|
2
|
-
# Load
|
2
|
+
# Load configuration from config/config.yml
|
3
3
|
############################################################
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
config = UcbRails::Configuration::Configuration.new
|
6
|
+
|
7
|
+
############################################################
|
8
|
+
# ActionMailer
|
9
|
+
############################################################
|
10
|
+
|
11
|
+
UcbRails::Configuration::Email.configure(config.for('email'))
|
12
|
+
|
13
|
+
############################################################
|
14
|
+
# Exception Notification
|
15
|
+
############################################################
|
16
|
+
|
17
|
+
UcbRails::Configuration::ExceptionNotification.configure(config.for('exception_notification'))
|
7
18
|
|
8
19
|
############################################################
|
9
20
|
# UCB::LDAP
|
10
21
|
############################################################
|
11
22
|
|
12
23
|
UCB::LDAP.host = 'nds.berkeley.edu'
|
13
|
-
ldap_credentials =
|
14
|
-
|
15
|
-
|
24
|
+
if ldap_credentials = config.for('ldap')
|
25
|
+
puts "[UcbRails] Using ldap credentials from #{config.config_filename}"
|
26
|
+
UCB::LDAP.authenticate(ldap_credentials['username'], ldap_credentials['password'])
|
27
|
+
else
|
28
|
+
puts "[UcbRails] No ldap credentials found. Using anonymous bind."
|
29
|
+
end
|
30
|
+
|
16
31
|
############################################################
|
17
32
|
# OmniAuth
|
18
33
|
############################################################
|
data/lib/ucb_rails.rb
CHANGED
data/lib/ucb_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucb_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.0.0.pre1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: exception_notification
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.0.0.rc1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 4.0.0.rc1
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: omniauth
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,6 +219,22 @@ dependencies:
|
|
203
219
|
- - ! '>='
|
204
220
|
- !ruby/object:Gem::Version
|
205
221
|
version: '0'
|
222
|
+
- !ruby/object:Gem::Dependency
|
223
|
+
name: bootstrap-datepicker-rails
|
224
|
+
requirement: !ruby/object:Gem::Requirement
|
225
|
+
none: false
|
226
|
+
requirements:
|
227
|
+
- - ! '>='
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ! '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
206
238
|
- !ruby/object:Gem::Dependency
|
207
239
|
name: rails_environment
|
208
240
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,7 +242,7 @@ dependencies:
|
|
210
242
|
requirements:
|
211
243
|
- - ~>
|
212
244
|
- !ruby/object:Gem::Version
|
213
|
-
version: 0.0.
|
245
|
+
version: 0.0.3
|
214
246
|
type: :runtime
|
215
247
|
prerelease: false
|
216
248
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -218,7 +250,7 @@ dependencies:
|
|
218
250
|
requirements:
|
219
251
|
- - ~>
|
220
252
|
- !ruby/object:Gem::Version
|
221
|
-
version: 0.0.
|
253
|
+
version: 0.0.3
|
222
254
|
- !ruby/object:Gem::Dependency
|
223
255
|
name: bootstrap-view-helpers
|
224
256
|
requirement: !ruby/object:Gem::Requirement
|
@@ -531,6 +563,7 @@ extensions: []
|
|
531
563
|
extra_rdoc_files: []
|
532
564
|
files:
|
533
565
|
- app/controllers/ucb_rails/admin/base_controller.rb
|
566
|
+
- app/controllers/ucb_rails/admin/force_exception_controller.rb
|
534
567
|
- app/controllers/ucb_rails/admin/users_controller.rb
|
535
568
|
- app/controllers/ucb_rails/bootstrap_controller.rb
|
536
569
|
- app/controllers/ucb_rails/controller_methods.rb
|
@@ -547,6 +580,10 @@ files:
|
|
547
580
|
- app/helpers/ucb_rails/renderer/base.rb
|
548
581
|
- app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
|
549
582
|
- app/helpers/ucb_rails/renderer/lps_typeahead_search_field.rb
|
583
|
+
- app/mailers/ucb_rails/test_mailer.rb
|
584
|
+
- app/models/ucb_rails/configuration/configuration.rb
|
585
|
+
- app/models/ucb_rails/configuration/email.rb
|
586
|
+
- app/models/ucb_rails/configuration/exception_notification.rb
|
550
587
|
- app/models/ucb_rails/ldap_person/entry.rb
|
551
588
|
- app/models/ucb_rails/ldap_person/finder.rb
|
552
589
|
- app/models/ucb_rails/ldap_person/test_finder.rb
|
@@ -584,6 +621,7 @@ files:
|
|
584
621
|
- lib/generators/ucb_rails/templates/app/views/layouts/_footer.html.haml
|
585
622
|
- lib/generators/ucb_rails/templates/app/views/layouts/_navigation.html.haml
|
586
623
|
- lib/generators/ucb_rails/templates/app/views/layouts/application.html.haml
|
624
|
+
- lib/generators/ucb_rails/templates/config/config.yml.example
|
587
625
|
- lib/generators/ucb_rails/templates/config/initializers/local/active_record/dom_and_haml.rb
|
588
626
|
- lib/generators/ucb_rails/templates/config/initializers/local/haml_buffer.rb
|
589
627
|
- lib/generators/ucb_rails/templates/config/initializers/local/simple_form.rb
|