ditty 0.7.1 → 0.10.1
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.
- checksums.yaml +4 -4
- data/.env.test +2 -0
- data/.gitignore +3 -0
- data/.pryrc +2 -0
- data/.rubocop.yml +24 -8
- data/.travis.yml +4 -8
- data/CNAME +1 -0
- data/Dockerfile +18 -0
- data/Gemfile.ci +0 -15
- data/Rakefile +5 -4
- data/Readme.md +24 -2
- data/_config.yml +1 -0
- data/config.ru +4 -4
- data/ditty.gemspec +31 -20
- data/docs/CNAME +1 -0
- data/docs/_config.yml +1 -0
- data/docs/index.md +34 -0
- data/exe/ditty +2 -0
- data/lib/ditty.rb +30 -4
- data/lib/ditty/cli.rb +38 -5
- data/lib/ditty/components/ditty.rb +82 -0
- data/lib/ditty/controllers/application_controller.rb +267 -0
- data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +5 -7
- data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +56 -32
- data/lib/ditty/controllers/{component.rb → component_controller.rb} +35 -24
- data/lib/ditty/controllers/{main.rb → main_controller.rb} +7 -7
- data/lib/ditty/controllers/roles_controller.rb +23 -0
- data/lib/ditty/controllers/user_login_traits_controller.rb +46 -0
- data/lib/ditty/controllers/{users.rb → users_controller.rb} +17 -20
- data/lib/ditty/db.rb +9 -5
- data/lib/ditty/emails/base.rb +48 -34
- data/lib/ditty/generators/crud_generator.rb +114 -0
- data/lib/ditty/generators/migration_generator.rb +26 -0
- data/lib/ditty/generators/project_generator.rb +52 -0
- data/lib/ditty/helpers/authentication.rb +6 -5
- data/lib/ditty/helpers/component.rb +11 -2
- data/lib/ditty/helpers/pundit.rb +24 -8
- data/lib/ditty/helpers/response.rb +38 -15
- data/lib/ditty/helpers/views.rb +48 -6
- data/lib/ditty/listener.rb +44 -14
- data/lib/ditty/memcached.rb +8 -0
- data/lib/ditty/middleware/accept_extension.rb +4 -2
- data/lib/ditty/middleware/error_catchall.rb +4 -2
- data/lib/ditty/models/audit_log.rb +1 -0
- data/lib/ditty/models/base.rb +13 -0
- data/lib/ditty/models/identity.rb +10 -7
- data/lib/ditty/models/role.rb +2 -0
- data/lib/ditty/models/user.rb +40 -3
- data/lib/ditty/models/user_login_trait.rb +17 -0
- data/lib/ditty/policies/audit_log_policy.rb +6 -6
- data/lib/ditty/policies/role_policy.rb +3 -3
- data/lib/ditty/policies/user_login_trait_policy.rb +45 -0
- data/lib/ditty/policies/user_policy.rb +3 -3
- data/lib/ditty/rubocop.rb +3 -0
- data/lib/ditty/seed.rb +2 -0
- data/lib/ditty/services/authentication.rb +31 -15
- data/lib/ditty/services/email.rb +22 -12
- data/lib/ditty/services/logger.rb +30 -13
- data/lib/ditty/services/pagination_wrapper.rb +9 -5
- data/lib/ditty/services/settings.rb +19 -7
- data/lib/ditty/tasks/ditty.rake +127 -0
- data/lib/ditty/tasks/omniauth-ldap.rake +43 -0
- data/lib/ditty/templates/.gitignore +5 -0
- data/lib/ditty/templates/.rspec +2 -0
- data/lib/ditty/templates/.rubocop.yml +7 -0
- data/lib/ditty/templates/Rakefile +12 -0
- data/lib/ditty/templates/application.rb +12 -0
- data/lib/ditty/templates/config.ru +37 -0
- data/lib/ditty/templates/controller.rb.erb +64 -0
- data/lib/ditty/templates/env.example +4 -0
- data/lib/ditty/templates/lib/project.rb.erb +5 -0
- data/lib/ditty/templates/migration.rb.erb +7 -0
- data/lib/ditty/templates/model.rb.erb +26 -0
- data/lib/ditty/templates/pids/.empty_directory +0 -0
- data/lib/ditty/templates/policy.rb.erb +48 -0
- data/{public → lib/ditty/templates/public}/browserconfig.xml +0 -0
- data/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
- data/lib/ditty/templates/public/css/styles.css +13 -0
- data/lib/ditty/templates/public/favicon.ico +0 -0
- data/{public → lib/ditty/templates/public}/images/apple-icon.png +0 -0
- data/{public → lib/ditty/templates/public}/images/favicon-16x16.png +0 -0
- data/{public → lib/ditty/templates/public}/images/favicon-32x32.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-1x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-2x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-4x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/mstile-150x150.png +0 -0
- data/{public → lib/ditty/templates/public}/images/safari-pinned-tab.svg +0 -0
- data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
- data/lib/ditty/templates/public/js/scripts.js +1 -0
- data/{public/manifest.json → lib/ditty/templates/public/manifest.json.erb} +2 -2
- data/lib/ditty/templates/settings.yml.erb +19 -0
- data/lib/ditty/templates/sidekiq.rb +18 -0
- data/lib/ditty/templates/sidekiq.yml +9 -0
- data/lib/ditty/templates/spec_helper.rb +43 -0
- data/lib/ditty/templates/type.rb.erb +21 -0
- data/lib/ditty/templates/views/display.haml.tt +20 -0
- data/lib/ditty/templates/views/edit.haml.tt +10 -0
- data/lib/ditty/templates/views/form.haml.tt +11 -0
- data/lib/ditty/templates/views/index.haml.tt +29 -0
- data/lib/ditty/templates/views/new.haml.tt +10 -0
- data/lib/ditty/version.rb +1 -1
- data/lib/rubocop/cop/ditty/call_services_directly.rb +42 -0
- data/migrate/20181209_add_user_login_traits.rb +16 -0
- data/migrate/20181209_extend_audit_log.rb +12 -0
- data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
- data/spec/ditty/api_spec.rb +51 -0
- data/spec/ditty/controllers/roles_spec.rb +67 -0
- data/spec/ditty/controllers/user_login_traits_spec.rb +72 -0
- data/spec/ditty/controllers/users_spec.rb +72 -0
- data/spec/ditty/emails/base_spec.rb +76 -0
- data/spec/ditty/emails/forgot_password_spec.rb +20 -0
- data/spec/ditty/helpers/component_spec.rb +85 -0
- data/spec/ditty/models/user_spec.rb +36 -0
- data/spec/ditty/services/email_spec.rb +36 -0
- data/spec/ditty/services/logger_spec.rb +68 -0
- data/spec/ditty/services/settings_spec.rb +63 -0
- data/spec/ditty_spec.rb +9 -0
- data/spec/factories.rb +46 -0
- data/spec/fixtures/logger.yml +17 -0
- data/spec/fixtures/section.yml +3 -0
- data/spec/fixtures/settings.yml +8 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/api_shared_examples.rb +250 -0
- data/spec/support/crud_shared_examples.rb +145 -0
- data/views/403.haml +2 -0
- data/views/404.haml +2 -4
- data/views/500.haml +11 -0
- data/views/audit_logs/index.haml +32 -28
- data/views/auth/forgot_password.haml +32 -16
- data/views/auth/identity.haml +14 -13
- data/views/auth/ldap.haml +17 -0
- data/views/auth/login.haml +23 -17
- data/views/auth/register.haml +20 -18
- data/views/auth/register_identity.haml +27 -12
- data/views/auth/reset_password.haml +36 -19
- data/views/blank.haml +43 -0
- data/views/emails/forgot_password.haml +1 -1
- data/views/emails/layouts/action.haml +10 -6
- data/views/emails/layouts/alert.haml +2 -1
- data/views/emails/layouts/billing.haml +2 -1
- data/views/embedded.haml +17 -11
- data/views/error.haml +8 -3
- data/views/index.haml +1 -1
- data/views/layout.haml +45 -30
- data/views/partials/actions.haml +15 -14
- data/views/partials/content_tag.haml +0 -0
- data/views/partials/delete_form.haml +1 -1
- data/views/partials/filter_control.haml +2 -2
- data/views/partials/footer.haml +13 -5
- data/views/partials/form_control.haml +30 -19
- data/views/partials/form_tag.haml +1 -1
- data/views/partials/navitems.haml +42 -0
- data/views/partials/notifications.haml +12 -8
- data/views/partials/pager.haml +44 -25
- data/views/partials/search.haml +15 -11
- data/views/partials/sidebar.haml +15 -37
- data/views/partials/sort_ui.haml +2 -0
- data/views/partials/timespan_selector.haml +64 -0
- data/views/partials/topbar.haml +53 -0
- data/views/partials/user_associations.haml +32 -0
- data/views/quick_start.haml +23 -0
- data/views/roles/display.haml +27 -6
- data/views/roles/edit.haml +3 -3
- data/views/roles/form.haml +1 -0
- data/views/roles/index.haml +23 -14
- data/views/roles/new.haml +2 -2
- data/views/user_login_traits/display.haml +32 -0
- data/views/user_login_traits/edit.haml +10 -0
- data/views/user_login_traits/form.haml +5 -0
- data/views/user_login_traits/index.haml +28 -0
- data/views/user_login_traits/new.haml +10 -0
- data/views/users/display.haml +15 -16
- data/views/users/edit.haml +3 -3
- data/views/users/form.haml +0 -0
- data/views/users/index.haml +31 -24
- data/views/users/login_traits.haml +25 -0
- data/views/users/new.haml +2 -2
- data/views/users/profile.haml +17 -15
- data/views/users/user.haml +1 -1
- metadata +314 -76
- data/lib/ditty/components/app.rb +0 -77
- data/lib/ditty/controllers/application.rb +0 -175
- data/lib/ditty/controllers/roles.rb +0 -16
- data/lib/ditty/rake_tasks.rb +0 -102
- data/views/partials/navbar.haml +0 -23
data/lib/ditty/services/email.rb
CHANGED
|
@@ -11,6 +11,8 @@ module Ditty
|
|
|
11
11
|
class << self
|
|
12
12
|
include ActiveSupport::Inflector
|
|
13
13
|
|
|
14
|
+
attr_writer :config
|
|
15
|
+
|
|
14
16
|
def config!
|
|
15
17
|
cfg = config
|
|
16
18
|
Mail.defaults do
|
|
@@ -18,27 +20,35 @@ module Ditty
|
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
def
|
|
23
|
+
def generate(email, to = nil, options = {})
|
|
22
24
|
config!
|
|
23
25
|
options[:to] ||= to unless to.nil?
|
|
26
|
+
options[:from] ||= config[:from] unless config[:from].nil?
|
|
24
27
|
email = from_symbol(email, options) if email.is_a? Symbol
|
|
25
|
-
email
|
|
28
|
+
email
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def deliver(email, to = nil, options = {})
|
|
32
|
+
generate(email, to, options).deliver!
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
private
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
def config
|
|
38
|
+
@config ||= default.merge ::Ditty::Services::Settings.values(:email) || {}
|
|
39
|
+
end
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
def default
|
|
42
|
+
{
|
|
43
|
+
delivery_method: :logger,
|
|
44
|
+
logger: ::Ditty::Services::Logger
|
|
45
|
+
}
|
|
46
|
+
end
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
def from_symbol(email, options)
|
|
49
|
+
require "ditty/emails/#{email}"
|
|
50
|
+
constantize("Ditty::Emails::#{classify(email)}").new(options)
|
|
51
|
+
end
|
|
42
52
|
end
|
|
43
53
|
end
|
|
44
54
|
end
|
|
@@ -20,6 +20,7 @@ module Ditty
|
|
|
20
20
|
def initialize
|
|
21
21
|
@loggers = []
|
|
22
22
|
return if config[:loggers].blank?
|
|
23
|
+
|
|
23
24
|
config[:loggers].each do |values|
|
|
24
25
|
klass = values[:class].constantize
|
|
25
26
|
opts = tr(values[:options]) || nil
|
|
@@ -29,30 +30,46 @@ module Ditty
|
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
|
|
33
|
+
# TODO: REfac this so that you can log something like ES to a separate logger
|
|
34
|
+
|
|
32
35
|
def method_missing(method, *args, &block)
|
|
33
36
|
loggers.each { |logger| logger.send(method, *args, &block) }
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
def respond_to_missing?(method, _include_private = false)
|
|
37
|
-
loggers.any? { |logger| logger.respond_to?(method) }
|
|
40
|
+
return true if loggers.any? { |logger| logger.respond_to?(method) }
|
|
41
|
+
|
|
42
|
+
super
|
|
38
43
|
end
|
|
39
44
|
|
|
40
45
|
private
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
def config
|
|
48
|
+
default.merge ::Ditty::Services::Settings.values(:logger) || {}
|
|
49
|
+
end
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
def tr(val)
|
|
52
|
+
{
|
|
53
|
+
'$stdout' => $stdout,
|
|
54
|
+
'$stderr' => $stderr
|
|
55
|
+
}[val] || val
|
|
56
|
+
end
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
def default
|
|
59
|
+
{ loggers: [{ name: 'default', class: 'Logger' }] }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class << self
|
|
63
|
+
def method_missing(method, *args, &block)
|
|
64
|
+
instance.send(method, *args, &block)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def respond_to_missing?(method, _include_private)
|
|
68
|
+
return true if instance.respond_to?(method)
|
|
69
|
+
|
|
70
|
+
super
|
|
71
|
+
end
|
|
72
|
+
end
|
|
56
73
|
end
|
|
57
74
|
end
|
|
58
75
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Ditty
|
|
2
4
|
module Services
|
|
3
5
|
class PaginationWrapper
|
|
@@ -8,18 +10,18 @@ module Ditty
|
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def last_page?
|
|
11
|
-
if list.respond_to? :
|
|
13
|
+
if list.respond_to? :last_page?
|
|
12
14
|
list.last_page?
|
|
13
15
|
else
|
|
14
|
-
list.
|
|
16
|
+
list.next_page.nil?
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def first_page?
|
|
19
|
-
if list.respond_to? :
|
|
21
|
+
if list.respond_to? :first_page?
|
|
20
22
|
list.first_page?
|
|
21
23
|
else
|
|
22
|
-
list.
|
|
24
|
+
list.previous_page.nil?
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
|
|
@@ -62,7 +64,9 @@ module Ditty
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def respond_to_missing?(method, _include_private = false)
|
|
65
|
-
list.respond_to?
|
|
67
|
+
return true if list.respond_to?(method)
|
|
68
|
+
|
|
69
|
+
super
|
|
66
70
|
end
|
|
67
71
|
|
|
68
72
|
def current_page_record_range
|
|
@@ -16,22 +16,30 @@ module Ditty
|
|
|
16
16
|
# in separate files will be used in preference of those in the `settings.yml`
|
|
17
17
|
# file.
|
|
18
18
|
module Settings
|
|
19
|
-
CONFIG_FOLDER = './config'
|
|
20
|
-
CONFIG_FILE = "#{CONFIG_FOLDER}/settings.yml"
|
|
19
|
+
CONFIG_FOLDER = './config'
|
|
20
|
+
CONFIG_FILE = "#{CONFIG_FOLDER}/settings.yml"
|
|
21
21
|
|
|
22
22
|
class << self
|
|
23
23
|
def [](key)
|
|
24
|
-
|
|
24
|
+
keys = key.to_s.split('.').map(&:to_sym)
|
|
25
|
+
from = values
|
|
26
|
+
if keys.count > 1 && scope?(keys.first)
|
|
27
|
+
from = values(keys.first)
|
|
28
|
+
keys = keys[1..]
|
|
29
|
+
key = keys.join('.')
|
|
30
|
+
end
|
|
31
|
+
key = key.to_sym if key.respond_to?(:to_sym)
|
|
32
|
+
from[key] || from.dig(*keys)
|
|
25
33
|
end
|
|
26
34
|
|
|
27
35
|
def values(scope = :settings)
|
|
28
36
|
@values ||= begin
|
|
29
37
|
v = Hash.new do |h, k|
|
|
30
38
|
h[k] = if File.file?("#{CONFIG_FOLDER}/#{k}.yml")
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
read("#{CONFIG_FOLDER}/#{k}.yml")
|
|
40
|
+
elsif k != :settings && h[:settings].key?(k)
|
|
41
|
+
h[:settings][k]
|
|
42
|
+
end
|
|
35
43
|
h[k]
|
|
36
44
|
end
|
|
37
45
|
v[:settings] = File.file?(CONFIG_FILE) ? read(CONFIG_FILE) : {}
|
|
@@ -40,6 +48,10 @@ module Ditty
|
|
|
40
48
|
@values[scope]
|
|
41
49
|
end
|
|
42
50
|
|
|
51
|
+
def scope?(name)
|
|
52
|
+
@values.key?(name.to_sym) || File.file?("#{CONFIG_FOLDER}/#{name}.yml")
|
|
53
|
+
end
|
|
54
|
+
|
|
43
55
|
attr_writer :values
|
|
44
56
|
|
|
45
57
|
def read(filename)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :ditty do
|
|
4
|
+
desc 'Run the ditty console'
|
|
5
|
+
task :console do
|
|
6
|
+
require 'irb'
|
|
7
|
+
ARGV.clear
|
|
8
|
+
IRB.start
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc 'Prepare Ditty'
|
|
12
|
+
task prep: ['generate_tokens', 'prep:folders', 'prep:public', 'prep:migrations']
|
|
13
|
+
|
|
14
|
+
desc 'Generate the needed tokens'
|
|
15
|
+
task :generate_tokens do
|
|
16
|
+
puts 'Generating the Ditty tokens'
|
|
17
|
+
require 'securerandom'
|
|
18
|
+
File.write('.session_secret', SecureRandom.random_bytes(40)) unless File.file?('.session_secret')
|
|
19
|
+
File.write('.token_secret', SecureRandom.random_bytes(40)) unless File.file?('.token_secret')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc 'Seed the Ditty database'
|
|
23
|
+
task :seed do
|
|
24
|
+
puts 'Seeding the Ditty database'
|
|
25
|
+
require 'ditty/seed'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc 'Dump the Ditty DB Schema'
|
|
29
|
+
task :dump_schema do
|
|
30
|
+
Ditty::Components.components.each do |_name, comp|
|
|
31
|
+
comp.load if comp.respond_to?(:load)
|
|
32
|
+
end.compact
|
|
33
|
+
DB.dump_schema_cache('./config/schema.dump')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
namespace :prep do
|
|
37
|
+
desc 'Check that the required Ditty folders are present'
|
|
38
|
+
task :folders do
|
|
39
|
+
puts 'Prepare the Ditty folders'
|
|
40
|
+
Dir.mkdir 'pids' unless File.exist?('pids')
|
|
41
|
+
Dir.mkdir 'logs' unless File.exist?('logs')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc 'Check that the public folder is present and populated'
|
|
45
|
+
task :public do
|
|
46
|
+
puts 'Preparing the Ditty public folder'
|
|
47
|
+
Dir.mkdir 'public' unless File.exist?('public')
|
|
48
|
+
::Ditty::Components.public_folder.each do |path|
|
|
49
|
+
puts "Checking #{path}"
|
|
50
|
+
path = "#{path}/."
|
|
51
|
+
FileUtils.cp_r path, 'public' unless File.expand_path(path).eql? File.expand_path('public')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
desc 'Check that the migrations folder is present and populated'
|
|
56
|
+
task :migrations do
|
|
57
|
+
puts 'Preparing the Ditty migrations folder'
|
|
58
|
+
Dir.mkdir 'migrations' unless File.exist?('migrations')
|
|
59
|
+
::Ditty::Components.migrations.each do |path|
|
|
60
|
+
path = "#{path}/."
|
|
61
|
+
FileUtils.cp_r path, 'migrations' unless File.expand_path(path).eql? File.expand_path('migrations')
|
|
62
|
+
end
|
|
63
|
+
puts 'Migrations added:'
|
|
64
|
+
Dir.foreach('migrations').sort.each { |x| puts x if File.file?("migrations/#{x}") && x[-3..] == '.rb' }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc 'Migrate Ditty database to latest version'
|
|
69
|
+
task migrate: ['prep:migrations'] do
|
|
70
|
+
puts 'Running the Ditty migrations'
|
|
71
|
+
Rake::Task['ditty:migrate:up'].invoke
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
namespace :migrate do
|
|
75
|
+
require 'logger'
|
|
76
|
+
|
|
77
|
+
folder = 'migrations'
|
|
78
|
+
|
|
79
|
+
desc 'Check if the migration is current'
|
|
80
|
+
task :check do
|
|
81
|
+
::DB.loggers << Logger.new($stdout) if ::DB.loggers.count.zero?
|
|
82
|
+
puts '** [ditty] Running Ditty Sequel Migrations check'
|
|
83
|
+
::Sequel.extension :migration
|
|
84
|
+
begin
|
|
85
|
+
::Sequel::Migrator.check_current(::DB, folder)
|
|
86
|
+
puts '** [ditty] Sequel Migrations up to date'
|
|
87
|
+
rescue Sequel::Migrator::Error => _e
|
|
88
|
+
raise 'Sequel Migrations NOT up to date'
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc 'Migrate Ditty database to the specified version'
|
|
93
|
+
task :run, [:version] do |_t, args|
|
|
94
|
+
::DB.loggers << Logger.new($stdout) if ::DB.loggers.count.zero?
|
|
95
|
+
raise 'No version specified' unless args[:version]
|
|
96
|
+
|
|
97
|
+
puts "** [ditty] Running Ditty Migrations to #{args[:version]}"
|
|
98
|
+
::Sequel.extension :migration
|
|
99
|
+
::Sequel::Migrator.run(::DB, folder, target: args[:version].to_i)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
desc 'Migrate Ditty database to latest version'
|
|
103
|
+
task :up do
|
|
104
|
+
::DB.loggers << Logger.new($stdout) if ::DB.loggers.count.zero?
|
|
105
|
+
puts '** [ditty] Running Ditty Migrations up'
|
|
106
|
+
::Sequel.extension :migration
|
|
107
|
+
::Sequel::Migrator.apply(::DB, folder)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
desc 'Remove the whole Ditty database. You WILL lose data'
|
|
111
|
+
task :down do
|
|
112
|
+
::DB.loggers << Logger.new($stdout) if ::DB.loggers.count.zero?
|
|
113
|
+
puts '** [ditty] Running Ditty Migrations down'
|
|
114
|
+
::Sequel.extension :migration
|
|
115
|
+
::Sequel::Migrator.apply(::DB, folder, 0)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
desc 'Reset the Ditty database. You WILL lose data'
|
|
119
|
+
task :bounce do
|
|
120
|
+
::DB.loggers << Logger.new($stdout) if ::DB.loggers.count.zero?
|
|
121
|
+
puts '** [ditty] Running Ditty Migrations bounce'
|
|
122
|
+
::Sequel.extension :migration
|
|
123
|
+
::Sequel::Migrator.apply(::DB, folder, 0)
|
|
124
|
+
::Sequel::Migrator.apply(::DB, folder)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :ditty do
|
|
4
|
+
namespace :ldap do
|
|
5
|
+
desc 'Check the LDAP settings'
|
|
6
|
+
task :check do
|
|
7
|
+
settings = ::Ditty::Services::Settings[:authentication][:ldap][:arguments].first
|
|
8
|
+
ldap = Net::LDAP.new host: settings[:host], port: settings[:port]
|
|
9
|
+
ldap.authenticate settings[:bind_dn], settings[:password] if settings[:bind_dn]
|
|
10
|
+
raise 'Could not bind to LDAP server' unless ldap.bind
|
|
11
|
+
|
|
12
|
+
puts 'LDAP Binding Successful'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Add the AD / LDAP Groups to Ditty as Roles'
|
|
16
|
+
task :populate_groups, [:filter] do |_task, args|
|
|
17
|
+
puts 'Adding AD / LDAP Groups to Ditty as Roles'
|
|
18
|
+
require 'ditty/services/settings'
|
|
19
|
+
require 'ditty/models/role'
|
|
20
|
+
|
|
21
|
+
settings = ::Ditty::Services::Settings[:authentication][:ldap][:arguments].first
|
|
22
|
+
ldap = Net::LDAP.new host: settings[:host], port: settings[:port]
|
|
23
|
+
ldap.authenticate settings[:bind_dn], settings[:password] if settings[:bind_dn]
|
|
24
|
+
if ldap.bind
|
|
25
|
+
group_filter = Net::LDAP::Filter.construct(settings[:group_filter]) unless settings[:group_filter].blank?
|
|
26
|
+
group_filter ||= Net::LDAP::Filter.eq('ObjectClass', 'Group')
|
|
27
|
+
if args[:filter]
|
|
28
|
+
search_filter = Net::LDAP::Filter.eq(*args[:filter].split(':', 2))
|
|
29
|
+
filter = Net::LDAP::Filter.join(group_filter, search_filter)
|
|
30
|
+
else
|
|
31
|
+
filter = group_filter
|
|
32
|
+
end
|
|
33
|
+
ldap.search(base: settings[:base], filter: filter).each do |group|
|
|
34
|
+
Ditty::Role.find_or_create(name: group.name) do |role|
|
|
35
|
+
puts "Adding #{role.name}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
puts 'Could not connect to LDAP Server'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
libdir = File.expand_path("#{File.dirname(__FILE__)}/lib")
|
|
4
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
5
|
+
|
|
6
|
+
require 'ditty/components/ditty'
|
|
7
|
+
Ditty.component :ditty
|
|
8
|
+
|
|
9
|
+
# Enable DB Caching
|
|
10
|
+
require 'ditty/memcached' if ENV['MEMCACHED_URL']
|
|
11
|
+
|
|
12
|
+
# Load more components here
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'dotenv/load'
|
|
4
|
+
|
|
5
|
+
# Last Gasp Effort to catch the error
|
|
6
|
+
require 'ditty/middleware/error_catchall'
|
|
7
|
+
use ::Ditty::Middleware::ErrorCatchall if ENV['APP_ENV'] == 'production'
|
|
8
|
+
|
|
9
|
+
require 'rack/static'
|
|
10
|
+
use Rack::Static, urls: ['/favicon.ico', '/js/', '/images/', '/css/'], root: 'public'
|
|
11
|
+
|
|
12
|
+
# Session
|
|
13
|
+
use Rack::Session::Cookie,
|
|
14
|
+
key: '_Ditty_session',
|
|
15
|
+
path: '/',
|
|
16
|
+
# :secure=>!TEST_MODE, # Uncomment if only allowing https:// access
|
|
17
|
+
secret: File.read('.session_secret')
|
|
18
|
+
|
|
19
|
+
require './application'
|
|
20
|
+
require 'ditty/services/authentication'
|
|
21
|
+
use OmniAuth::Builder do
|
|
22
|
+
::Ditty::Services::Authentication.providers.each do |prov|
|
|
23
|
+
provider prov, *::Ditty::Services::Authentication.config[prov][:arguments]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
map '/' do
|
|
28
|
+
use Rack::Static, root: 'public', urls: ['/css', '/images', '/js'], header_rules: [
|
|
29
|
+
[:all, { 'Cache-Control' => 'public, max-age=31536000' }]
|
|
30
|
+
]
|
|
31
|
+
require 'ditty/middleware/accept_extension'
|
|
32
|
+
use Ditty::Middleware::AcceptExtension
|
|
33
|
+
require 'rack/content_type'
|
|
34
|
+
use Rack::ContentType
|
|
35
|
+
|
|
36
|
+
run Rack::URLMap.new ::Ditty::Components.routes
|
|
37
|
+
end
|