chaltron 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5a8e03b4ed2bea1ef2bdd39e00edb3f71001142f4d58f9fad4f9acbbf27cfc7
4
- data.tar.gz: 44aa8e6409c252816a7f3bf2bacff397a9dfbc3f40b6c95b5ccc79c5f675044d
3
+ metadata.gz: c903358c42ce7e75e0ecae0e4f87b025e9909f769ec87c7644a02fa36cf8a948
4
+ data.tar.gz: 5cf855bce93ee306d909091109db3947c279ab284a00e96662b748b17fdb9a2c
5
5
  SHA512:
6
- metadata.gz: 673cf0c5e3c66a1d1d846fb8e2cbd131b59e0e4c5091648e34c3b0006e28a25113d752aa35b845cd637ad9cf5ee0910cdf245692d41eb745a2e499825ee9f2db
7
- data.tar.gz: 947026bc6ee89b70b1d41cfec36037fefd48ff2f0849e1da99e2b7e0c2068c647bd3c763a8ccf7e5ac261bfce401c4fd4495ef31eb948faafdb5ae036d58d962
6
+ metadata.gz: 6e272d644dd254dffb34be9997ce334fbd5ce76894c9315933cc8a0ac766c212eeba164c7deffdc93e87ef34e7bc9ae889ebcb249b5b3d99155cc5af6a1cc270
7
+ data.tar.gz: d5867fa6b7f3e3279db592afada65c3bb85d801a17f604e56c7c660d871e33edc5f0afe7ef3703bfbbaa95074a7223df8d8aca954531e9066da36793decfb943
@@ -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?
@@ -1,11 +1,16 @@
1
1
  module Chaltron::UsersHelper
2
- def display_username(user)
3
- if user == current_user
4
- link_to(user.username, user) + '&nbsp;'.html_safe +
5
- content_tag(:span, I18n.t('chaltron.users.it_s_you'), class: 'badge badge-success')
6
- else
7
- link_to user.username, user
8
- end
2
+ def display_username(user, link = true)
3
+ capture do
4
+ if link
5
+ concat link_to(user.username, user)
6
+ else
7
+ concat content_tag(:span, user.username)
8
+ end
9
+ concat content_tag(:span, I18n.t('chaltron.users.it_s_you'),
10
+ class: 'badge badge-success ml-2') if user == current_user
11
+ concat content_tag :span, t('.disabled'),
12
+ class: 'badge badge-danger ml-2' if user.disabled?
13
+ end
9
14
  end
10
15
 
11
16
  def display_side_filter_link(url, active, text, count)
@@ -30,4 +30,28 @@ class User < ApplicationRecord
30
30
  provider == 'ldap'
31
31
  end
32
32
 
33
+ def enabled?
34
+ self.enabled
35
+ end
36
+
37
+ def disabled?
38
+ !self.enabled
39
+ end
40
+
41
+ def enable!
42
+ update!(enabled: true)
43
+ end
44
+
45
+ def disable!
46
+ update!(enabled: false)
47
+ end
48
+
49
+ def active_for_authentication?
50
+ super && enabled?
51
+ end
52
+
53
+ def inactive_message
54
+ I18n.t('chaltron.users.inactive_message')
55
+ end
56
+
33
57
  end
@@ -8,7 +8,7 @@
8
8
  <ul class='list-group list-group-flush'>
9
9
  <li class='list-group-item'>
10
10
  <span><%= User.human_attribute_name(:username) %>: </span>
11
- <strong><%= @user.username %></strong>
11
+ <strong><%= display_username(@user, false) %></strong>
12
12
  </li>
13
13
  <li class='list-group-item'>
14
14
  <span><%= User.human_attribute_name(:fullname) %>: </span>
@@ -64,9 +64,20 @@
64
64
  <% end %>
65
65
 
66
66
  <div class='float-right'>
67
- <%= link_to edit_user_path(@user), class: 'btn btn-primary' do %>
68
- <%= icon :fas, :edit, t('.edit') %>
69
- <% end if can? :edit, @user %>
67
+ <% if can? :edit, @user %>
68
+ <%= link_to edit_user_path(@user), class: 'btn btn-primary' do %>
69
+ <%= icon :fas, :edit, t('.edit') %>
70
+ <% end %>
71
+ <% if @user.enabled? %>
72
+ <%= link_to disable_user_path(@user), class: 'btn btn-danger' do %>
73
+ <%= icon :fas, 'user-slash', t('.disable') %>
74
+ <% end %>
75
+ <% else %>
76
+ <%= link_to enable_user_path(@user), class: 'btn btn-primary' do %>
77
+ <%= icon :fas, :user, t('.enable') %>
78
+ <% end %>
79
+ <% end %>
80
+ <% end %>
70
81
  <%= link_to @user, method: :delete, class: 'btn btn-danger',
71
82
  disabled: current_user == @user,
72
83
  data: { confirm: t('.destroy_confirm', user: @user.username) } do %>
@@ -57,6 +57,8 @@ en:
57
57
  activity: Activity
58
58
  details: Details
59
59
  edit: Edit
60
+ enable: Abilita
61
+ disable: Disabilita
60
62
  destroy: Destroy
61
63
  destroy_confirm: Are you sure you want to destroy %{user}?
62
64
  self_show:
@@ -57,6 +57,8 @@ it:
57
57
  activity: Attività
58
58
  details: Dettagli
59
59
  edit: Modifica
60
+ enable: Abilita
61
+ disable: Disabilita
60
62
  destroy: Cancella
61
63
  destroy_confirm: Sei sicuro di voler cancellare %{user}?
62
64
  self_show:
@@ -0,0 +1,31 @@
1
+ require 'chaltron/ldap/user'
2
+
3
+ Warden::Manager.after_set_user do |record, warden, options|
4
+ # LDAP callback. Last check before authentication
5
+ if record && record.ldap_user? &&
6
+ Chaltron.ldap_after_authenticate.call(record, Chaltron::LDAP::Connection.new).nil?
7
+ scope = options[:scope]
8
+ warden.logout(scope)
9
+ throw :warden, scope: scope, message: I18n.t('chaltron.not_allowed_to_sign_in')
10
+ end
11
+ end
12
+
13
+ # Log after authentication
14
+ Warden::Manager.after_authentication do |user,auth,opts|
15
+ Log.create(
16
+ message: I18n.t('chaltron.logs.login', user: user.display_name),
17
+ category: :login,
18
+ severity: :info
19
+ ) if user
20
+ end
21
+
22
+ Warden::Manager.before_logout do |user,auth,opts|
23
+ # LDAP callback
24
+ Chaltron.ldap_before_logout.call(user, Chaltron::LDAP::Connection.new) if user.ldap_user?
25
+ # Log before logout
26
+ Log.create(
27
+ message: I18n.t('chaltron.logs.logout', user: user.display_name),
28
+ category: :login,
29
+ severity: :info
30
+ ) if user
31
+ end
@@ -23,8 +23,10 @@ en:
23
23
  self_updated: Account data successfully updated.
24
24
  cannot_self_destroy: You cannot destroy your own account.
25
25
  it_s_you: It's you!
26
+ disabled: Disabled
26
27
  missing_field: Missing!
27
28
  already_present: Already present!
29
+ inactive_message: Your account has been disabled.
28
30
  logs:
29
31
  severity:
30
32
  emerg: Emergency
@@ -40,7 +42,6 @@ en:
40
42
  user_admin: User administration
41
43
  login: "%{user} has logged in successfully"
42
44
  logout: "%{user} has logged out successfully"
43
- login_via: "%{user} has logged in successfully with %{provider}"
44
45
  users:
45
46
  created: "%{current} created user %{user}"
46
47
  destroyed: "%{current} destroyed user %{user}"
@@ -23,8 +23,10 @@ it:
23
23
  self_updated: Dati personali aggiornati con successo.
24
24
  cannot_self_destroy: Non puoi cancellare il tuo stesso account.
25
25
  it_s_you: Sei tu!
26
+ disabled: Disabilitato
26
27
  missing_field: Manca!
27
28
  already_present: Giá presente!
29
+ inactive_message: Il tuo account è stato disabilitato.
28
30
  logs:
29
31
  severity:
30
32
  emerg: Emergenza
@@ -40,7 +42,6 @@ it:
40
42
  user_admin: Amministrazione utenti
41
43
  login: "%{user} ha effettuato il login con successo"
42
44
  logout: "%{user} ha effettuato il logout con successo"
43
- login_via: "%{user} ha effettuato il login con successo via %{provider}"
44
45
  users:
45
46
  created: "%{current} ha creato l'utente %{user}"
46
47
  destroyed: "%{current} ha cancellato l'utente %{user}"
@@ -1,7 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  devise_for :users, controllers: {
3
- omniauth_callbacks: 'chaltron/omniauth_callbacks',
4
- sessions: 'chaltron/sessions'
3
+ omniauth_callbacks: 'chaltron/omniauth_callbacks'
5
4
  }
6
5
 
7
6
  resources :users, controller: 'chaltron/users' do
@@ -10,6 +9,10 @@ Rails.application.routes.draw do
10
9
  get 'self_edit'
11
10
  patch 'self_update'
12
11
  end
12
+ member do
13
+ get 'enable'
14
+ get 'disable'
15
+ end
13
16
  end
14
17
 
15
18
  resources :logs, controller: 'chaltron/logs', only: [:index, :show]
@@ -0,0 +1,5 @@
1
+ class AddEnabledToUsers < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :users, :enabled, :boolean, default: true
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Chaltron
2
- VERSION = '1.1.6'.freeze
2
+ VERSION = '1.1.7'.freeze
3
3
  end
@@ -0,0 +1 @@
1
+ webpacker: ./bin/webpack-dev-server
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaltron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - vicvega
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-05 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: omniauth-rails_csrf_protection
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: gitlab_omniauth-ldap
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -397,7 +411,6 @@ files:
397
411
  - app/controllers/chaltron/ldap_controller.rb
398
412
  - app/controllers/chaltron/logs_controller.rb
399
413
  - app/controllers/chaltron/omniauth_callbacks_controller.rb
400
- - app/controllers/chaltron/sessions_controller.rb
401
414
  - app/controllers/chaltron/users_controller.rb
402
415
  - app/datatables/log_datatable.rb
403
416
  - app/helpers/chaltron/ldap_helper.rb
@@ -435,6 +448,7 @@ files:
435
448
  - app/views/locales/it.yml
436
449
  - config/chaltron_navigation.rb
437
450
  - config/initializers/devise.rb
451
+ - config/initializers/warden.rb
438
452
  - config/locales/devise.en.yml
439
453
  - config/locales/devise.it.yml
440
454
  - config/locales/en.yml
@@ -446,6 +460,7 @@ files:
446
460
  - db/migrate/20140909115653_add_roles_mask_to_users.rb
447
461
  - db/migrate/20141205095036_add_additional_ldap_info_to_user.rb
448
462
  - db/migrate/20150127174621_create_logs.rb
463
+ - db/migrate/20200414150601_add_enabled_to_users.rb
449
464
  - lib/chaltron.rb
450
465
  - lib/chaltron/banner.rb
451
466
  - lib/chaltron/bootstrap_form.rb
@@ -455,6 +470,7 @@ files:
455
470
  - lib/chaltron/ldap/person.rb
456
471
  - lib/chaltron/ldap/user.rb
457
472
  - lib/chaltron/version.rb
473
+ - lib/generators/chaltron/install/templates/Procfile
458
474
  - lib/generators/chaltron/install_generator.rb
459
475
  - lib/generators/chaltron/templates/app/assets/images/700x300.gif
460
476
  - lib/generators/chaltron/templates/app/assets/images/favicon.ico
@@ -1,17 +0,0 @@
1
- require 'chaltron/ldap/connection'
2
-
3
- class Chaltron::SessionsController < Devise::SessionsController
4
- after_action :after_login, only: :create
5
- before_action :before_logout, only: :destroy
6
-
7
- default_log_category :login
8
-
9
- def after_login
10
- info I18n.t('chaltron.logs.login', user: current_user.display_name)
11
- end
12
-
13
- def before_logout
14
- Chaltron.ldap_before_logout.call(current_user, Chaltron::LDAP::Connection.new) if current_user.ldap_user?
15
- info I18n.t('chaltron.logs.logout', user: current_user.display_name)
16
- end
17
- end