chaltron 1.1.3 → 2.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/chaltron.js +0 -18
  3. data/app/assets/javascripts/chaltron/core.js.erb +62 -0
  4. data/app/assets/javascripts/chaltron/datatables.js +69 -0
  5. data/app/assets/javascripts/chaltron/flash_messages.js +14 -0
  6. data/app/assets/javascripts/chaltron/ldap_create.js +44 -0
  7. data/app/assets/javascripts/chaltron/locales/en.json +25 -0
  8. data/app/assets/javascripts/chaltron/locales/it.json +25 -0
  9. data/app/assets/javascripts/chaltron/navbar.js +86 -0
  10. data/app/assets/stylesheets/chaltron.scss +0 -27
  11. data/app/controllers/chaltron/omniauth_callbacks_controller.rb +4 -7
  12. data/app/controllers/chaltron/users_controller.rb +10 -0
  13. data/app/helpers/chaltron/ldap_helper.rb +9 -0
  14. data/app/helpers/chaltron/users_helper.rb +12 -7
  15. data/app/models/user.rb +24 -0
  16. data/app/views/chaltron/ldap/_entry.html.erb +3 -1
  17. data/app/views/chaltron/ldap/multi_new.html.erb +6 -2
  18. data/app/views/chaltron/users/show.html.erb +15 -4
  19. data/app/views/locales/en.yml +2 -0
  20. data/app/views/locales/it.yml +2 -0
  21. data/config/initializers/devise.rb +259 -255
  22. data/config/initializers/warden.rb +33 -0
  23. data/config/locales/en.yml +2 -1
  24. data/config/locales/it.yml +2 -1
  25. data/config/routes.rb +6 -3
  26. data/db/migrate/20200414150601_add_enabled_to_users.rb +5 -0
  27. data/lib/chaltron.rb +0 -1
  28. data/lib/chaltron/engine.rb +17 -18
  29. data/lib/chaltron/form_builder/bootstrap_form.rb +23 -0
  30. data/lib/chaltron/ldap/connection.rb +154 -152
  31. data/lib/chaltron/version.rb +1 -1
  32. data/lib/generators/chaltron/install_generator.rb +59 -5
  33. data/lib/generators/chaltron/templates/Procfile +2 -0
  34. data/lib/generators/chaltron/templates/app/assets/javascripts/{home.js.coffee → home.coffee} +0 -0
  35. data/lib/generators/chaltron/templates/app/assets/stylesheets/chaltron_custom.scss +24 -10
  36. data/lib/generators/chaltron/templates/app/assets/stylesheets/datatables.scss +2 -0
  37. data/lib/generators/chaltron/templates/app/views/layouts/application.html.erb +2 -5
  38. data/lib/generators/chaltron/templates/config/navigation.rb +8 -8
  39. metadata +15 -220
  40. data/app/assets/javascripts/chaltron/datatables.js.coffee +0 -103
  41. data/app/assets/javascripts/chaltron/localization.js.coffee +0 -59
  42. data/app/assets/javascripts/chaltron/main.js.coffee +0 -7
  43. data/app/assets/javascripts/chaltron/navbar.js.coffee +0 -58
  44. data/app/assets/javascripts/dataTables/dataTables.bootstrap4.min.js +0 -8
  45. data/app/controllers/chaltron/sessions_controller.rb +0 -17
  46. data/lib/chaltron/bootstrap_form.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d081b6eb5ec02e7c03ebfee40e7c5bbf0044af5ce5a84d00da1672099d895143
4
- data.tar.gz: 72bc1ca9c34fb24d7881e25eb834cf3d747cf4045b6f7a6bc5198a1b87876826
3
+ metadata.gz: aefae6179b039a391256431f1581b0a57d28abf2a3c4edb33f9541368f30e3b8
4
+ data.tar.gz: 4e8d46b611a4874dd2f3f5399ab24a08fdcf85c5434cb04b194ef8bb45fa0bb3
5
5
  SHA512:
6
- metadata.gz: 05e8234a1ff00fdf42be87a2057a5afefd8ef0f785fa78bf08f69f631b8145cfb97585984f0c87c416b2fad367bcf6b272b2734996cd3038b8670268528adfe3
7
- data.tar.gz: 9988543b86afb2ce68b12e1c4e965599e335795db4dde8427ad6b6639aa8a994242360029dda2e32ac822a21dbdffb6c73fb486f986b2459446c9eef79ff8fa7
6
+ metadata.gz: f69e5c6708976f4e2448c5820584039685b4c6e61b2cc6162fb68759fb3f2e72e670a399eea0927f7fe16f3ebe56ea06d9c6a02a19d10394b962c06c33e596ce
7
+ data.tar.gz: 90dfb275ad24a7d88405c16c772227f8367f1d1c619c2bd0c7f129f711eb2cf431a338729d900c8b3146208d86148a2d9af28ed08b825eb5249a28ca5b1aea7f
@@ -1,19 +1 @@
1
- //= require jquery
2
- //= require jquery_ujs
3
- //= require popper
4
- //= require bootstrap
5
- //= require datatables/jquery.dataTables
6
- //= require datatables/dataTables.bootstrap4
7
- //= require datatables/extensions/Responsive/dataTables.responsive
8
- //= require datatables/extensions/Responsive/responsive.bootstrap4
9
- //= require datatables/extensions/Select/dataTables.select
10
- //= require nprogress
11
- //= require nprogress-turbolinks
12
- //= require nprogress-ajax
13
-
14
1
  //= require_tree ./chaltron
15
-
16
-
17
- NProgress.configure({
18
- showSpinner: false,
19
- });
@@ -0,0 +1,62 @@
1
+ // Using UMD pattern from
2
+ // https://github.com/umdjs/umd#regular-module
3
+ // `returnExports.js` version
4
+ (function (root, factory) {
5
+ if (typeof define === 'function' && define.amd) {
6
+ // AMD. Register as an anonymous module.
7
+ define('Chaltron', function(){ return factory(root);});
8
+ } else if (typeof module === 'object' && module.exports) {
9
+ // Node. Does not work with strict CommonJS, but
10
+ // only CommonJS-like environments that support module.exports,
11
+ // like Node.
12
+ module.exports = factory(root);
13
+ } else {
14
+ // Browser globals (root is window)
15
+ root.Chaltron = factory(root);
16
+ }
17
+ }(this, function(global) {
18
+ 'use strict';
19
+ // Use previously defined object if exists in current scope
20
+ var Chaltron = global && global.Chaltron || {};
21
+
22
+ // Check if value is different than undefined and null;
23
+ var isSet = function(value) {
24
+ return typeof(value) !== 'undefined' && value !== null;
25
+ };
26
+
27
+ var DEFAULT_OPTIONS = {
28
+ defaultLocale: 'en',
29
+ locale: 'en'
30
+ };
31
+ var key;
32
+ for (key in DEFAULT_OPTIONS) if (!isSet(Chaltron[key])) {
33
+ Chaltron[key] = DEFAULT_OPTIONS[key];
34
+ }
35
+
36
+ // Load locales files
37
+ Chaltron.locales = {}
38
+ <% Dir.glob(File.expand_path('../locales/*.json', __FILE__)) do |file| %>
39
+ Chaltron.locales["<%= File.basename(file, '.json') %>"] = <%= File.read(file) %>
40
+ <% end %>
41
+
42
+ // Return current locale. If no locale has been set, then
43
+ // the current locale will be the default locale.
44
+ Chaltron.currentLocale = function() {
45
+ return this.locale || this.defaultLocale;
46
+ };
47
+
48
+ Chaltron.missingTranslation = function(scope, locale) {
49
+ return 'missing translation ' + scope + ' for ' + locale;
50
+ };
51
+
52
+ Chaltron.translate = function(scope, locale) {
53
+ locale = locale || Chaltron.currentLocale();
54
+ if (!isSet(Chaltron.locales[locale]) || !isSet(Chaltron.locales[locale][scope])) {
55
+ return Chaltron.missingTranslation(scope, locale);
56
+ }
57
+ return Chaltron.locales[locale][scope];
58
+ };
59
+
60
+ // Just return a value to define the module export.
61
+ return Chaltron;
62
+ }));
@@ -0,0 +1,69 @@
1
+ document.addEventListener('turbolinks:load', function(){
2
+ var defaultOptions = {
3
+ destroy: true,
4
+ autoWidth: false,
5
+ responsive: true,
6
+ stateSave: true,
7
+ language: Chaltron.translate('datatables')
8
+ };
9
+
10
+ // generic datatable
11
+ var container = $('table.datatable');
12
+ if (container.length > 0) {
13
+ var table = container.DataTable(defaultOptions);
14
+ document.addEventListener('turbolinks:before-cache', function() {
15
+ table.destroy();
16
+ });
17
+ }
18
+
19
+ // users
20
+ container = $('table#users');
21
+ if (container.length > 0) {
22
+ var user_table = container.DataTable(defaultOptions);
23
+ document.addEventListener('turbolinks:before-cache', function() {
24
+ user_table.destroy();
25
+ });
26
+ }
27
+
28
+ // logs
29
+ container = $('table#logs');
30
+ if (container.length > 0) {
31
+ var log_table = container.DataTable($.extend({}, defaultOptions, {
32
+ processing: true,
33
+ serverSide: true,
34
+ ajax: container.data('source'),
35
+ // default sorting: date (2nd column) desc
36
+ order: [[1,'desc']],
37
+ columns: [
38
+ { data: 'severity', searchable: false },
39
+ { data: 'date', searchable: false },
40
+ { data: 'message' },
41
+ { data: 'category', searchable: false },
42
+ ],
43
+ columnDefs: [
44
+ { orderSequence: ['desc', 'asc'], targets: [ 1 ] },
45
+ { className: 'text-center', 'targets': [ 0 ] }
46
+ ]
47
+ }));
48
+ document.addEventListener('turbolinks:before-cache', function() {
49
+ log_table.destroy();
50
+ });
51
+ }
52
+
53
+ // ldap_create
54
+ container = $('table#ldap_create');
55
+ if (container.length > 0) {
56
+ var ldap_create_table = container.DataTable($.extend({}, defaultOptions, {
57
+ paging: false,
58
+ // default sorting: uid (2nd column) asc
59
+ order: [[1,'asc']],
60
+ columnDefs: [
61
+ { orderable: false, className: 'select-checkbox', targets: 0 }
62
+ ]
63
+ }));
64
+ document.addEventListener('turbolinks:before-cache', function() {
65
+ ldap_create_table.destroy();
66
+ });
67
+ }
68
+
69
+ });
@@ -0,0 +1,14 @@
1
+ document.addEventListener('turbolinks:load', function(){
2
+
3
+ // flash messages
4
+ var flash = $('.flash-container div.alert');
5
+ if (flash.length > 0) {
6
+ flash.click(function(){
7
+ $(this).fadeOut();
8
+ });
9
+ setTimeout(function(){
10
+ flash.fadeOut();
11
+ }, 5000);
12
+ }
13
+
14
+ });
@@ -0,0 +1,44 @@
1
+ $(document).on('turbolinks:load', function() {
2
+ container = $('table#ldap_create');
3
+ if (container.length > 0) {
4
+
5
+ var toggleButton = function() {
6
+ var any = $('input.entry' + ':checkbox')
7
+ .filter(function() { return this.checked; })
8
+ .length > 0;
9
+ if (any) {
10
+ $('#ldap_create_button').prop('disabled', false);
11
+ } else {
12
+ $('#ldap_create_button').prop('disabled', true);
13
+ }
14
+ };
15
+ // checkboxes
16
+ $('input.entry' + ':checkbox:disabled').prop('indeterminate', true);
17
+ $('input.entry' + ':checkbox').off().on('click', function() {
18
+ toggleButton();
19
+ });
20
+ $('#entry-check-all').off().on('click', function() {
21
+ $('input.entry' + ':checkbox:enabled').prop('checked', this.checked);
22
+ toggleButton();
23
+ });
24
+
25
+ $('form#ldap_create').on('submit', function(event) {
26
+ var selectedEntry = $('input.entry' + ':checkbox:checked')
27
+ .map(function() { return $(this).attr('data-entry'); })
28
+ .get();
29
+ if(selectedEntry.lenght == 0) {
30
+ // should nevere be here!!
31
+ event.preventDefault();
32
+ } else {
33
+ $.each(selectedEntry, function(index, entry){
34
+ $('<input/>', {
35
+ name: 'uids[]',
36
+ type: 'hidden',
37
+ multiple: 'multiple',
38
+ value: entry
39
+ }).appendTo('form#ldap_create');
40
+ });
41
+ }
42
+ });
43
+ }
44
+ });
@@ -0,0 +1,25 @@
1
+ {
2
+ "datatables": {
3
+ "sEmptyTable": "No data available in table",
4
+ "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
5
+ "sInfoEmpty": "Showing 0 to 0 of 0 entries",
6
+ "sInfoFiltered": "(filtered from _MAX_ total entries)",
7
+ "sInfoPostFix": "",
8
+ "sInfoThousands": ",",
9
+ "sLengthMenu": "Show _MENU_ entries",
10
+ "sLoadingRecords": "Loading...",
11
+ "sProcessing": "Processing...",
12
+ "sSearch": "Search:",
13
+ "sZeroRecords": "No matching records found",
14
+ "oPaginate": {
15
+ "sFirst": "First",
16
+ "sLast": "Last",
17
+ "sNext": "Next",
18
+ "sPrevious": "Previous"
19
+ },
20
+ "oAria": {
21
+ "sSortAscending": ": activate to sort column ascending",
22
+ "sSortDescending": ": activate to sort column descending"
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "datatables": {
3
+ "sEmptyTable": "Nessun dato presente nella tabella",
4
+ "sInfo": "Vista da _START_ a _END_ di _TOTAL_ elementi",
5
+ "sInfoEmpty": "Vista da 0 a 0 di 0 elementi",
6
+ "sInfoFiltered": "(filtrati da _MAX_ elementi totali)",
7
+ "sInfoPostFix": "",
8
+ "sInfoThousands": ".",
9
+ "sLengthMenu": "Visualizza _MENU_ elementi",
10
+ "sLoadingRecords": "Caricamento...",
11
+ "sProcessing": "Elaborazione...",
12
+ "sSearch": "Cerca:",
13
+ "sZeroRecords": "La ricerca non ha portato alcun risultato.",
14
+ "oPaginate": {
15
+ "sFirst": "Inizio",
16
+ "sPrevious": "Precedente",
17
+ "sNext": "Successivo",
18
+ "sLast": "Fine"
19
+ },
20
+ "oAria": {
21
+ "sSortAscending": ": attiva per ordinare la colonna in ordine crescente",
22
+ "sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,86 @@
1
+ function NavbarBuilder() {
2
+
3
+ function renderDropdownMenu(item){
4
+ var i, ref;
5
+ ref = $(item).find('ul li a');
6
+ for(i = 0; i < ref.length; i++) {
7
+ $(ref[i]).addClass('dropdown-item').removeClass('nav-link');
8
+ }
9
+ ref = $(item).find('ul');
10
+ for(i = 0; i < ref.length; i++) {
11
+ renderDropdownLinks(ref[i]);
12
+ }
13
+ }
14
+
15
+ function renderDropdownLinks(item) {
16
+ var links = $(item).find('li a');
17
+ klass = 'dropdown-menu';
18
+ if($(item).parent().hasClass('dropdown-menu-right')) {
19
+ klass += ' dropdown-menu-right';
20
+ }
21
+ var div = $('<div></div>').addClass(klass).attr('aria-labelledby', 'navbarDropdown').append(links);
22
+ $(item).replaceWith(div);
23
+ }
24
+
25
+ function prependClass(item, klass) {
26
+ if($(item).attr('class') ) {
27
+ klass += ' ' + $(item).attr('class');
28
+ }
29
+ $(item).addClass(klass);
30
+ if($(item).hasClass('justify-content-end')) {
31
+ $(item).removeClass('mr-auto');
32
+ }
33
+ }
34
+
35
+ function renderIconLink(item) {
36
+ if($(item).attr('icon') ) {
37
+ $(item).html("<i class=\"fa fa-" + $(item).attr('icon') + "\"></i>&nbsp;" + $(item).text());
38
+ }
39
+ }
40
+
41
+ return {
42
+ create: function () {
43
+ // backup
44
+ $('#navigation').data('navbar', $('#navigation').html());
45
+
46
+ var i, ref;
47
+ ref = $('#navigation ul');
48
+ for(i = 0; i < ref.length; i++) {
49
+ prependClass(ref[i], 'navbar-nav mr-auto');
50
+ }
51
+ $('#navigation ul li').addClass('nav-item');
52
+ $('#navigation ul li a').addClass('nav-link');
53
+ $('#navigation ul li ul').parent().addClass('dropdown');
54
+ $('#navigation ul li.dropdown').children('a').addClass('dropdown-toggle').attr(
55
+ {id: 'navbarDropdown', role: 'button', 'aria-haspopup': 'true', 'aria-expanded': 'false', 'data-toggle': 'dropdown'}
56
+ );
57
+ ref = $('#navigation ul li.dropdown');
58
+ for(i = 0; i < ref.length; i++) {
59
+ renderDropdownMenu(ref[i]);
60
+ }
61
+ ref = $('#navigation ul li a');
62
+ for(i = 0; i < ref.length; i++) {
63
+ renderIconLink(ref[i]);
64
+ }
65
+ },
66
+ destroy: function () {
67
+ // restore
68
+ $('#navigation').html($('#navigation').data('navbar'));
69
+ }
70
+ };
71
+ }
72
+
73
+ document.addEventListener('turbolinks:load', function(){
74
+ var navbar = new NavbarBuilder();
75
+ navbar.create();
76
+ }, {once: true});
77
+
78
+ document.addEventListener('turbolinks:render', function(){
79
+ var navbar = new NavbarBuilder();
80
+ navbar.create();
81
+ });
82
+
83
+ document.addEventListener('turbolinks:before-render', function(){
84
+ var navbar = new NavbarBuilder();
85
+ navbar.destroy();
86
+ });
@@ -1,29 +1,2 @@
1
- // Bootstrap
2
- @import 'bootstrap';
3
-
4
- // font-awesome
5
- @import 'font-awesome-sprockets';
6
- @import 'font-awesome';
7
-
8
- // datatables
9
- @import 'datatables/dataTables.bootstrap4';
10
- @import 'datatables/extensions/Responsive/responsive.bootstrap4';
11
- @import 'datatables/extensions/Select/select.bootstrap4';
12
-
13
- // bootstrap_form
14
- @import 'rails_bootstrap_forms';
15
-
16
- // minor fix
17
- .dataTables_wrapper .dataTables_filter input {
18
- margin-left: 0.5em;
19
- }
20
-
21
- // nprogress
22
- @import 'nprogress';
23
- @import 'nprogress-bootstrap';
24
-
25
- // Core CSS
26
1
  @import 'chaltron/layout';
27
-
28
- // logs
29
2
  @import 'chaltron/logs';
@@ -3,7 +3,7 @@ require 'chaltron/ldap/user'
3
3
  module Chaltron
4
4
  class OmniauthCallbacksController < Devise::OmniauthCallbacksController
5
5
 
6
- default_log_category :login
6
+ default_log_category :login
7
7
 
8
8
  def ldap
9
9
  # puts '##########################################'
@@ -12,15 +12,12 @@ module Chaltron
12
12
  # We only find ourselves here
13
13
  # if the authentication to LDAP was successful.
14
14
  user = Chaltron::LDAP::User.find_or_create(oauth, Chaltron.ldap_allow_all)
15
- user = Chaltron.ldap_after_authenticate.call(user, Chaltron::LDAP::Connection.new)
16
15
  if user.nil?
17
- redirect_to root_url, alert: I18n.t('chaltron.not_allowed_to_sign_in')
16
+ redirect_to new_user_session_url, alert: I18n.t('chaltron.not_allowed_to_sign_in')
18
17
  else
19
18
  user.remember_me = params[:remember_me] if user.persisted?
20
- flash[:notice] = I18n.t('devise.sessions.signed_in')
21
-
22
- info I18n.t('chaltron.logs.login_via', user: user.display_name, provider: 'ldap')
23
- sign_in_and_redirect(user)
19
+ sign_in_and_redirect(user, event: :authentication)
20
+ set_flash_message(:notice, :success, kind: 'LDAP')
24
21
  end
25
22
  end
26
23
 
@@ -43,6 +43,16 @@ class Chaltron::UsersController < ApplicationController
43
43
  respond_with(@user)
44
44
  end
45
45
 
46
+ def enable
47
+ @user.enable!
48
+ redirect_to(@user)
49
+ end
50
+
51
+ def disable
52
+ @user.disable!
53
+ redirect_to(@user)
54
+ end
55
+
46
56
  def self_update
47
57
  user_params_with_pass = self_update_params.dup.to_h
48
58
  if params[:user][:password].present?
@@ -18,4 +18,13 @@ module Chaltron::LdapHelper
18
18
  end
19
19
  end
20
20
 
21
+ def custom_checkbox(options)
22
+ id = options.delete(:id)
23
+ klass = options.delete(:class)
24
+ content_tag :div, class: 'custom-control custom-checkbox' do
25
+ check_box_tag('checkbox', nil, nil, options.merge(id: id, class: "custom-control-input d-none #{klass}")) +
26
+ label_tag(id, '', class: 'custom-control-label d-block', for: id)
27
+ end
28
+ end
29
+
21
30
  end