egov_utils 0.1.37 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/egov_utils/groups_controller.rb +21 -1
  3. data/app/controllers/egov_utils/passwords_controller.rb +34 -0
  4. data/app/controllers/egov_utils/sessions_controller.rb +1 -0
  5. data/app/controllers/egov_utils/users_controller.rb +5 -1
  6. data/app/helpers/egov_utils/groups_helper.rb +9 -0
  7. data/app/mailers/egov_utils/user_mailer.rb +11 -0
  8. data/app/models/egov_utils/group.rb +7 -0
  9. data/app/models/egov_utils/user.rb +53 -2
  10. data/app/views/common/modal_action.js.erb +1 -0
  11. data/app/views/egov_utils/groups/_form.html.haml +1 -0
  12. data/app/views/egov_utils/groups/_groups_tab.html.haml +6 -1
  13. data/app/views/egov_utils/groups/new_users.html.haml +8 -0
  14. data/app/views/egov_utils/groups/show.html.haml +8 -0
  15. data/app/views/egov_utils/passwords/edit.html.haml +6 -0
  16. data/app/views/egov_utils/passwords/new.html.haml +0 -0
  17. data/app/views/egov_utils/user_mailer/account_information.html.erb +12 -0
  18. data/app/views/egov_utils/user_mailer/account_information.text.erb +8 -0
  19. data/app/views/egov_utils/user_mailer/confirmation_email.html.erb +3 -7
  20. data/app/views/egov_utils/user_mailer/password_change_info.html.erb +3 -0
  21. data/app/views/egov_utils/user_mailer/password_change_info.text.erb +1 -0
  22. data/app/views/egov_utils/users/_form.html.haml +24 -6
  23. data/app/views/egov_utils/users/_users_tab.html.haml +6 -2
  24. data/app/views/egov_utils/users/index.html.haml +1 -1
  25. data/app/views/layouts/egov_utils/mailer.html.erb +6 -0
  26. data/app/views/layouts/egov_utils/mailer.text.erb +6 -0
  27. data/config/locales/cs.yml +23 -0
  28. data/config/routes.rb +8 -1
  29. data/db/migrate/20180125133500_add_password_generation_to_egov_utils_users.rb +6 -0
  30. data/db/migrate/20180126131416_create_egov_utils_groups_users.rb +8 -0
  31. data/lib/bootstrap_form/datetimepicker.rb +1 -1
  32. data/lib/bootstrap_form/helpers/bootstrap4.rb +0 -1
  33. data/lib/egov_utils/engine.rb +6 -6
  34. data/lib/egov_utils/user_utils/application_controller_patch.rb +19 -1
  35. data/lib/egov_utils/version.rb +1 -1
  36. metadata +17 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e8d0fbd9213c1a72766c4051bd1ae95a113d37dabe8fbec63e6c99c7cb375b6
4
- data.tar.gz: 0b1ab4b993e1b0ebfa4abc19a15af8080771e9b55e6561a07b627dc0c180f90f
3
+ metadata.gz: 1eee02ae4029cc5582c5e991adb3010ffb6e7a5087c98b4561f20ec62b7100de
4
+ data.tar.gz: 62cec3d7e6153323f0b9599fc58b44fae8ef4d8c13f5550ca9a096bf380370e6
5
5
  SHA512:
6
- metadata.gz: c1b649500df057474548fee95ec35bfc87062c89322b2bc220a2165b1722428c503df8c36e4ecb80ee556e4d84fc4dda9fac0feadb8a84dd6848a6b7c442621b
7
- data.tar.gz: f6ae27ac1abbab33ec27387dcfa769c4b2a9bf198b9cf12be4b20017719996f3a8c5e453d71f1c8ef4c1265deb0cc2d998572d688e7e9996922198acf328954f
6
+ metadata.gz: 0faa5cb9e202f159c1305da4566e50a298ad4d886a9f3079f895651249b1aa968574a17d5bc12666102defd0dcdd2f875f9ded7d0796b64e2e31e84352c10fc3
7
+ data.tar.gz: 63c5ad465bec8724b8c240d05d5363dbcf13fb0105448eb342934ab38ae7af90aedfdd33c5f7a8326c3ffb0a50f0db6b5375f1bf2fdd60a0856fa627e5f67088
@@ -9,10 +9,13 @@ module EgovUtils
9
9
  @groups = EgovUtils::Group.accessible_by(current_ability)
10
10
  end
11
11
 
12
+ def show
13
+ end
14
+
12
15
  def create
13
16
  respond_to do |format|
14
17
  if @group.save
15
- format.html{ redirect_to main_app.root_path, notice: t('success_created') }
18
+ format.html{ redirect_to egov_utils.users_path, notice: t('success_created') }
16
19
  format.json{ render json: @group, status: :created }
17
20
  else
18
21
  format.html{ render 'new' }
@@ -21,6 +24,23 @@ module EgovUtils
21
24
  end
22
25
  end
23
26
 
27
+ def new_users
28
+ @principals = EgovUtils::User.active.not_in_group(@group)
29
+ respond_to do |format|
30
+ format.html
31
+ format.js { render_modal_js }
32
+ end
33
+ end
34
+
35
+ def add_users
36
+ @users = User.not_in_group(@group).where(:id => (params[:user_id] || params[:user_ids])).to_a
37
+ @group.users << @users
38
+ respond_to do |format|
39
+ format.html { redirect_to group_path(@group) }
40
+ format.json { head :ok }
41
+ end
42
+ end
43
+
24
44
  private
25
45
 
26
46
  def create_params
@@ -0,0 +1,34 @@
1
+ require_dependency "egov_utils/application_controller"
2
+
3
+ module EgovUtils
4
+ class PasswordsController < ApplicationController
5
+
6
+ skip_before_action :check_password_change
7
+
8
+ def edit
9
+ @user = current_user
10
+ end
11
+
12
+ def update
13
+ @user = current_user
14
+ if @user.password_change_possible? && @user.password_check?(params[:password_change][:current_password])
15
+ @user.attributes = password_change_params
16
+ @user.must_change_password = false
17
+ end
18
+ if @user.save
19
+ flash[:notice] = t(:notice_password_changed)
20
+ redirect_to main_app.root_path
21
+ else
22
+ flash[:warning] = t(:warning_password_not_changed)
23
+ redirect_to edit_password_path(@user)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def password_change_params
30
+ params.require(:password_change).permit(:password, :password_confirmation)
31
+ end
32
+
33
+ end
34
+ end
@@ -3,6 +3,7 @@ module EgovUtils
3
3
 
4
4
  skip_before_action :verify_authenticity_token, only: [:create]
5
5
  skip_before_action :require_login, only: [:new, :create]
6
+ skip_before_action :check_password_change, only: [:destroy]
6
7
 
7
8
  def new
8
9
  if current_user.logged?
@@ -13,6 +13,7 @@ module EgovUtils
13
13
  providers
14
14
  @users = EgovUtils::User.accessible_by(current_ability).order(:provider)
15
15
  @groups = EgovUtils::Group.accessible_by(current_ability).order(:provider)
16
+ @new_user = EgovUtils::User.new(generate_password: true)
16
17
  end
17
18
 
18
19
  def new
@@ -28,6 +29,7 @@ module EgovUtils
28
29
  UserMailer.confirmation_email(@user).deliver_later
29
30
  flash[:notice] = t('notice_signeup_with_mail')
30
31
  else
32
+ UserMailer.account_information(@user, @user.password).deliver_later if @user.auth_source.nil?
31
33
  flash[:notice] = t('activerecord.successful.messages.created', model: User.model_name.human)
32
34
  end
33
35
  format.html{ redirect_to main_app.root_path }
@@ -84,7 +86,9 @@ module EgovUtils
84
86
  end
85
87
 
86
88
  def create_params
87
- params.require(:user).permit(:login, :mail, :password, :password_confirmation, :provider, :firstname, :lastname)
89
+ params_to_permit = [:login, :mail, :password, :password_confirmation, :provider, :firstname, :lastname]
90
+ params_to_permit << :generate_password if current_user.logged?
91
+ params.require(:user).permit(*params_to_permit)
88
92
  end
89
93
  end
90
94
  end
@@ -1,4 +1,13 @@
1
1
  module EgovUtils
2
2
  module GroupsHelper
3
+
4
+ def principals_check_box_tags(name, principals)
5
+ s = ''
6
+ principals.each do |principal|
7
+ s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n"
8
+ end
9
+ s.html_safe
10
+ end
11
+
3
12
  end
4
13
  end
@@ -6,5 +6,16 @@ module EgovUtils
6
6
  mail(to: user.mail, subject: t(:app_name))
7
7
  end
8
8
 
9
+ def account_information(user, password)
10
+ @user = user
11
+ @password = password
12
+ mail(to: user.mail, subject: t(:app_name))
13
+ end
14
+
15
+ def password_change_info(user)
16
+ @user = user
17
+ mail(to: user.mail, subject: t(:app_name))
18
+ end
19
+
9
20
  end
10
21
  end
@@ -1,6 +1,9 @@
1
1
  require_dependency 'egov_utils/auth_source'
2
2
  module EgovUtils
3
3
  class Group < Principal
4
+
5
+ has_and_belongs_to_many :users
6
+
4
7
  validates :name, presence: true, uniqueness: true
5
8
  validates :ldap_uid, uniqueness: true, allow_nil: true
6
9
 
@@ -8,6 +11,10 @@ module EgovUtils
8
11
  EgovUtils::Organization.where(domain: domains)
9
12
  end
10
13
 
14
+ def allow_member_assign?
15
+ provider.nil?
16
+ end
17
+
11
18
  def members
12
19
 
13
20
  end
@@ -4,22 +4,39 @@ require 'request_store_rails'
4
4
  module EgovUtils
5
5
  class User < Principal
6
6
 
7
+ has_and_belongs_to_many :groups
8
+
7
9
  serialize :roles, Array
8
10
 
9
11
  has_secure_password validations: false
10
12
 
11
13
  validates_confirmation_of :password, if: lambda { |m| m.password.present? }
12
14
  validates_presence_of :password, on: :create, unless: :provider?
15
+ validates_presence_of :password_confirmation, if: lambda { |m| m.password.present? }
13
16
  validates :login, uniqueness: true
14
17
 
15
18
  before_validation :generate_confirmation_code, unless: :provider?
19
+ before_validation :generate_password_if_needed
16
20
 
17
- scope :active, -> { where(active: true) }
21
+ scope :active, -> { where(active: true) }
18
22
  scope :inactive, -> { where(active: false) }
19
23
 
24
+ scope :in_group, ->(group){
25
+ group_id = group.is_a?(EgovUtils::Group) ? group.id : group.to_i
26
+ at = Arel::Table.new('egov_utils_groups_users', as: 'gu')
27
+ where( arel_table[:id].in( at.project(at[:user_id]).where(at[:group_id].eq(group_id)) ) )
28
+ }
29
+ scope :not_in_group, ->(group){
30
+ group_id = group.is_a?(EgovUtils::Group) ? group.id : group.to_i
31
+ at = Arel::Table.new('egov_utils_groups_users', as: 'gu')
32
+ where(arel_table[:id].not_in( at.project(at[:user_id]).where(at[:group_id].eq(group_id)) ))
33
+ }
34
+
20
35
  cattr_accessor :default_role
21
36
  self.default_role = nil
22
37
 
38
+ attribute :generate_password, :boolean, default: false
39
+
23
40
  def self.authenticate(login, password, active_only=true)
24
41
  login = login.to_s
25
42
  password = password.to_s
@@ -61,6 +78,10 @@ module EgovUtils
61
78
  RequestLocals.fetch(:current_user) { User.anonymous }
62
79
  end
63
80
 
81
+ def to_s
82
+ fullname
83
+ end
84
+
64
85
  def roles
65
86
  logged? ? super : ['anonymous']
66
87
  end
@@ -77,6 +98,10 @@ module EgovUtils
77
98
  end
78
99
  end
79
100
 
101
+ def password_change_possible?
102
+ !provider.present?
103
+ end
104
+
80
105
  def logged?
81
106
  persisted?
82
107
  end
@@ -110,7 +135,7 @@ module EgovUtils
110
135
  end
111
136
 
112
137
  def groups
113
- ldap_groups || []
138
+ super.to_a.concat( Array.wrap(ldap_groups) )
114
139
  end
115
140
 
116
141
  def ldap_dn
@@ -130,11 +155,37 @@ module EgovUtils
130
155
  end
131
156
  end
132
157
 
158
+ def must_change_password?
159
+ (super || password_expired?) && !provider?
160
+ end
161
+
162
+ def password_expired?
163
+ false
164
+ end
165
+
133
166
  private
134
167
 
135
168
  def generate_confirmation_code
136
169
  self.confirmation_code ||= SecureRandom.hex
137
170
  end
138
171
 
172
+ def generate_password_if_needed
173
+ if generate_password? && !provider?
174
+ set_random_password(10)
175
+ end
176
+ end
177
+
178
+ def set_random_password(length=40)
179
+ chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
180
+ chars -= %w(0 O 1 l)
181
+ password = ''
182
+ length.times {|i| password << chars[SecureRandom.random_number(chars.size)] }
183
+ self.password = password
184
+ self.password_confirmation = password
185
+ self.must_change_password = true
186
+ self.password_changed_at = Time.now
187
+ self
188
+ end
189
+
139
190
  end
140
191
  end
@@ -0,0 +1 @@
1
+ eGovUtilities.showModal('<%= j render template: "#{@partial_scope}/#{@action}.html" %>')
@@ -0,0 +1 @@
1
+ = form.text_field(:name)
@@ -1,3 +1,8 @@
1
+ = bootstrap_form_for(EgovUtils::Group.new) do |f|
2
+ = render 'egov_utils/groups/form', form: f
3
+ .form-actions
4
+ = f.submit
5
+
1
6
  %table#groups.table
2
7
  %thead
3
8
  %tr
@@ -7,7 +12,7 @@
7
12
  %tbody
8
13
  - groups.each do |group|
9
14
  %tr
10
- %td= group.name
15
+ %td= link_to(group.name, group)
11
16
  %td= group.provider
12
17
  - if can?(:manage, group)
13
18
  %td.roles{data: {roles: group.roles, id: group.id}}= group.roles.join(', ')
@@ -0,0 +1,8 @@
1
+ %h2= t('common_labels.new_record', model: EgovUtils::User.model_name.human)
2
+
3
+ = bootstrap_form_for(@group, url: users_group_path(@group), method: :post) do |f|
4
+ .objects-selection
5
+ #new_group_users
6
+ = principals_check_box_tags('user_ids[]', @principals)
7
+ .form-actions
8
+ = f.submit t('button_add')
@@ -0,0 +1,8 @@
1
+ %h2= @group.name
2
+
3
+ = link_to(new_users_group_path(@group), remote: true) do
4
+ %i.fa.fa-plus-circle{'aria-hidden' => 'true'}
5
+ = t('label_add_group_member')
6
+ %ul
7
+ - @group.users.each do |user|
8
+ %li= user.fullname
@@ -0,0 +1,6 @@
1
+ = bootstrap_form_for(:password_change, url: password_path, method: :patch) do |f|
2
+ = f.password_field(:current_password)
3
+ = f.password_field(:password)
4
+ = f.password_field(:password_confirmation)
5
+ .form-actions
6
+ = f.submit
@@ -0,0 +1,12 @@
1
+ <p>
2
+ v aplikaci <%= t(:app_name) %> Vám byl vytvořen přístup.
3
+ Vaše přístupové údaje jsou:
4
+ </p>
5
+ <ul>
6
+ <li>login: <%= @user.login %></li>
7
+ <li>heslo: <%= @password %></li>
8
+ </ul>
9
+
10
+ <p>
11
+ Po prvním přihlášení budete vyzváni ke změně hesla.
12
+ </p>
@@ -0,0 +1,8 @@
1
+ v aplikaci <%= t(:app_name) %> Vám byl vytvořen přístup.
2
+
3
+ Vaše přístupové údaje jsou:
4
+
5
+ login: <%= @user.login %>
6
+ heslo: <%= @password %>
7
+
8
+ Po prvním přihlášení budete vyzváni ke změně hesla.
@@ -1,7 +1,3 @@
1
- Dobrý den,<br />
2
- <br />
3
- vítejte v aplikaci <%= t(:app_name) %>, pro aktivaci vašeho účtu klikněte prosím <%= link_to 'sem', confirm_user_url(@user.confirmation_code) %>.<br />
4
- <br />
5
- S pozdravem<br />
6
- Ministerstvo spravedlnosti<br />
7
- Odbor Informatiky
1
+ <p>
2
+ vítejte v aplikaci <%= t(:app_name) %>, pro aktivaci vašeho účtu klikněte prosím <%= link_to 'sem', confirm_user_url(@user.confirmation_code) %>.
3
+ </p>
@@ -0,0 +1,3 @@
1
+ <p>
2
+ Vaše heslo bylo právě změněno, pokud jste změnu neprovedl/a Vy, prosím kontaktujte podporu aplikace.
3
+ </p>
@@ -0,0 +1 @@
1
+ Vaše heslo bylo právě změněno, pokud jste změnu neprovedl/a Vy, prosím kontaktujte podporu aplikace.
@@ -1,6 +1,24 @@
1
- = form.text_field :login
2
- /= form.text_field :mail
3
- = form.password_field :password
4
- = form.password_field :password_confirmation
5
- = form.text_field :firstname
6
- = form.text_field :lastname
1
+ - box_id = "user_#{form.object.id || 'new'}"
2
+ %div{id: box_id}
3
+ = form.text_field :login
4
+ /= form.text_field :mail
5
+ - if current_user.logged?
6
+ = form.check_box :generate_password, class: 'generate_password'
7
+ .passwords
8
+ = form.password_field :password
9
+ = form.password_field :password_confirmation
10
+ = form.text_field :firstname
11
+ = form.text_field :lastname
12
+
13
+ :javascript
14
+ $(function(){
15
+ function toggle_paswords(state){
16
+ var $passwd = $('##{box_id} .passwords');
17
+ $passwd.find(':input').prop('disabled', !state);
18
+ $passwd.toggle(state);
19
+ }
20
+
21
+ var $generate_check = $('##{box_id} .generate_password');
22
+ toggle_paswords(!$generate_check.is(':checked'))
23
+ $generate_check.on('change', function(evt){ toggle_paswords(!$(this).is(':checked')) });
24
+ });
@@ -2,8 +2,9 @@
2
2
  %thead
3
3
  %tr
4
4
  %th= t('model_attributes.user.fullname')
5
- %th= EgovUtils::User.human_attribute_name('roles')
6
5
  %th= EgovUtils::User.human_attribute_name('provider')
6
+ %th= EgovUtils::User.human_attribute_name('roles')
7
+ %th= EgovUtils::User.human_attribute_name('groups')
7
8
  %th= t('label_actions')
8
9
  %tbody
9
10
  - users.each do |user|
@@ -13,7 +14,10 @@
13
14
  - if can?(:manage, user)
14
15
  %td.roles{data: {roles: user.roles, id: user.id}}= user.roles.join(', ')
15
16
  - else
16
- %td
17
+ %td= user.roles.join(', ')
18
+ %td
19
+ - user.groups.each do |g|
20
+ %span= g.name
17
21
  %td
18
22
  = button_to(t('label_delete'), user_path(user), method: :delete, class: 'btn btn-warning btn-sm')
19
23
  - unless user.active?
@@ -20,7 +20,7 @@
20
20
  = render 'egov_utils/users/ldap_search'
21
21
  #create.tab-pane.fade{role: 'tabpanel', 'aria-labelledby'=>'create_tab'}
22
22
  %h3= t('label_new')
23
- = bootstrap_form_for(EgovUtils::User.new) do |f|
23
+ = bootstrap_form_for(@new_user) do |f|
24
24
  = render 'egov_utils/users/form', form: f
25
25
  .form-actions
26
26
  = f.submit
@@ -8,6 +8,12 @@
8
8
  </head>
9
9
 
10
10
  <body>
11
+ Dobrý den,<br />
12
+ <br />
11
13
  <%= yield %>
14
+ <br />
15
+ S pozdravem<br />
16
+ Ministerstvo spravedlnosti<br />
17
+ Odbor Informatiky
12
18
  </body>
13
19
  </html>
@@ -1 +1,7 @@
1
+ Dobrý den,
2
+
1
3
  <%= yield %>
4
+
5
+ S pozdravem
6
+ Ministerstvo spravedlnosti
7
+ Odbor Informatiky
@@ -13,6 +13,8 @@ cs:
13
13
  cookies_text: K ukládání nastavení a správnému fungování využíváme soubory cookies. Používáním webu s jejich používáním souhlasíte.
14
14
  ok: Rozumím
15
15
 
16
+ button_add: Přidat
17
+
16
18
  ministery_justice_name: Ministerstvo spravedlnosti ČR
17
19
  label_no_records: Žádné záznamy k zobrazení
18
20
 
@@ -22,7 +24,10 @@ cs:
22
24
  notice_account_locked: Váš účet byl uzamčen správcem aplikace
23
25
  notice_logout: Byl/a jste úspěšně odhlášen/a
24
26
  notice_signeup_with_mail: Registrace proběhla úspěšně, byl Vám odeslán potvrzovací e-mail, prosím zkontrolujte svou poštu.
27
+ notice_password_changed: Vaše heslo bylo úspěšně změněno
25
28
  success_user_confirm: Váše e-mailová adresa byla potvrzena. Nyní se již můžete přihlásit.
29
+ error_password_expired: Platnost vašeho hesla vypršela. Prosím změňte ho.
30
+ warning_password_not_changed: Heslo nebylo změněno, zadali jste všechna hesla správně?
26
31
 
27
32
  label_approve: Schválit
28
33
  label_new: Nový
@@ -37,6 +42,7 @@ cs:
37
42
  label_search: Vyhledat
38
43
  label_delete: Smazat
39
44
  label_actions: Akce
45
+ label_add_group_member: Přidat uživatele
40
46
 
41
47
  text_born_on_at: "Narozen %{date} v %{place}"
42
48
 
@@ -65,6 +71,7 @@ cs:
65
71
  lastname: Příjmení
66
72
  fullname: Jméno a příjmení
67
73
  roles: Role
74
+ generate_password: Generovat heslo
68
75
  egov_utils/group:
69
76
  roles: Role
70
77
  egov_utils/address:
@@ -91,6 +98,10 @@ cs:
91
98
  profile:
92
99
  too_many_authors: Příliš mnoho autorů
93
100
 
101
+ model_help_messages: &my_help_messages
102
+ egov_utils/user:
103
+ generate_password: Heslo bude vygenerováno a posláno uživateli na e-mail, při prvním přihlášení bude heslo muset změnit.
104
+
94
105
 
95
106
  labels: &my_labels
96
107
  user:
@@ -98,12 +109,22 @@ cs:
98
109
  session:
99
110
  username: Přihlašovací jméno
100
111
  password: Heslo
112
+ password_change:
113
+ current_password: Současné heslo
114
+ password: Heslo
115
+ password_confirmation: Potvrzení hesla
116
+
117
+ submits: &my_submits
118
+ password_change:
119
+ submit: Změnit heslo
101
120
 
102
121
  activerecord:
103
122
  models:
104
123
  <<: *my_models
105
124
  attributes:
106
125
  <<: *my_attributes
126
+ help:
127
+ <<: *my_help_messages
107
128
  errors:
108
129
  models:
109
130
  <<: *my_model_errors
@@ -121,6 +142,8 @@ cs:
121
142
  helpers:
122
143
  label:
123
144
  <<: *my_labels
145
+ submit:
146
+ <<: *my_submits
124
147
 
125
148
 
126
149
  errors:
@@ -14,9 +14,16 @@ EgovUtils::Engine.routes.draw do
14
14
 
15
15
  resources :people
16
16
 
17
- resources :groups
17
+ resources :groups do
18
+ member do
19
+ get '/users/new', to: 'groups#new_users', as: 'new_users'
20
+ post '/users', to: 'groups#add_users', as: 'users'
21
+ end
22
+ end
18
23
  resources :roles
19
24
 
25
+ resources :passwords
26
+
20
27
  # post '/auth/:provider/callback', to: 'sessions#create'
21
28
 
22
29
  get '/address/validate_ruian' => 'addresses#validate_ruian', as: :validate_ruian
@@ -0,0 +1,6 @@
1
+ class AddPasswordGenerationToEgovUtilsUsers < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :egov_utils_users, :must_change_password, :boolean
4
+ add_column :egov_utils_users, :password_changed_at, :datetime
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class CreateEgovUtilsGroupsUsers < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :egov_utils_groups_users do |t|
4
+ t.references :group, foreign_key: {to_table: :egov_utils_groups}
5
+ t.references :user, foreign_key: {to_table: :egov_utils_users}
6
+ end
7
+ end
8
+ end
@@ -31,7 +31,7 @@ module BootstrapForm
31
31
  private
32
32
 
33
33
  def calendar_addon
34
- content_tag('i', '', class: 'fa fa-calendar')
34
+ content_tag('i', '', class: 'input-group-text fa fa-calendar')
35
35
  end
36
36
  end
37
37
  end
@@ -4,7 +4,6 @@ module BootstrapForm
4
4
 
5
5
  def submit(name = nil, options = {})
6
6
  options.reverse_merge! class: 'btn btn-secondary'
7
- pp options
8
7
  super(name, options)
9
8
  end
10
9
 
@@ -42,10 +42,10 @@ module EgovUtils
42
42
  ActiveSupport::Reloader.to_prepare do
43
43
  AzaharaSchema::Outputs.register(Grid::ShieldGrid)
44
44
  end
45
- ActiveSupport.on_load(:action_controller) do
46
- ::ActionController::Base.helper EgovUtils::ApplicationHelper
47
- ::ActionController::Base.helper EgovUtils::GridHelper
48
- ::ActionController::Base.helper EgovUtils::EnumHelper
45
+ ActiveSupport.on_load(:action_controller_base) do
46
+ helper EgovUtils::ApplicationHelper
47
+ helper EgovUtils::GridHelper
48
+ helper EgovUtils::EnumHelper
49
49
  end
50
50
  end
51
51
 
@@ -59,9 +59,9 @@ module EgovUtils
59
59
  initializer 'egov_utils.user_setup' do
60
60
  require 'egov_utils/user_utils/role'
61
61
  require_dependency 'ability'
62
- ActiveSupport.on_load(:action_controller) do
62
+ ActiveSupport.on_load(:action_controller_base) do
63
63
  require 'egov_utils/user_utils/application_controller_patch'
64
- ::ActionController::Base.include EgovUtils::UserUtils::ApplicationControllerPatch
64
+ include EgovUtils::UserUtils::ApplicationControllerPatch
65
65
  end
66
66
  # require 'omniauth'
67
67
  # require 'omniauth-kerberos'
@@ -7,7 +7,7 @@ module EgovUtils
7
7
  included do
8
8
 
9
9
  before_action :user_setup, :set_locale
10
- before_action :require_login
10
+ before_action :require_login, :check_password_change
11
11
 
12
12
  rescue_from CanCan::AccessDenied do |exception|
13
13
  respond_to do |format|
@@ -44,6 +44,12 @@ module EgovUtils
44
44
  end
45
45
  end
46
46
 
47
+ def render_modal_js(**options)
48
+ @partial_scope = options[:scope] || params[:controller]
49
+ @action = options[:action] || params[:action]
50
+ render 'common/modal_action'
51
+ end
52
+
47
53
  protected
48
54
  def find_current_user
49
55
  # existing session
@@ -114,6 +120,18 @@ module EgovUtils
114
120
  true
115
121
  end
116
122
 
123
+ def check_password_change
124
+ if current_user.logged? && current_user.must_change_password?
125
+ respond_to do |format|
126
+ format.html {
127
+ flash[:error] = t(:error_password_expired)
128
+ redirect_to egov_utils.edit_password_path(current_user)
129
+ }
130
+ format.json { render json: { error: t(:error_password_expired) }, status: :unauthorized }
131
+ end
132
+ end
133
+ end
134
+
117
135
  def require_login?
118
136
  false
119
137
  end
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.37'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.37
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-05 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -282,14 +282,14 @@ dependencies:
282
282
  requirements:
283
283
  - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: '0.1'
285
+ version: '0.2'
286
286
  type: :runtime
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
- version: '0.1'
292
+ version: '0.2'
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: egon_gate
295
295
  requirement: !ruby/object:Gem::Requirement
@@ -365,6 +365,7 @@ files:
365
365
  - app/controllers/egov_utils/application_controller.rb
366
366
  - app/controllers/egov_utils/groups_controller.rb
367
367
  - app/controllers/egov_utils/organizations_controller.rb
368
+ - app/controllers/egov_utils/passwords_controller.rb
368
369
  - app/controllers/egov_utils/people_controller.rb
369
370
  - app/controllers/egov_utils/roles_controller.rb
370
371
  - app/controllers/egov_utils/sessions_controller.rb
@@ -399,14 +400,24 @@ files:
399
400
  - app/views/azahara_schema/outputs/_grid.html.haml
400
401
  - app/views/common/_grid.html.coffee
401
402
  - app/views/common/_modal.html.haml
403
+ - app/views/common/modal_action.js.erb
402
404
  - app/views/egov_utils/addresses/_form.html.haml
405
+ - app/views/egov_utils/groups/_form.html.haml
403
406
  - app/views/egov_utils/groups/_groups_tab.html.haml
404
407
  - app/views/egov_utils/groups/index.html.haml
408
+ - app/views/egov_utils/groups/new_users.html.haml
409
+ - app/views/egov_utils/groups/show.html.haml
410
+ - app/views/egov_utils/passwords/edit.html.haml
411
+ - app/views/egov_utils/passwords/new.html.haml
405
412
  - app/views/egov_utils/people/_form.html.haml
406
413
  - app/views/egov_utils/roles/index.html.haml
407
414
  - app/views/egov_utils/sessions/new.html.haml
415
+ - app/views/egov_utils/user_mailer/account_information.html.erb
416
+ - app/views/egov_utils/user_mailer/account_information.text.erb
408
417
  - app/views/egov_utils/user_mailer/confirmation_email.html.erb
409
418
  - app/views/egov_utils/user_mailer/confirmation_email.text.erb
419
+ - app/views/egov_utils/user_mailer/password_change_info.html.erb
420
+ - app/views/egov_utils/user_mailer/password_change_info.text.erb
410
421
  - app/views/egov_utils/users/_form.html.haml
411
422
  - app/views/egov_utils/users/_ldap_search.html.haml
412
423
  - app/views/egov_utils/users/_users_tab.html.haml
@@ -433,6 +444,8 @@ files:
433
444
  - db/migrate/20171103141234_add_birth_place_and_residence_to_people.rb
434
445
  - db/migrate/20171109172909_add_external_uid_to_groups.rb
435
446
  - db/migrate/20171115142450_add_confirmation_code_to_users.rb
447
+ - db/migrate/20180125133500_add_password_generation_to_egov_utils_users.rb
448
+ - db/migrate/20180126131416_create_egov_utils_groups_users.rb
436
449
  - lib/bootstrap_form/check_box_patch.rb
437
450
  - lib/bootstrap_form/custom_file_field.rb
438
451
  - lib/bootstrap_form/datetimepicker.rb