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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.env.test +2 -0
  3. data/.gitignore +3 -0
  4. data/.pryrc +2 -0
  5. data/.rubocop.yml +24 -8
  6. data/.travis.yml +4 -8
  7. data/CNAME +1 -0
  8. data/Dockerfile +18 -0
  9. data/Gemfile.ci +0 -15
  10. data/Rakefile +5 -4
  11. data/Readme.md +24 -2
  12. data/_config.yml +1 -0
  13. data/config.ru +4 -4
  14. data/ditty.gemspec +31 -20
  15. data/docs/CNAME +1 -0
  16. data/docs/_config.yml +1 -0
  17. data/docs/index.md +34 -0
  18. data/exe/ditty +2 -0
  19. data/lib/ditty.rb +30 -4
  20. data/lib/ditty/cli.rb +38 -5
  21. data/lib/ditty/components/ditty.rb +82 -0
  22. data/lib/ditty/controllers/application_controller.rb +267 -0
  23. data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +5 -7
  24. data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +56 -32
  25. data/lib/ditty/controllers/{component.rb → component_controller.rb} +35 -24
  26. data/lib/ditty/controllers/{main.rb → main_controller.rb} +7 -7
  27. data/lib/ditty/controllers/roles_controller.rb +23 -0
  28. data/lib/ditty/controllers/user_login_traits_controller.rb +46 -0
  29. data/lib/ditty/controllers/{users.rb → users_controller.rb} +17 -20
  30. data/lib/ditty/db.rb +9 -5
  31. data/lib/ditty/emails/base.rb +48 -34
  32. data/lib/ditty/generators/crud_generator.rb +114 -0
  33. data/lib/ditty/generators/migration_generator.rb +26 -0
  34. data/lib/ditty/generators/project_generator.rb +52 -0
  35. data/lib/ditty/helpers/authentication.rb +6 -5
  36. data/lib/ditty/helpers/component.rb +11 -2
  37. data/lib/ditty/helpers/pundit.rb +24 -8
  38. data/lib/ditty/helpers/response.rb +38 -15
  39. data/lib/ditty/helpers/views.rb +48 -6
  40. data/lib/ditty/listener.rb +44 -14
  41. data/lib/ditty/memcached.rb +8 -0
  42. data/lib/ditty/middleware/accept_extension.rb +4 -2
  43. data/lib/ditty/middleware/error_catchall.rb +4 -2
  44. data/lib/ditty/models/audit_log.rb +1 -0
  45. data/lib/ditty/models/base.rb +13 -0
  46. data/lib/ditty/models/identity.rb +10 -7
  47. data/lib/ditty/models/role.rb +2 -0
  48. data/lib/ditty/models/user.rb +40 -3
  49. data/lib/ditty/models/user_login_trait.rb +17 -0
  50. data/lib/ditty/policies/audit_log_policy.rb +6 -6
  51. data/lib/ditty/policies/role_policy.rb +3 -3
  52. data/lib/ditty/policies/user_login_trait_policy.rb +45 -0
  53. data/lib/ditty/policies/user_policy.rb +3 -3
  54. data/lib/ditty/rubocop.rb +3 -0
  55. data/lib/ditty/seed.rb +2 -0
  56. data/lib/ditty/services/authentication.rb +31 -15
  57. data/lib/ditty/services/email.rb +22 -12
  58. data/lib/ditty/services/logger.rb +30 -13
  59. data/lib/ditty/services/pagination_wrapper.rb +9 -5
  60. data/lib/ditty/services/settings.rb +19 -7
  61. data/lib/ditty/tasks/ditty.rake +127 -0
  62. data/lib/ditty/tasks/omniauth-ldap.rake +43 -0
  63. data/lib/ditty/templates/.gitignore +5 -0
  64. data/lib/ditty/templates/.rspec +2 -0
  65. data/lib/ditty/templates/.rubocop.yml +7 -0
  66. data/lib/ditty/templates/Rakefile +12 -0
  67. data/lib/ditty/templates/application.rb +12 -0
  68. data/lib/ditty/templates/config.ru +37 -0
  69. data/lib/ditty/templates/controller.rb.erb +64 -0
  70. data/lib/ditty/templates/env.example +4 -0
  71. data/lib/ditty/templates/lib/project.rb.erb +5 -0
  72. data/lib/ditty/templates/migration.rb.erb +7 -0
  73. data/lib/ditty/templates/model.rb.erb +26 -0
  74. data/lib/ditty/templates/pids/.empty_directory +0 -0
  75. data/lib/ditty/templates/policy.rb.erb +48 -0
  76. data/{public → lib/ditty/templates/public}/browserconfig.xml +0 -0
  77. data/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
  78. data/lib/ditty/templates/public/css/styles.css +13 -0
  79. data/lib/ditty/templates/public/favicon.ico +0 -0
  80. data/{public → lib/ditty/templates/public}/images/apple-icon.png +0 -0
  81. data/{public → lib/ditty/templates/public}/images/favicon-16x16.png +0 -0
  82. data/{public → lib/ditty/templates/public}/images/favicon-32x32.png +0 -0
  83. data/{public → lib/ditty/templates/public}/images/launcher-icon-1x.png +0 -0
  84. data/{public → lib/ditty/templates/public}/images/launcher-icon-2x.png +0 -0
  85. data/{public → lib/ditty/templates/public}/images/launcher-icon-4x.png +0 -0
  86. data/{public → lib/ditty/templates/public}/images/mstile-150x150.png +0 -0
  87. data/{public → lib/ditty/templates/public}/images/safari-pinned-tab.svg +0 -0
  88. data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
  89. data/lib/ditty/templates/public/js/scripts.js +1 -0
  90. data/{public/manifest.json → lib/ditty/templates/public/manifest.json.erb} +2 -2
  91. data/lib/ditty/templates/settings.yml.erb +19 -0
  92. data/lib/ditty/templates/sidekiq.rb +18 -0
  93. data/lib/ditty/templates/sidekiq.yml +9 -0
  94. data/lib/ditty/templates/spec_helper.rb +43 -0
  95. data/lib/ditty/templates/type.rb.erb +21 -0
  96. data/lib/ditty/templates/views/display.haml.tt +20 -0
  97. data/lib/ditty/templates/views/edit.haml.tt +10 -0
  98. data/lib/ditty/templates/views/form.haml.tt +11 -0
  99. data/lib/ditty/templates/views/index.haml.tt +29 -0
  100. data/lib/ditty/templates/views/new.haml.tt +10 -0
  101. data/lib/ditty/version.rb +1 -1
  102. data/lib/rubocop/cop/ditty/call_services_directly.rb +42 -0
  103. data/migrate/20181209_add_user_login_traits.rb +16 -0
  104. data/migrate/20181209_extend_audit_log.rb +12 -0
  105. data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
  106. data/spec/ditty/api_spec.rb +51 -0
  107. data/spec/ditty/controllers/roles_spec.rb +67 -0
  108. data/spec/ditty/controllers/user_login_traits_spec.rb +72 -0
  109. data/spec/ditty/controllers/users_spec.rb +72 -0
  110. data/spec/ditty/emails/base_spec.rb +76 -0
  111. data/spec/ditty/emails/forgot_password_spec.rb +20 -0
  112. data/spec/ditty/helpers/component_spec.rb +85 -0
  113. data/spec/ditty/models/user_spec.rb +36 -0
  114. data/spec/ditty/services/email_spec.rb +36 -0
  115. data/spec/ditty/services/logger_spec.rb +68 -0
  116. data/spec/ditty/services/settings_spec.rb +63 -0
  117. data/spec/ditty_spec.rb +9 -0
  118. data/spec/factories.rb +46 -0
  119. data/spec/fixtures/logger.yml +17 -0
  120. data/spec/fixtures/section.yml +3 -0
  121. data/spec/fixtures/settings.yml +8 -0
  122. data/spec/spec_helper.rb +51 -0
  123. data/spec/support/api_shared_examples.rb +250 -0
  124. data/spec/support/crud_shared_examples.rb +145 -0
  125. data/views/403.haml +2 -0
  126. data/views/404.haml +2 -4
  127. data/views/500.haml +11 -0
  128. data/views/audit_logs/index.haml +32 -28
  129. data/views/auth/forgot_password.haml +32 -16
  130. data/views/auth/identity.haml +14 -13
  131. data/views/auth/ldap.haml +17 -0
  132. data/views/auth/login.haml +23 -17
  133. data/views/auth/register.haml +20 -18
  134. data/views/auth/register_identity.haml +27 -12
  135. data/views/auth/reset_password.haml +36 -19
  136. data/views/blank.haml +43 -0
  137. data/views/emails/forgot_password.haml +1 -1
  138. data/views/emails/layouts/action.haml +10 -6
  139. data/views/emails/layouts/alert.haml +2 -1
  140. data/views/emails/layouts/billing.haml +2 -1
  141. data/views/embedded.haml +17 -11
  142. data/views/error.haml +8 -3
  143. data/views/index.haml +1 -1
  144. data/views/layout.haml +45 -30
  145. data/views/partials/actions.haml +15 -14
  146. data/views/partials/content_tag.haml +0 -0
  147. data/views/partials/delete_form.haml +1 -1
  148. data/views/partials/filter_control.haml +2 -2
  149. data/views/partials/footer.haml +13 -5
  150. data/views/partials/form_control.haml +30 -19
  151. data/views/partials/form_tag.haml +1 -1
  152. data/views/partials/navitems.haml +42 -0
  153. data/views/partials/notifications.haml +12 -8
  154. data/views/partials/pager.haml +44 -25
  155. data/views/partials/search.haml +15 -11
  156. data/views/partials/sidebar.haml +15 -37
  157. data/views/partials/sort_ui.haml +2 -0
  158. data/views/partials/timespan_selector.haml +64 -0
  159. data/views/partials/topbar.haml +53 -0
  160. data/views/partials/user_associations.haml +32 -0
  161. data/views/quick_start.haml +23 -0
  162. data/views/roles/display.haml +27 -6
  163. data/views/roles/edit.haml +3 -3
  164. data/views/roles/form.haml +1 -0
  165. data/views/roles/index.haml +23 -14
  166. data/views/roles/new.haml +2 -2
  167. data/views/user_login_traits/display.haml +32 -0
  168. data/views/user_login_traits/edit.haml +10 -0
  169. data/views/user_login_traits/form.haml +5 -0
  170. data/views/user_login_traits/index.haml +28 -0
  171. data/views/user_login_traits/new.haml +10 -0
  172. data/views/users/display.haml +15 -16
  173. data/views/users/edit.haml +3 -3
  174. data/views/users/form.haml +0 -0
  175. data/views/users/index.haml +31 -24
  176. data/views/users/login_traits.haml +25 -0
  177. data/views/users/new.haml +2 -2
  178. data/views/users/profile.haml +17 -15
  179. data/views/users/user.haml +1 -1
  180. metadata +314 -76
  181. data/lib/ditty/components/app.rb +0 -77
  182. data/lib/ditty/controllers/application.rb +0 -175
  183. data/lib/ditty/controllers/roles.rb +0 -16
  184. data/lib/ditty/rake_tasks.rb +0 -102
  185. data/views/partials/navbar.haml +0 -23
@@ -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 deliver(email, to = nil, options = {})
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.deliver!
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
- def config
31
- default.merge Ditty::Services::Settings.values(:email) || {}
32
- end
37
+ def config
38
+ @config ||= default.merge ::Ditty::Services::Settings.values(:email) || {}
39
+ end
33
40
 
34
- def default
35
- { delivery_method: :logger, logger: Ditty::Services::Logger.instance }
36
- end
41
+ def default
42
+ {
43
+ delivery_method: :logger,
44
+ logger: ::Ditty::Services::Logger
45
+ }
46
+ end
37
47
 
38
- def from_symbol(email, options)
39
- require "ditty/emails/#{email}"
40
- constantize("Ditty::Emails::#{classify(email)}").new(options)
41
- end
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
- def config
43
- default.merge Ditty::Services::Settings.values(:logger) || {}
44
- end
47
+ def config
48
+ default.merge ::Ditty::Services::Settings.values(:logger) || {}
49
+ end
45
50
 
46
- def tr(val)
47
- {
48
- '$stdout' => $stdout,
49
- '$stderr' => $stderr
50
- }[val] || val
51
- end
51
+ def tr(val)
52
+ {
53
+ '$stdout' => $stdout,
54
+ '$stderr' => $stderr
55
+ }[val] || val
56
+ end
52
57
 
53
- def default
54
- { loggers: [{ name: 'default', class: 'Logger' }] }
55
- end
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? :'last_page?'
13
+ if list.respond_to? :last_page?
12
14
  list.last_page?
13
15
  else
14
- list.current_page == list.total_pages
16
+ list.next_page.nil?
15
17
  end
16
18
  end
17
19
 
18
20
  def first_page?
19
- if list.respond_to? :'first_page?'
21
+ if list.respond_to? :first_page?
20
22
  list.first_page?
21
23
  else
22
- list.current_page == 0
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? method
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'.freeze
20
- CONFIG_FILE = "#{CONFIG_FOLDER}/settings.yml".freeze
19
+ CONFIG_FOLDER = './config'
20
+ CONFIG_FILE = "#{CONFIG_FOLDER}/settings.yml"
21
21
 
22
22
  class << self
23
23
  def [](key)
24
- values(key.to_sym)
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
- read("#{CONFIG_FOLDER}/#{k}.yml")
32
- elsif k != :settings && h[:settings].key?(k)
33
- h[:settings][k]
34
- end
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,5 @@
1
+ .token_secret
2
+ .session_secret
3
+ gems
4
+ logs/*
5
+ migrations
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,7 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+ - rubocop-thread_safety
5
+ - rubocop-sequel
6
+ - ditty/rubocop
7
+
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv/load'
4
+
5
+ require 'rake'
6
+ require 'ditty'
7
+ require 'ditty/db' if ENV['DATABASE_URL']
8
+ require 'ditty/memcached' if ENV['MEMCACHED_URL']
9
+
10
+ require './application'
11
+
12
+ Ditty::Components.tasks
@@ -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