ditty 0.8.0 → 0.9.0
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/.gitignore +2 -0
- data/.pryrc +2 -0
- data/.rubocop.yml +1 -1
- data/.travis.yml +5 -4
- data/CNAME +1 -0
- data/Dockerfile +18 -0
- data/Gemfile.ci +0 -2
- data/Rakefile +2 -2
- data/_config.yml +1 -0
- data/config.ru +4 -4
- data/ditty.gemspec +9 -3
- 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 +4 -2
- data/lib/ditty/cli.rb +28 -4
- data/lib/ditty/components/{app.rb → ditty.rb} +19 -14
- data/lib/ditty/controllers/{application.rb → application_controller.rb} +58 -29
- data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +2 -2
- data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +17 -16
- data/lib/ditty/controllers/{component.rb → component_controller.rb} +19 -18
- data/lib/ditty/controllers/{main.rb → main_controller.rb} +6 -2
- data/lib/ditty/controllers/roles_controller.rb +23 -0
- data/lib/ditty/controllers/{user_login_traits.rb → user_login_traits_controller.rb} +4 -3
- data/lib/ditty/controllers/{users.rb → users_controller.rb} +11 -10
- data/lib/ditty/db.rb +4 -3
- data/lib/ditty/emails/base.rb +5 -2
- data/lib/ditty/generators/crud_generator.rb +104 -0
- data/lib/ditty/generators/migration_generator.rb +26 -0
- data/lib/ditty/generators/project_generator.rb +51 -0
- data/lib/ditty/helpers/component.rb +2 -1
- data/lib/ditty/helpers/pundit.rb +20 -4
- data/lib/ditty/helpers/response.rb +20 -13
- data/lib/ditty/helpers/views.rb +7 -3
- data/lib/ditty/listener.rb +5 -3
- data/lib/ditty/memcached.rb +8 -0
- data/lib/ditty/middleware/accept_extension.rb +2 -2
- data/lib/ditty/middleware/error_catchall.rb +2 -2
- data/lib/ditty/models/base.rb +4 -0
- data/lib/ditty/models/role.rb +1 -0
- data/lib/ditty/models/user.rb +14 -1
- data/lib/ditty/policies/role_policy.rb +1 -1
- data/lib/ditty/policies/user_login_trait_policy.rb +1 -1
- data/lib/ditty/services/authentication.rb +11 -10
- data/lib/ditty/services/email.rb +8 -4
- data/lib/ditty/services/logger.rb +1 -1
- data/lib/ditty/tasks/ditty.rake +17 -0
- data/lib/ditty/tasks/omniauth-ldap.rake +2 -2
- 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 +58 -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/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
- data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
- data/lib/ditty/templates/settings.yml.erb +18 -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 +2 -2
- data/migrate/20181209_add_user_login_traits.rb +4 -4
- data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
- data/public/css/styles.css +13 -0
- data/public/js/scripts.js +1 -0
- data/views/404.haml +2 -4
- data/views/audit_logs/index.haml +32 -34
- data/views/auth/forgot_password.haml +27 -16
- data/views/auth/identity.haml +14 -13
- data/views/auth/ldap.haml +2 -2
- data/views/auth/login.haml +22 -17
- data/views/auth/register.haml +19 -18
- data/views/auth/register_identity.haml +27 -12
- data/views/auth/reset_password.haml +2 -2
- data/views/blank.haml +42 -0
- data/views/index.haml +1 -1
- data/views/layout.haml +37 -30
- data/views/partials/content_tag.haml +0 -0
- data/views/partials/delete_form.haml +1 -1
- data/views/partials/filter_control.haml +1 -1
- data/views/partials/footer.haml +5 -5
- data/views/partials/form_control.haml +19 -12
- data/views/partials/navitems.haml +44 -0
- data/views/partials/notifications.haml +12 -8
- data/views/partials/pager.haml +17 -17
- data/views/partials/search.haml +6 -7
- data/views/partials/sidebar.haml +15 -37
- data/views/partials/topbar.haml +68 -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 -16
- data/views/roles/new.haml +2 -2
- data/views/user_login_traits/display.haml +4 -4
- data/views/user_login_traits/edit.haml +3 -3
- data/views/user_login_traits/index.haml +4 -4
- data/views/user_login_traits/new.haml +2 -2
- data/views/users/display.haml +11 -12
- 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 +6 -8
- data/views/users/new.haml +2 -2
- data/views/users/profile.haml +13 -13
- metadata +143 -15
- data/lib/ditty/controllers/roles.rb +0 -13
- data/views/partials/navbar.haml +0 -22
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor/group'
|
|
4
|
+
require 'active_support/inflector'
|
|
5
|
+
|
|
6
|
+
module Ditty
|
|
7
|
+
module Generators
|
|
8
|
+
class MigrationGenerator < Thor::Group
|
|
9
|
+
include Thor::Actions
|
|
10
|
+
|
|
11
|
+
attr_reader :namespace, :folder
|
|
12
|
+
|
|
13
|
+
desc 'Creates a new Sequel migration for the current project'
|
|
14
|
+
argument :name, type: :string, desc: 'Name of the migration'
|
|
15
|
+
|
|
16
|
+
def self.source_root
|
|
17
|
+
File.expand_path('../templates', __dir__)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_model
|
|
21
|
+
filename = File.join('migrations', "#{Time.now.strftime('%Y%m%d')}_#{name.underscore}.rb")
|
|
22
|
+
template '../templates/migration.rb.erb', filename
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor/group'
|
|
4
|
+
require 'active_support/inflector'
|
|
5
|
+
|
|
6
|
+
module Ditty
|
|
7
|
+
module Generators
|
|
8
|
+
class ProjectGenerator < Thor::Group
|
|
9
|
+
include Thor::Actions
|
|
10
|
+
|
|
11
|
+
attr_reader :name, :namespace, :folder
|
|
12
|
+
|
|
13
|
+
desc 'Initialize a new Ditty project in the current folder'
|
|
14
|
+
|
|
15
|
+
def setup
|
|
16
|
+
@name = File.basename(Dir.getwd)
|
|
17
|
+
@folder = @name.underscore
|
|
18
|
+
@namespace = folder.classify
|
|
19
|
+
@name = @name.titleize
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.source_root
|
|
23
|
+
File.expand_path('../templates', __dir__)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create_startup_files
|
|
27
|
+
directory 'logs'
|
|
28
|
+
directory 'pids'
|
|
29
|
+
directory 'public'
|
|
30
|
+
copy_file '.gitignore', './.gitignore'
|
|
31
|
+
copy_file 'env.example', './.env'
|
|
32
|
+
copy_file '.rubocop.yml', './.rubocop.yml'
|
|
33
|
+
copy_file '.rspec', './.rspec'
|
|
34
|
+
|
|
35
|
+
template 'lib/project.rb.erb', "lib/#{folder}.rb"
|
|
36
|
+
|
|
37
|
+
copy_file 'application.rb', './application.rb'
|
|
38
|
+
copy_file 'config.ru', './config.ru'
|
|
39
|
+
copy_file 'Rakefile', './Rakefile'
|
|
40
|
+
copy_file 'sidekiq.rb', './config/sidekiq.rb'
|
|
41
|
+
copy_file 'sidekiq.yml', './config/sidekiq.yml'
|
|
42
|
+
|
|
43
|
+
copy_file 'spec_helper.rb', './specs/spec_helper.rb'
|
|
44
|
+
copy_file '../../../spec/support/api_shared_examples.rb', './specs/support/api_shared_examples.rb'
|
|
45
|
+
copy_file '../../../spec/support/crud_shared_examples.rb', './specs/support/crud_shared_examples.rb'
|
|
46
|
+
|
|
47
|
+
template 'settings.yml.erb', './config/settings.yml'
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -33,11 +33,12 @@ module Ditty
|
|
|
33
33
|
param :q, String
|
|
34
34
|
param :page, Integer, min: 1, default: 1
|
|
35
35
|
param :sort, String
|
|
36
|
-
param :order, String, in: %w[asc desc], transform: :downcase
|
|
36
|
+
param :order, String, in: %w[asc desc], transform: :downcase
|
|
37
37
|
# TODO: Can we dynamically validate the search / filter fields?
|
|
38
38
|
|
|
39
39
|
ds = dataset
|
|
40
40
|
ds = ds.dataset if ds.respond_to?(:dataset)
|
|
41
|
+
params[:order] ||= 'asc' if params[:sort]
|
|
41
42
|
return ds if params[:count] == 'all'
|
|
42
43
|
|
|
43
44
|
params[:count] = check_count
|
data/lib/ditty/helpers/pundit.rb
CHANGED
|
@@ -12,23 +12,39 @@ module Ditty
|
|
|
12
12
|
super
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def permitted_attributes(record, action)
|
|
16
|
-
param_key = PolicyFinder.new(record).param_key
|
|
15
|
+
def permitted_attributes(record, action = nil)
|
|
17
16
|
policy = policy(record)
|
|
17
|
+
action ||= record.new? ? :create : :update
|
|
18
18
|
method_name = if policy.respond_to?("permitted_attributes_for_#{action}")
|
|
19
19
|
"permitted_attributes_for_#{action}"
|
|
20
20
|
else
|
|
21
21
|
'permitted_attributes'
|
|
22
22
|
end
|
|
23
|
+
policy.public_send(method_name)
|
|
24
|
+
end
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
def permitted_parameters(record, action = nil)
|
|
27
|
+
param_key = PolicyFinder.new(record).param_key
|
|
28
|
+
policy_fields = permitted_attributes(record, action)
|
|
25
29
|
request.params.fetch(param_key, {}).select do |key, _value|
|
|
26
30
|
policy_fields.include? key.to_sym
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
|
|
34
|
+
def permitted_response_attributes(record, method = :values)
|
|
35
|
+
policy = policy(record)
|
|
36
|
+
response = record.send(method)
|
|
37
|
+
|
|
38
|
+
return response unless policy.respond_to? :response_attributes
|
|
39
|
+
|
|
40
|
+
policy_fields = policy.response_attributes
|
|
41
|
+
response.select do |key, _value|
|
|
42
|
+
policy_fields.include? key.to_sym
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
30
46
|
def pundit_user
|
|
31
|
-
current_user
|
|
47
|
+
current_user unless current_user&.anonymous?
|
|
32
48
|
end
|
|
33
49
|
end
|
|
34
50
|
end
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
require 'csv'
|
|
4
4
|
|
|
5
|
+
require 'csv'
|
|
6
|
+
|
|
5
7
|
module Ditty
|
|
6
8
|
module Helpers
|
|
7
9
|
module Response
|
|
8
|
-
def list_response(result)
|
|
10
|
+
def list_response(result, view: 'index')
|
|
9
11
|
respond_to do |format|
|
|
10
12
|
format.html do
|
|
11
13
|
actions = {}
|
|
12
14
|
actions["#{base_path}/new"] = "New #{heading}" if policy(settings.model_class).create?
|
|
13
|
-
haml :"#{view_location}
|
|
15
|
+
haml :"#{view_location}/#{view}",
|
|
14
16
|
locals: { list: result, title: heading(:list), actions: actions },
|
|
15
17
|
layout: layout
|
|
16
18
|
end
|
|
@@ -18,7 +20,7 @@ module Ditty
|
|
|
18
20
|
# TODO: Add links defined by actions (New #{heading})
|
|
19
21
|
total = result.respond_to?(:pagination_record_count) ? result.pagination_record_count : result.count
|
|
20
22
|
json(
|
|
21
|
-
'items' => result.all.map(
|
|
23
|
+
'items' => result.all.map { |e| permitted_response_attributes(e, :for_json) },
|
|
22
24
|
'page' => (params['page'] || 1).to_i,
|
|
23
25
|
'count' => result.count,
|
|
24
26
|
'total' => total
|
|
@@ -39,18 +41,18 @@ module Ditty
|
|
|
39
41
|
respond_to do |format|
|
|
40
42
|
format.html do
|
|
41
43
|
flash[:success] = "#{heading} Created"
|
|
42
|
-
redirect with_layout("#{base_path}/#{entity.
|
|
44
|
+
redirect with_layout(flash[:redirect_to] || "#{base_path}/#{entity.display_id}")
|
|
43
45
|
end
|
|
44
46
|
format.json do
|
|
45
47
|
content_type :json
|
|
46
|
-
redirect "#{base_path}/#{entity.
|
|
48
|
+
redirect "#{base_path}/#{entity.display_id}", 201
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def actions(entity = nil)
|
|
52
54
|
actions = {}
|
|
53
|
-
actions["#{base_path}/#{entity.
|
|
55
|
+
actions["#{base_path}/#{entity.display_id}/edit"] = "Edit #{heading}" if entity && policy(entity).update?
|
|
54
56
|
actions["#{base_path}/new"] = "New #{heading}" if policy(settings.model_class).create?
|
|
55
57
|
actions
|
|
56
58
|
end
|
|
@@ -66,7 +68,13 @@ module Ditty
|
|
|
66
68
|
end
|
|
67
69
|
format.json do
|
|
68
70
|
# TODO: Add links defined by actions (Edit #{heading})
|
|
69
|
-
json entity
|
|
71
|
+
json permitted_response_attributes(entity, :for_json)
|
|
72
|
+
end
|
|
73
|
+
format.csv do
|
|
74
|
+
CSV.generate do |csv|
|
|
75
|
+
csv << entity.for_csv.keys
|
|
76
|
+
csv << entity.for_csv.values
|
|
77
|
+
end
|
|
70
78
|
end
|
|
71
79
|
format.csv do
|
|
72
80
|
CSV.generate do |csv|
|
|
@@ -82,11 +90,11 @@ module Ditty
|
|
|
82
90
|
format.html do
|
|
83
91
|
# TODO: Ability to customize the return path and message?
|
|
84
92
|
flash[:success] = "#{heading} Updated"
|
|
85
|
-
redirect with_layout("#{base_path}/#{entity.
|
|
93
|
+
redirect with_layout(flash[:redirect_to] || back || "#{base_path}/#{entity.display_id}")
|
|
86
94
|
end
|
|
87
95
|
format.json do
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
content_type :json
|
|
97
|
+
redirect "#{base_path}/#{entity.display_id}", 200, json(entity.for_json)
|
|
90
98
|
end
|
|
91
99
|
end
|
|
92
100
|
end
|
|
@@ -95,12 +103,11 @@ module Ditty
|
|
|
95
103
|
respond_to do |format|
|
|
96
104
|
format.html do
|
|
97
105
|
flash[:success] = "#{heading} Deleted"
|
|
98
|
-
redirect with_layout(base_path
|
|
106
|
+
redirect with_layout(flash[:redirect_to] || back || base_path)
|
|
99
107
|
end
|
|
100
108
|
format.json do
|
|
101
109
|
content_type :json
|
|
102
|
-
|
|
103
|
-
status 204
|
|
110
|
+
redirect base_path.to_s, 204
|
|
104
111
|
end
|
|
105
112
|
end
|
|
106
113
|
end
|
data/lib/ditty/helpers/views.rb
CHANGED
|
@@ -24,9 +24,11 @@ module Ditty
|
|
|
24
24
|
def form_control(name, model, opts = {})
|
|
25
25
|
label = opts.delete(:label) || name.to_s.titlecase
|
|
26
26
|
klass = opts.delete(:class) || 'form-control' unless opts[:type] == 'file'
|
|
27
|
+
klass = "#{klass} is-invalid" if model.errors[name]
|
|
27
28
|
group = opts.delete(:group) || model.class.to_s.demodulize.underscore
|
|
28
29
|
field = opts.delete(:field) || name
|
|
29
30
|
default = opts.delete(:default) || nil
|
|
31
|
+
help_text = opts.delete(:help_text) || nil
|
|
30
32
|
|
|
31
33
|
attributes = { type: 'text', id: name, name: "#{group}[#{name}]", class: klass }.merge(opts)
|
|
32
34
|
haml :'partials/form_control', locals: {
|
|
@@ -36,7 +38,8 @@ module Ditty
|
|
|
36
38
|
name: name,
|
|
37
39
|
group: group,
|
|
38
40
|
field: field,
|
|
39
|
-
default: default
|
|
41
|
+
default: default,
|
|
42
|
+
help_text: help_text
|
|
40
43
|
}
|
|
41
44
|
end
|
|
42
45
|
|
|
@@ -47,7 +50,8 @@ module Ditty
|
|
|
47
50
|
haml :'partials/filter_control', locals: {
|
|
48
51
|
name: filter[:name],
|
|
49
52
|
label: opts[:label] || filter[:name].to_s.titlecase,
|
|
50
|
-
options: send(meth)
|
|
53
|
+
options: send(meth),
|
|
54
|
+
total_filters: opts[:filters]
|
|
51
55
|
}
|
|
52
56
|
end
|
|
53
57
|
|
|
@@ -98,7 +102,7 @@ module Ditty
|
|
|
98
102
|
def pagination(list, base_path, qp = {})
|
|
99
103
|
return unless list.respond_to?(:pagination_record_count) || list.respond_to?(:total_entries)
|
|
100
104
|
|
|
101
|
-
list = Ditty::Services::PaginationWrapper.new(list)
|
|
105
|
+
list = ::Ditty::Services::PaginationWrapper.new(list)
|
|
102
106
|
locals = {
|
|
103
107
|
first_link: "#{base_path}?" + query_string(qp.merge(page: 1)),
|
|
104
108
|
next_link: list.last_page? ? '#' : "#{base_path}?" + query_string(qp.merge(page: list.next_page)),
|
data/lib/ditty/listener.rb
CHANGED
|
@@ -17,7 +17,9 @@ module Ditty
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def method_missing(method, *args)
|
|
20
|
-
|
|
20
|
+
unless args[0].is_a?(Hash) && args[0][:target].is_a?(Sinatra::Base) && args[0][:target].settings.track_actions
|
|
21
|
+
return
|
|
22
|
+
end
|
|
21
23
|
|
|
22
24
|
log_action(
|
|
23
25
|
user_traits(args[0][:target]).merge(
|
|
@@ -69,7 +71,7 @@ module Ditty
|
|
|
69
71
|
|
|
70
72
|
def log_action(values)
|
|
71
73
|
values[:user] ||= values[:target].current_user if values[:target]
|
|
72
|
-
@mutex.synchronize { Ditty::AuditLog.create values }
|
|
74
|
+
@mutex.synchronize { ::Ditty::AuditLog.create values }
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
def user_traits(target)
|
|
@@ -84,4 +86,4 @@ module Ditty
|
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
Wisper.subscribe(Ditty::Listener.new) unless ENV['RACK_ENV'] == 'test'
|
|
89
|
+
Wisper.subscribe(::Ditty::Listener.new) unless ENV['RACK_ENV'] == 'test'
|
|
@@ -8,7 +8,7 @@ module Ditty
|
|
|
8
8
|
class AcceptExtension
|
|
9
9
|
attr_reader :env, :regex, :content_type
|
|
10
10
|
|
|
11
|
-
def initialize(app, regex =
|
|
11
|
+
def initialize(app, regex = %r{\A(.*)\.json(/?)\Z}, content_type = 'application/json')
|
|
12
12
|
# @mutex = Mutex.new
|
|
13
13
|
@app = app
|
|
14
14
|
@regex = regex
|
|
@@ -19,7 +19,7 @@ module Ditty
|
|
|
19
19
|
@env = env
|
|
20
20
|
|
|
21
21
|
request = Rack::Request.new(env)
|
|
22
|
-
if request.path
|
|
22
|
+
if request.path&.match?(regex)
|
|
23
23
|
request.path_info = request.path_info.gsub(regex, '\1\2')
|
|
24
24
|
env = request.env
|
|
25
25
|
env['ACCEPT'] = content_type
|
|
@@ -16,8 +16,8 @@ module Ditty
|
|
|
16
16
|
begin
|
|
17
17
|
@app.call env
|
|
18
18
|
rescue StandardError => e
|
|
19
|
-
::Ditty::Services::Logger.
|
|
20
|
-
::Ditty::Services::Logger.
|
|
19
|
+
::Ditty::Services::Logger.error "Ditty Catchall: #{e.class}"
|
|
20
|
+
::Ditty::Services::Logger.error e
|
|
21
21
|
[500, {}, ['Unknown Error']]
|
|
22
22
|
end
|
|
23
23
|
end
|
data/lib/ditty/models/base.rb
CHANGED
data/lib/ditty/models/role.rb
CHANGED
data/lib/ditty/models/user.rb
CHANGED
|
@@ -17,11 +17,20 @@ module Ditty
|
|
|
17
17
|
|
|
18
18
|
def role?(check)
|
|
19
19
|
@roles ||= Hash.new do |h, k|
|
|
20
|
-
|
|
20
|
+
role_or_descendant = roles.find do |role|
|
|
21
|
+
role.name == k || role.descendants.map(&:name).include?(k)
|
|
22
|
+
end
|
|
23
|
+
h[k] = !role_or_descendant.nil?
|
|
21
24
|
end
|
|
22
25
|
@roles[check]
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
def all_roles
|
|
29
|
+
roles.inject([]) do |memo, role|
|
|
30
|
+
memo + [role] + role.descendants
|
|
31
|
+
end.uniq
|
|
32
|
+
end
|
|
33
|
+
|
|
25
34
|
def method_missing(method_sym, *arguments, &block)
|
|
26
35
|
if respond_to_missing?(method_sym)
|
|
27
36
|
role?(method_sym[0..-2])
|
|
@@ -68,6 +77,10 @@ module Ditty
|
|
|
68
77
|
email
|
|
69
78
|
end
|
|
70
79
|
|
|
80
|
+
def display_name
|
|
81
|
+
name || username
|
|
82
|
+
end
|
|
83
|
+
|
|
71
84
|
class << self
|
|
72
85
|
def anonymous_user
|
|
73
86
|
role = ::Ditty::Role.find_or_create(name: 'anonymous')
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'ditty/controllers/
|
|
3
|
+
require 'ditty/controllers/application_controller'
|
|
4
4
|
require 'ditty/services/settings'
|
|
5
5
|
require 'ditty/services/logger'
|
|
6
6
|
require 'backports/2.4.0/hash/compact'
|
|
7
7
|
|
|
8
8
|
require 'omniauth'
|
|
9
|
-
OmniAuth.config.logger = Ditty::Services::Logger
|
|
10
|
-
OmniAuth.config.path_prefix = "#{Ditty::
|
|
9
|
+
OmniAuth.config.logger = ::Ditty::Services::Logger
|
|
10
|
+
OmniAuth.config.path_prefix = "#{::Ditty::ApplicationController.map_path}/auth"
|
|
11
11
|
OmniAuth.config.on_failure = proc { |env|
|
|
12
12
|
next [400, {}, []] if env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
|
|
13
13
|
|
|
@@ -28,8 +28,9 @@ module Ditty
|
|
|
28
28
|
|
|
29
29
|
def setup
|
|
30
30
|
providers.each do |provider|
|
|
31
|
+
req = config.dig(provider, :require) || "omniauth/#{provider}"
|
|
31
32
|
begin
|
|
32
|
-
require
|
|
33
|
+
require req
|
|
33
34
|
rescue LoadError
|
|
34
35
|
require "omniauth-#{provider}"
|
|
35
36
|
end
|
|
@@ -37,7 +38,7 @@ module Ditty
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def config
|
|
40
|
-
default.merge Ditty::Services::Settings.values(:authentication) || {}
|
|
41
|
+
default.merge ::Ditty::Services::Settings.values(:authentication) || {}
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def provides?(provider)
|
|
@@ -46,15 +47,15 @@ module Ditty
|
|
|
46
47
|
|
|
47
48
|
def default
|
|
48
49
|
require 'ditty/models/identity'
|
|
49
|
-
require 'ditty/controllers/
|
|
50
|
+
require 'ditty/controllers/auth_controller'
|
|
50
51
|
{
|
|
51
52
|
identity: {
|
|
52
53
|
arguments: [
|
|
53
54
|
{
|
|
54
55
|
fields: [:username],
|
|
55
|
-
model: Ditty::Identity,
|
|
56
|
-
on_login: Ditty::
|
|
57
|
-
on_registration: Ditty::
|
|
56
|
+
model: ::Ditty::Identity,
|
|
57
|
+
on_login: ::Ditty::AuthController,
|
|
58
|
+
on_registration: ::Ditty::AuthController,
|
|
58
59
|
locate_conditions: ->(req) { { username: req['username'] } }
|
|
59
60
|
}
|
|
60
61
|
]
|
|
@@ -66,4 +67,4 @@ module Ditty
|
|
|
66
67
|
end
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
Ditty::Services::Authentication.setup
|
|
70
|
+
::Ditty::Services::Authentication.setup
|