tb_core 1.4.3.1 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -54
- data/app/assets/javascripts/admin/core/application.js +8 -4
- data/app/assets/javascripts/admin/core/dashboard.js +2 -3
- data/app/assets/javascripts/admin/core/date_picker.js +2 -2
- data/app/assets/javascripts/admin/core/editor.js +2 -2
- data/app/assets/javascripts/admin/core/modal.js +1 -1
- data/app/assets/javascripts/admin/core/users.js +5 -5
- data/app/assets/javascripts/tb_core.js +8 -0
- data/app/assets/libs/sortable/sortable.js +152 -91
- data/app/controllers/admin/application_controller.rb +1 -2
- data/app/controllers/admin/dashboard_controller.rb +2 -2
- data/app/controllers/admin/settings_controller.rb +2 -2
- data/app/controllers/admin/users_controller.rb +4 -7
- data/app/controllers/concerns/tb_core/error_handling.rb +16 -7
- data/app/controllers/concerns/tb_core/user_authentication.rb +5 -5
- data/app/controllers/tb_core/application_controller.rb +1 -1
- data/app/controllers/user_sessions_controller.rb +2 -2
- data/app/helpers/tb_core/application_helper.rb +4 -36
- data/app/mailers/tb_core_mailer.rb +3 -3
- data/app/models/concerns/tb_core/user_model.rb +131 -0
- data/app/models/spud/spud_user_model.rb +6 -138
- data/app/models/spud_permission.rb +4 -4
- data/app/models/spud_role.rb +1 -1
- data/app/models/spud_user.rb +2 -1
- data/app/views/admin/dashboard/index.html.erb +1 -1
- data/app/views/admin/settings/_form.html.erb +1 -1
- data/app/views/admin/settings/edit.html.erb +1 -1
- data/app/views/admin/setup/new.html.erb +1 -1
- data/app/views/admin/users/_form.html.erb +1 -1
- data/app/views/admin/users/index.html.erb +2 -2
- data/app/views/admin/users/show.html.erb +1 -1
- data/app/views/layouts/admin/application.html.erb +6 -6
- data/app/views/layouts/admin/login.html.erb +1 -1
- data/app/views/tb_core_mailer/forgot_password_notification.html.erb +2 -2
- data/app/views/tb_core_mailer/user_credentials.html.erb +2 -2
- data/app/views/user_sessions/_form.html.erb +1 -1
- data/app/views/user_sessions/new.html.erb +1 -1
- data/lib/generators/spud/module_generator.rb +7 -7
- data/lib/generators/spud/setup_generator.rb +6 -7
- data/lib/generators/spud/templates/assets/admin/application.js +1 -1
- data/lib/generators/spud/templates/assets/application.js +3 -4
- data/lib/generators/spud/templates/controller_spec.rb.erb +5 -5
- data/lib/generators/spud/templates/views/admin/_form.html.erb +1 -1
- data/lib/generators/spud/templates/views/admin/index.html.erb +1 -1
- data/lib/generators/spud/templates/views/admin/show.html.erb +1 -1
- data/lib/generators/spud/templates/views/frontend/index.html.erb +1 -1
- data/lib/generators/spud/templates/views/frontend/show.html.erb +1 -1
- data/lib/tb_core.rb +3 -5
- data/lib/tb_core/belongs_to_app.rb +47 -46
- data/lib/tb_core/catch_all_route.rb +3 -0
- data/lib/tb_core/configuration.rb +28 -0
- data/lib/tb_core/engine.rb +61 -0
- data/lib/tb_core/errors.rb +50 -0
- data/lib/tb_core/responder.rb +0 -26
- data/lib/{spud_core → tb_core}/searchable.rb +4 -1
- data/lib/tb_core/spud_core.rb +23 -0
- data/lib/{spud_core → tb_core}/test_files.rb +0 -0
- data/lib/tb_core/test_helper.rb +3 -3
- data/lib/tb_core/version.rb +3 -0
- data/spec/controllers/admin/application_controller_spec.rb +5 -5
- data/spec/controllers/admin/dashboard_controller_spec.rb +5 -5
- data/spec/controllers/admin/password_reset_controller_spec.rb +1 -1
- data/spec/controllers/admin/settings_controller_spec.rb +1 -1
- data/spec/controllers/admin/setup_controller_spec.rb +2 -2
- data/spec/controllers/admin/user_sessions_controller_spec.rb +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +17 -17
- data/spec/dummy/app/assets/javascripts/admin/application.js +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/factories/spud_admin_permission_factories.rb +2 -2
- data/spec/factories/spud_role_factories.rb +2 -2
- data/spec/factories/spud_user_factories.rb +6 -6
- data/spec/helpers/spud/admin/application_helper_spec.rb +1 -1
- data/spec/helpers/tb_core/application_helper_spec.rb +0 -35
- data/spec/lib/spud_core/configuration_spec.rb +2 -2
- data/spec/lib/tb_core/belongs_to_app_spec.rb +4 -3
- data/spec/models/spud_role_spec.rb +2 -2
- data/spec/models/spud_user_spec.rb +13 -13
- data/spec/rails_helper.rb +1 -1
- metadata +59 -67
- data/app/assets/javascripts/tb_core.js.erb +0 -9
- data/app/assets/javascripts/tb_core/configuration.js.erb +0 -9
- data/app/assets/javascripts/tb_core/console.js +0 -12
- data/app/assets/javascripts/tb_core/remote.js +0 -237
- data/app/assets/javascripts/tb_core/utility.js +0 -55
- data/app/controllers/concerns/tb_core/sortable_params.rb +0 -80
- data/app/controllers/spud/application_controller.rb +0 -10
- data/lib/generators/spud/templates/assets/bootstrap.js +0 -14
- data/lib/spud_core/catch_all_route.rb +0 -3
- data/lib/spud_core/configuration.rb +0 -56
- data/lib/spud_core/engine.rb +0 -76
- data/lib/spud_core/errors.rb +0 -47
- data/lib/spud_core/version.rb +0 -5
- data/lib/tb_core/table_header.rb +0 -92
- data/spec/controllers/tb_core/sortable_params_spec.rb +0 -64
@@ -10,24 +10,24 @@ class SpudPermission
|
|
10
10
|
|
11
11
|
# Find a permission by tag
|
12
12
|
def self.find(tag)
|
13
|
-
return
|
13
|
+
return TbCore.permissions.find{ |p| p.tag == tag }
|
14
14
|
end
|
15
15
|
|
16
16
|
# Returns hash of permissions, grouped by tag namespace
|
17
17
|
def self.grouped_by_tag
|
18
|
-
return
|
18
|
+
return TbCore.permissions.group_by do |p|
|
19
19
|
p.tag.split('.').first
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# Returns array permissions sorted by tag
|
24
24
|
def self.sorted_by_tag
|
25
|
-
return
|
25
|
+
return TbCore.permissions.sort_by(&:tag)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns all permissions
|
29
29
|
def self.all
|
30
|
-
return
|
30
|
+
return TbCore.permissions
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
data/app/models/spud_role.rb
CHANGED
data/app/models/spud_user.rb
CHANGED
@@ -9,6 +9,6 @@
|
|
9
9
|
<%= render :partial => "form", :locals => {:f => f} %>
|
10
10
|
<div class="form-actions">
|
11
11
|
<%= f.submit "Save Settings", :class=>"btn btn-primary"%> or
|
12
|
-
<%=link_to "cancel", (@current_user.
|
12
|
+
<%=link_to "cancel", (@current_user.admin_rights? ? admin_root_path : root_path), :class => "btn btn-default" %>
|
13
13
|
</div>
|
14
14
|
<% end %>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<%= content_for :detail do %>
|
9
9
|
<div class="table-responsive">
|
10
10
|
<table class="table table-striped table-hover">
|
11
|
-
<%=
|
11
|
+
<%= sortable_table_header :admin_users_path, model: SpudUser do |t| %>
|
12
12
|
<%= t.sortable :name %>
|
13
13
|
<%= t.sortable :email %>
|
14
14
|
<%= t.sortable :current_login_at %>
|
@@ -34,6 +34,6 @@
|
|
34
34
|
<%= will_paginate @spud_users, :renderer => BootstrapPagination::Rails %>
|
35
35
|
|
36
36
|
<script>
|
37
|
-
|
37
|
+
document.addEventListener('DOMContentLoaded', tb.users.index);
|
38
38
|
</script>
|
39
39
|
<% end %>
|
@@ -1,24 +1,24 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
|
-
<title><%=
|
5
|
-
<%= stylesheet_link_tag *
|
6
|
-
<%= javascript_include_tag *
|
4
|
+
<title><%= TbCore.config.site_name %> Admin</title>
|
5
|
+
<%= stylesheet_link_tag *TbCore.config.admin_stylesheets %>
|
6
|
+
<%= javascript_include_tag *TbCore.config.admin_javascripts %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
9
9
|
<meta name="viewport" content="width=device-width"/>
|
10
10
|
<%= yield :head %>
|
11
11
|
</head>
|
12
12
|
<body>
|
13
|
-
<% if
|
13
|
+
<% if TbCore.production_alert_domain %>
|
14
14
|
<div class="production-alert-header">
|
15
|
-
<p><strong>Notice:</strong> This is a staging version of your website. To update your live website, please <%= link_to 'log in to production.', "http://#{
|
15
|
+
<p><strong>Notice:</strong> This is a staging version of your website. To update your live website, please <%= link_to 'log in to production.', "http://#{TbCore.production_alert_domain}/admin" %></p>
|
16
16
|
</div>
|
17
17
|
<% end %>
|
18
18
|
<div id="header">
|
19
19
|
<div class="container">
|
20
20
|
<%= link_to '/' do %>
|
21
|
-
<h1><%=
|
21
|
+
<h1><%= TbCore.config.site_name %></h1>
|
22
22
|
<% end %>
|
23
23
|
<% if current_user %>
|
24
24
|
<div class="pull-right">
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%=
|
4
|
+
<title><%= TbCore.config.site_name %> Admin: Login</title>
|
5
5
|
<%= stylesheet_link_tag 'admin/core/application' %>
|
6
6
|
<%= javascript_include_tag 'admin/core/application' %>
|
7
7
|
<%= csrf_meta_tags %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h1>Hello <%= @user.full_name %>,</h1>
|
2
2
|
|
3
|
-
<p>A password reset has recently been requested for your user account on <strong><%=
|
3
|
+
<p>A password reset has recently been requested for your user account on <strong><%= TbCore.config.site_name %></strong>. Click the link below to set your new password.</p>
|
4
4
|
|
5
5
|
<p><%= link_to @url, @url %></p>
|
6
6
|
|
@@ -8,5 +8,5 @@
|
|
8
8
|
|
9
9
|
<p>
|
10
10
|
Thanks,<br/>
|
11
|
-
<strong><%=
|
11
|
+
<strong><%= TbCore.config.site_name %></strong>
|
12
12
|
</p>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h1>Hello <%= @user.full_name %>,</h1>
|
2
2
|
|
3
|
-
<p><%= t('tb_core_mailer.user_credentials.greeting', :site_name =>
|
3
|
+
<p><%= t('tb_core_mailer.user_credentials.greeting', :site_name => TbCore.config.site_name) %></p>
|
4
4
|
|
5
5
|
<ul>
|
6
6
|
<li><strong>Username:</strong> <%= @user.login %></li>
|
@@ -15,5 +15,5 @@
|
|
15
15
|
|
16
16
|
<p>
|
17
17
|
Thanks,<br/>
|
18
|
-
<strong><%=
|
18
|
+
<strong><%= TbCore.config.site_name %></strong>
|
19
19
|
</p>
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<%= tb_form_errors(@user_session) %>
|
6
6
|
<%= hidden_field_tag :return_to, return_to %>
|
7
7
|
<div class="form-group">
|
8
|
-
<% if
|
8
|
+
<% if TbCore.config.use_email_as_login %>
|
9
9
|
<%= f.label :email %>
|
10
10
|
<%= f.text_field :email, :placeholder => 'Email', :autofocus => 'autofocus', :autocomplete => 'username', :class => 'form-control' %>
|
11
11
|
<% else %>
|
@@ -41,7 +41,7 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
|
|
41
41
|
|
42
42
|
def inject_code
|
43
43
|
environment(
|
44
|
-
"
|
44
|
+
"TbCore.config.admin_applications += [{name: '#{module_name_formatted.humanize.titlecase}',
|
45
45
|
thumbnail: \"admin/module_icon.png\", url: \"/admin/#{module_name_formatted}\"}]"
|
46
46
|
)
|
47
47
|
Rails::Generators.invoke 'model', [module_name_formatted.singularize] + attributes, behavior: behavior
|
@@ -54,12 +54,12 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def create_routes
|
57
|
-
route
|
58
|
-
namespace :admin do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
route <<~RUBY
|
58
|
+
namespace :admin do
|
59
|
+
resources :#{module_name_formatted}
|
60
|
+
end
|
61
|
+
resources :#{module_name_formatted}, :only => [:index, :show]
|
62
|
+
RUBY
|
63
63
|
end
|
64
64
|
|
65
65
|
def create_specs
|
@@ -39,18 +39,17 @@ private
|
|
39
39
|
template theme_file, 'app/assets/stylesheets/imports/bootstrap_theme.scss' if File.exist?(theme_file)
|
40
40
|
modules_file = Bootstrap::Rails::Engine.root.join('assets', 'stylesheets', '_bootstrap.scss')
|
41
41
|
template modules_file, 'app/assets/stylesheets/imports/bootstrap_modules.scss' if File.exist?(modules_file)
|
42
|
-
template 'assets/bootstrap.js', 'app/assets/javascripts/bootstrap_modules.js'
|
43
42
|
end
|
44
43
|
|
45
44
|
def spud_core_configs
|
46
45
|
site_name = application_name().titleize
|
47
46
|
domain_name = application_name().dasherize
|
48
|
-
return
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
return <<~RUBY
|
48
|
+
TbCore.configure do |config|
|
49
|
+
config.site_name = "#{site_name}"
|
50
|
+
config.from_address = "no-reply@#{domain_name}.com"
|
51
|
+
end
|
52
|
+
RUBY
|
54
53
|
end
|
55
54
|
|
56
55
|
def application_name
|
@@ -1,6 +1,5 @@
|
|
1
|
-
//= require
|
2
|
-
//= require
|
3
|
-
//= require bootstrap_modules
|
1
|
+
//= require rails-ujs
|
2
|
+
//= require rails-validator
|
4
3
|
//= require_self
|
5
4
|
//= require_directory .
|
6
5
|
|
@@ -12,6 +11,6 @@ window.app = {
|
|
12
11
|
}
|
13
12
|
};
|
14
13
|
|
15
|
-
|
14
|
+
document.addEventListener('DOMContentLoaded', app.init);
|
16
15
|
|
17
16
|
})();
|
@@ -16,7 +16,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
|
|
16
16
|
|
17
17
|
describe 'show' do
|
18
18
|
it 'should render the show page' do
|
19
|
-
<%= model_variable_name %> =
|
19
|
+
<%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
|
20
20
|
get :show, id: <%= model_variable_name %>.id
|
21
21
|
expect(response).to have_http_status :success
|
22
22
|
end
|
@@ -36,7 +36,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
|
|
36
36
|
|
37
37
|
describe 'edit' do
|
38
38
|
it 'should render the edit page' do
|
39
|
-
<%= model_variable_name %> =
|
39
|
+
<%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
|
40
40
|
get :edit, id: <%= model_variable_name %>.id
|
41
41
|
expect(response).to have_http_status :success
|
42
42
|
end
|
@@ -45,14 +45,14 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
|
|
45
45
|
describe 'create' do
|
46
46
|
it 'should create the record' do
|
47
47
|
expect do
|
48
|
-
post :create, <%= model_variable_name %>:
|
48
|
+
post :create, <%= model_variable_name %>: FactoryBot.attributes_for(:<%= model_variable_name %>)
|
49
49
|
end.to change(<%= model_class_name %>, :count).by(1)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe 'update' do
|
54
54
|
it 'should update the record' do
|
55
|
-
<%= model_variable_name %> =
|
55
|
+
<%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
|
56
56
|
current_value = <%= model_variable_name %>.<%= model_string_attribute_name %>
|
57
57
|
new_value = current_value + '-Updated'
|
58
58
|
expect do
|
@@ -64,7 +64,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
|
|
64
64
|
|
65
65
|
describe 'destroy' do
|
66
66
|
it 'should destroy the record' do
|
67
|
-
<%= model_variable_name %> =
|
67
|
+
<%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
|
68
68
|
expect do
|
69
69
|
delete :destroy, id: <%= model_variable_name %>.id
|
70
70
|
end.to change(<%= model_class_name %>, :count).by(-1)
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<%%= will_paginate @<%=module_name_formatted%>, :renderer => BootstrapPagination::Rails %>
|
32
32
|
|
33
33
|
<script>
|
34
|
-
|
34
|
+
document.addEventListener('DOMContentLoaded', app.admin.<%= module_name_formatted %>.index);
|
35
35
|
</script>
|
36
36
|
|
37
37
|
<%% end %>
|
data/lib/tb_core.rb
CHANGED
@@ -1,58 +1,59 @@
|
|
1
|
-
module TbCore
|
2
|
-
|
1
|
+
module TbCore
|
2
|
+
module BelongsToApp
|
3
|
+
extend ActiveSupport::Concern
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module ClassMethods
|
6
|
+
def belongs_to_spud_app(name, options={})
|
7
|
+
ActiveSupport::Deprecation.warn(
|
8
|
+
'ApplicationController#belongs_to_spud_app is deprecated. Please use #belongs_to_app instead.',
|
9
|
+
caller
|
10
|
+
)
|
11
|
+
belongs_to_app(name, page_title: options[:page_title])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Adds a before action to the current controller to act like the specified twice baked app
|
15
|
+
#
|
16
|
+
# symbol: This should be the :key value for the app you want to use
|
17
|
+
# page_title: Override the base name value for the app (optional)
|
18
|
+
# only: An array of controller actions you want this to apply to (optional)
|
19
|
+
#
|
20
|
+
def belongs_to_app(name, page_title: nil, only: nil)
|
21
|
+
before_action ->(){
|
22
|
+
act_as_app(name, page_title: page_title)
|
23
|
+
}, only: only
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
|
-
|
27
|
+
private
|
28
|
+
|
29
|
+
# Call the make the current controller behave as though it belongs to the specified twice baked app
|
14
30
|
#
|
15
31
|
# symbol: This should be the :key value for the app you want to use
|
16
32
|
# page_title: Override the base name value for the app (optional)
|
17
|
-
# only: An array of controller actions you want this to apply to (optional)
|
18
33
|
#
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
def act_as_app(symbol, page_title: nil)
|
35
|
+
@page_application = TbCore.admin_applications.find{ |app| app[:key] == symbol }
|
36
|
+
if @page_application.blank?
|
37
|
+
raise "Requested application '#{symbol}' could not be found"
|
38
|
+
elsif !current_user.can_view_app?(@page_application)
|
39
|
+
raise AccessDeniedError.new(item: 'module', template: '/layouts/admin/error_page')
|
40
|
+
end
|
41
|
+
@page_thumbnail = @page_application[:thumbnail]
|
42
|
+
@page_name = determine_page_name(page_title || @page_application[:name], action_name)
|
23
43
|
end
|
24
|
-
end
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
raise Spud::AccessDeniedError.new(item: 'module', template: '/layouts/admin/error_page')
|
39
|
-
end
|
40
|
-
@page_thumbnail = @page_application[:thumbnail]
|
41
|
-
@page_name = determine_page_name(page_title || @page_application[:name], action_name)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Takes a base app name and controller action name and returns an appropriate page title
|
45
|
-
#
|
46
|
-
def determine_page_name(base_name, action_name)
|
47
|
-
if action_name == 'new' || action_name == 'create'
|
48
|
-
return "New #{base_name.singularize}"
|
49
|
-
elsif action_name == 'edit' || action_name == 'update'
|
50
|
-
return "Edit #{base_name.singularize}"
|
51
|
-
elsif action_name == 'show'
|
52
|
-
return "#{base_name.singularize} Detail"
|
53
|
-
else
|
54
|
-
return base_name
|
45
|
+
# Takes a base app name and controller action name and returns an appropriate page title
|
46
|
+
#
|
47
|
+
def determine_page_name(base_name, action_name)
|
48
|
+
if ['new', 'create'].include?(action_name)
|
49
|
+
return "New #{base_name.singularize}"
|
50
|
+
elsif ['edit', 'update'].include?(action_name)
|
51
|
+
return "Edit #{base_name.singularize}"
|
52
|
+
elsif action_name == 'show'
|
53
|
+
return "#{base_name.singularize} Detail"
|
54
|
+
else
|
55
|
+
return base_name
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
58
59
|
end
|