egov_utils 1.1.0 → 1.2.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/app/controllers/egov_utils/current_users_controller.rb +26 -0
- data/app/controllers/egov_utils/groups_controller.rb +33 -7
- data/app/controllers/egov_utils/passwords_controller.rb +4 -1
- data/app/controllers/egov_utils/people_controller.rb +1 -1
- data/app/controllers/egov_utils/registration_requests_controller.rb +59 -0
- data/app/controllers/egov_utils/users_controller.rb +56 -33
- data/app/jobs/egov_utils/registration_requests/check_auto_accept_job.rb +12 -0
- data/app/mailers/egov_utils/registration_request_mailer.rb +31 -0
- data/app/models/egov_utils/group.rb +1 -3
- data/app/models/egov_utils/registration_request.rb +21 -0
- data/app/models/egov_utils/user.rb +12 -0
- data/app/services/egov_utils/archive_users.rb +12 -0
- data/app/services/egov_utils/refresh_groups.rb +28 -0
- data/app/services/egov_utils/refresh_user_groups.rb +3 -4
- data/app/services/egov_utils/registration_requests/check_auto_accept.rb +31 -0
- data/app/services/egov_utils/registration_requests/create.rb +25 -0
- data/app/services/egov_utils/registration_requests/handle_request.rb +57 -0
- data/app/views/egov_utils/current_users/edit.html.haml +12 -0
- data/app/views/egov_utils/groups/_form.html.haml +5 -0
- data/app/views/egov_utils/groups/_groups_tab.html.haml +0 -5
- data/app/views/egov_utils/groups/edit.html.haml +4 -0
- data/app/views/egov_utils/groups/index.html.haml +28 -19
- data/app/views/egov_utils/groups/new.html.haml +4 -0
- data/app/views/egov_utils/registration_request_mailer/accepted.html.erb +12 -0
- data/app/views/egov_utils/registration_request_mailer/auto_accepted.html.erb +8 -0
- data/app/views/egov_utils/registration_request_mailer/created.html.erb +12 -0
- data/app/views/egov_utils/registration_request_mailer/rejected.html.erb +6 -0
- data/app/views/egov_utils/registration_requests/index.html.haml +29 -0
- data/app/views/egov_utils/registration_requests/new.html.haml +9 -0
- data/app/views/egov_utils/registration_requests/show.html.haml +51 -0
- data/app/views/egov_utils/sessions/new.html.haml +3 -0
- data/app/views/egov_utils/users/edit.html.haml +9 -0
- data/app/views/egov_utils/users/index.html.haml +42 -25
- data/config/locales/cs.yml +81 -3
- data/config/routes.rb +6 -1
- data/db/migrate/20230407114921_add_deleted_at_to_egov_utils_users.rb +6 -0
- data/db/migrate/20230408123813_create_egov_utils_registration_requests.rb +16 -0
- data/db/migrate/20230412063325_add_days_before_archive_to_egov_utils_users.rb +5 -0
- data/lib/egov_utils/version.rb +1 -1
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0d959fdb236578d9d04f1828e69794d06ef9b7e03696f4459a714da45528180
|
4
|
+
data.tar.gz: c74d6584c3ca4ba356a236d81decd35e9d5a45b09f0b84048f2f32f2d95597ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d208c342267f541e57835573f28bb10f173592f87b2c0a7a96427c7398cfcd11b2984a1ba4770d67f1ef6be0b04e32edd0586b3f887d0e5b3b56711961afad94
|
7
|
+
data.tar.gz: 7e06bb6d70942d28fa90266e3b9aa5e4bc0c8bf3790989c934b385e5cafc9e95559af1beae42e189b9210b4a49360d6d28435d58f7a71e88a18259482ad7348b
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
class CurrentUsersController < ApplicationController
|
3
|
+
before_action :require_login
|
4
|
+
|
5
|
+
def edit; end
|
6
|
+
|
7
|
+
def update
|
8
|
+
current_user.update(update_params)
|
9
|
+
|
10
|
+
if current_user.valid?
|
11
|
+
redirect_to edit_current_user_path, notice: t('activerecord.successful.messages.updated', model: User.model_name.human)
|
12
|
+
else
|
13
|
+
render :edit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def update_params
|
20
|
+
params
|
21
|
+
.require(:user)
|
22
|
+
.permit(:email, :password, :password_confirmation, :firstname,
|
23
|
+
:lastname)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,20 +2,36 @@ require_dependency "egov_utils/application_controller"
|
|
2
2
|
|
3
3
|
module EgovUtils
|
4
4
|
class GroupsController < ApplicationController
|
5
|
+
def index
|
6
|
+
@groups = EgovUtils::Group.
|
7
|
+
accessible_by(current_ability).
|
8
|
+
order(:provider).
|
9
|
+
page(params[:page] || 1)
|
10
|
+
end
|
5
11
|
|
6
|
-
|
12
|
+
def new
|
13
|
+
@group = Group.new
|
14
|
+
end
|
7
15
|
|
8
|
-
def
|
9
|
-
@
|
16
|
+
def edit
|
17
|
+
@group = Group.find(params[:id])
|
10
18
|
end
|
11
19
|
|
12
|
-
def
|
20
|
+
def update
|
21
|
+
@group = Group.find(params[:id])
|
22
|
+
|
23
|
+
if @group.update(update_params)
|
24
|
+
redirect_to egov_utils.groups_path, notice: t('success_updated')
|
25
|
+
else
|
26
|
+
render :edit
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
15
30
|
def create
|
31
|
+
@group = Group.new(create_params)
|
16
32
|
respond_to do |format|
|
17
33
|
if @group.save
|
18
|
-
format.html{ redirect_to egov_utils.
|
34
|
+
format.html{ redirect_to egov_utils.groups_path, notice: t('success_created') }
|
19
35
|
format.json{ render json: @group, status: :created }
|
20
36
|
else
|
21
37
|
format.html{ render 'new' }
|
@@ -44,9 +60,19 @@ module EgovUtils
|
|
44
60
|
|
45
61
|
private
|
46
62
|
|
47
|
-
|
48
|
-
|
63
|
+
def create_params
|
64
|
+
params
|
65
|
+
.require(:group)
|
66
|
+
.permit(:name, :provider, :ldap_uid, :external_uid, roles: []) do |p|
|
67
|
+
p[:roles] = p[:roles].compact_blank
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def update_params
|
72
|
+
params.require(:group).permit(:name, roles: []).tap do |p|
|
73
|
+
p[:roles] = p[:roles].compact_blank
|
49
74
|
end
|
75
|
+
end
|
50
76
|
|
51
77
|
end
|
52
78
|
end
|
@@ -18,8 +18,11 @@ module EgovUtils
|
|
18
18
|
if @user && @user.password_change_possible?
|
19
19
|
@token = @user.generate_reset_password_token
|
20
20
|
EgovUtils::UserMailer.with(host: mailer_host).password_reset(@user, @token).deliver_later if @user.save
|
21
|
+
flash[:notice] = t('notice_reset_email_sent')
|
22
|
+
elsif !@user.password_change_possible?
|
23
|
+
flash[:error] = t('notice_pw_reset_not_possible')
|
21
24
|
end
|
22
|
-
redirect_to egov_utils.reset_passwords_path
|
25
|
+
redirect_to egov_utils.reset_passwords_path
|
23
26
|
end
|
24
27
|
|
25
28
|
# New password for existing user - password reset
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
class RegistrationRequestsController < ApplicationController
|
3
|
+
before_action :find_registration_request, only: %i[show update]
|
4
|
+
before_action :require_login, except: %i[new create]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@registration_requests =
|
8
|
+
RegistrationRequest.order(created_at: :desc).page(params[:page] || 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def show; end
|
12
|
+
|
13
|
+
def new
|
14
|
+
@registration_request = RegistrationRequest.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
@registration_request = RegistrationRequests::Create.run!(create_params)
|
19
|
+
if @registration_request.valid?
|
20
|
+
redirect_to egov_utils.new_session_path,
|
21
|
+
notice: I18n.t('registration_request.create.success')
|
22
|
+
else
|
23
|
+
render :new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
RegistrationRequests::HandleRequest.run!(
|
29
|
+
update_params.merge(registration_request: @registration_request)
|
30
|
+
)
|
31
|
+
|
32
|
+
if @registration_request.valid?
|
33
|
+
redirect_to @registration_request,
|
34
|
+
notice: I18n.t('registration_request.update.success')
|
35
|
+
else
|
36
|
+
render :show
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def find_registration_request
|
43
|
+
@registration_request = EgovUtils::RegistrationRequest.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_params
|
47
|
+
params
|
48
|
+
.require(:registration_request)
|
49
|
+
.permit(:mail, :firstname, :lastname, :organization, :note)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update_params
|
53
|
+
params
|
54
|
+
.require(:registration_request)
|
55
|
+
.permit(:status, :reason, :internal_reason, roles: [])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -1,24 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'egov_utils/application_controller'
|
4
|
+
require_dependency 'egov_utils/auth_source'
|
3
5
|
|
4
6
|
module EgovUtils
|
5
7
|
class UsersController < ApplicationController
|
8
|
+
skip_before_action :require_login, only: %i[new create confirm edit update]
|
9
|
+
before_action :set_providers, only: %i[index search]
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
load_and_authorize_resource only: [:index, :new, :create, :show, :destroy, :edit, :update]
|
11
|
+
load_and_authorize_resource only: %i[index new create show destroy edit update]
|
10
12
|
|
11
13
|
def index
|
12
|
-
|
13
|
-
@groups = EgovUtils::Group.accessible_by(current_ability).order(:provider)
|
14
|
-
@new_user = EgovUtils::User.new(generate_password: true)
|
14
|
+
params[:default_scope] ||= :without_deleted
|
15
15
|
azahara_schema_index do |users|
|
16
16
|
users.add_sort('provider')
|
17
17
|
end
|
18
|
+
@entities =
|
19
|
+
@users.entities.includes(:groups).page(params[:page] || 1).per(50)
|
20
|
+
if params[:search]
|
21
|
+
@entities = @entities.search(params[:search])
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
|
-
def new
|
21
|
-
end
|
25
|
+
def new; end
|
22
26
|
|
23
27
|
def create
|
24
28
|
@user.mail ||= @user.login
|
@@ -34,25 +38,27 @@ module EgovUtils
|
|
34
38
|
end
|
35
39
|
flash[:notice] = t('activerecord.successful.messages.created', model: User.model_name.human)
|
36
40
|
end
|
37
|
-
format.html{ redirect_to main_app.root_path }
|
38
|
-
format.json{ render json: @user, status: :created }
|
41
|
+
format.html { redirect_to main_app.root_path }
|
42
|
+
format.json { render json: @user, status: :created }
|
39
43
|
else
|
40
|
-
format.html{ render 'new' }
|
41
|
-
format.json{ render json: @user.errors.full_messages, status: :unprocessable_entity }
|
44
|
+
format.html { render 'new' }
|
45
|
+
format.json { render json: @user.errors.full_messages, status: :unprocessable_entity }
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def show
|
47
|
-
end
|
50
|
+
def show; end
|
48
51
|
|
49
|
-
def edit
|
50
|
-
end
|
52
|
+
def edit; end
|
51
53
|
|
52
54
|
def update
|
53
55
|
@user.update(update_params)
|
54
56
|
|
55
|
-
|
57
|
+
if @user.valid?
|
58
|
+
redirect_to users_path, notice: t('activerecord.successful.messages.updated', model: User.model_name.human)
|
59
|
+
else
|
60
|
+
render :edit
|
61
|
+
end
|
56
62
|
end
|
57
63
|
|
58
64
|
def destroy
|
@@ -81,29 +87,46 @@ module EgovUtils
|
|
81
87
|
authorize!(:read, User)
|
82
88
|
authorize!(:read, Group)
|
83
89
|
user_results = []; group_results = []
|
84
|
-
providers.each do |provider|
|
85
|
-
user_results.concat(
|
86
|
-
group_results.concat(
|
90
|
+
@providers.each do |provider|
|
91
|
+
user_results.concat(provider.search_user(params[:q]))
|
92
|
+
group_results.concat(provider.search_group(params[:q]))
|
87
93
|
end if params[:q].present?
|
88
94
|
respond_to do |format|
|
89
|
-
format.json
|
95
|
+
format.json do
|
96
|
+
render json: { users: user_results, groups: group_results }
|
97
|
+
end
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
101
|
+
def unarchive
|
102
|
+
user = User.with_deleted.find(params[:id])
|
103
|
+
user.restore
|
104
|
+
redirect_to users_path, notice: t('activerecord.successful.messages.unarchived', model: User.model_name.human)
|
105
|
+
end
|
106
|
+
|
93
107
|
private
|
94
108
|
|
95
|
-
|
96
|
-
|
109
|
+
def set_providers
|
110
|
+
@providers = EgovUtils::AuthSource.providers.map do |p|
|
111
|
+
EgovUtils::AuthSource.new(p)
|
97
112
|
end
|
113
|
+
end
|
98
114
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
115
|
+
def create_params
|
116
|
+
params_to_permit = %i[login mail password password_confirmation provider firstname lastname]
|
117
|
+
params_to_permit << :generate_password if current_user.logged?
|
118
|
+
params.require(:user).permit(*params_to_permit)
|
119
|
+
end
|
104
120
|
|
105
|
-
|
106
|
-
|
107
|
-
|
121
|
+
def update_params
|
122
|
+
params
|
123
|
+
.require(:user)
|
124
|
+
.permit(
|
125
|
+
:days_before_inactive, :days_before_archive, :password,
|
126
|
+
:password_confirmation, roles: []
|
127
|
+
).tap do |p|
|
128
|
+
p[:roles] = p[:roles].compact_blank
|
129
|
+
end
|
130
|
+
end
|
108
131
|
end
|
109
132
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
class RegistrationRequestMailer < ApplicationMailer
|
3
|
+
before_action { @host = params && params[:host] || Rails.application.config.action_mailer.default_url_options[:host] }
|
4
|
+
|
5
|
+
def created(request_id)
|
6
|
+
@request = EgovUtils::RegistrationRequest.find(request_id)
|
7
|
+
|
8
|
+
mail(to: @request.mail, subject: I18n.t('mailers.registration_requests.created.subject'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def accepted(request_id, user_id, password)
|
12
|
+
@request = EgovUtils::RegistrationRequest.find(request_id)
|
13
|
+
@user = User.find(user_id)
|
14
|
+
@password = password
|
15
|
+
|
16
|
+
mail(to: @user.mail, subject: I18n.t('mailers.registration_requests.accepted.subject'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def auto_accepted(request_id)
|
20
|
+
@request = EgovUtils::RegistrationRequest.find(request_id)
|
21
|
+
|
22
|
+
mail(to: @request.mail, subject: I18n.t('mailers.registration_requests.auto_accepted.subject'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def rejected(request_id)
|
26
|
+
@request = EgovUtils::RegistrationRequest.find(request_id)
|
27
|
+
|
28
|
+
mail(to: @request.mail, subject: I18n.t('mailers.registration_requests.rejected.subject'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
class RegistrationRequest < ApplicationRecord
|
3
|
+
validates :mail, :firstname, :lastname, :organization, presence: true
|
4
|
+
validate :check_user_already_exists!
|
5
|
+
|
6
|
+
attr_accessor :roles
|
7
|
+
|
8
|
+
def fullname
|
9
|
+
"#{firstname} #{lastname}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def check_user_already_exists!
|
15
|
+
return unless User.find_by(mail: mail)
|
16
|
+
|
17
|
+
errors.add(:mail, :taken)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -3,7 +3,13 @@ require 'request_store_rails'
|
|
3
3
|
|
4
4
|
module EgovUtils
|
5
5
|
class User < Principal
|
6
|
+
acts_as_paranoid without_default_scope: true
|
7
|
+
|
6
8
|
DEFAULT_ROLE = nil
|
9
|
+
SEARCH_FIELDS = [
|
10
|
+
'login', 'firstname', 'lastname', 'mail',
|
11
|
+
"CONCAT(firstname, ' ', lastname)", "CONCAT(lastname, ' ', firstname)"
|
12
|
+
].freeze
|
7
13
|
|
8
14
|
has_and_belongs_to_many :groups
|
9
15
|
|
@@ -36,6 +42,12 @@ module EgovUtils
|
|
36
42
|
not_in_group(group).where(provider: nil)
|
37
43
|
}
|
38
44
|
|
45
|
+
scope :search, lambda { |search_term|
|
46
|
+
search_term = search_term.to_s
|
47
|
+
term = SEARCH_FIELDS.map { |field| "#{field} ILIKE :search" }.join(' OR ')
|
48
|
+
where(term, search: "%#{sanitize_sql_like(search_term)}%")
|
49
|
+
}
|
50
|
+
|
39
51
|
attribute :generate_password, :boolean, default: false
|
40
52
|
|
41
53
|
def self.authenticate(login, password, active_only=true)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
class RefreshGroups
|
3
|
+
|
4
|
+
def call
|
5
|
+
hsh = groups.each_with_object({}) do |group, memo|
|
6
|
+
infos = group.ldap_members
|
7
|
+
infos.each do |info|
|
8
|
+
memo[info] ||= []
|
9
|
+
memo[info] << group
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
hsh.each do |info, groups|
|
14
|
+
user = EgovUtils::User.find_by(login: info[:login])
|
15
|
+
next unless user
|
16
|
+
|
17
|
+
all_groups = user.groups.where(ldap_uid: nil) + groups
|
18
|
+
user.update(info.merge(groups: all_groups))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def groups
|
25
|
+
EgovUtils::Group.where.not(ldap_uid: nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -6,7 +6,7 @@ module EgovUtils
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call
|
9
|
-
group_ids = (
|
9
|
+
group_ids = (current_non_ldap_groups + ldap_groups).compact.map(&:id)
|
10
10
|
user.group_ids = group_ids
|
11
11
|
user
|
12
12
|
end
|
@@ -18,14 +18,13 @@ module EgovUtils
|
|
18
18
|
def ldap_groups
|
19
19
|
return [] if user.provider.blank?
|
20
20
|
|
21
|
-
@ldap_groups ||=
|
21
|
+
@ldap_groups ||=
|
22
22
|
EgovUtils::Group.where(provider: user.provider).to_a.select do |g|
|
23
23
|
user.auth_source.member?(user.ldap_dn, g.external_uid)
|
24
24
|
end
|
25
|
-
end
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
27
|
+
def current_non_ldap_groups
|
29
28
|
@current_non_ldap_groups ||= user.groups.where(ldap_uid: nil)
|
30
29
|
end
|
31
30
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
module RegistrationRequests
|
3
|
+
class CheckAutoAccept < ActiveInteraction::Base
|
4
|
+
record :registration_request, class: 'EgovUtils::RegistrationRequest'
|
5
|
+
|
6
|
+
def execute
|
7
|
+
member = nil
|
8
|
+
EgovUtils::Group.where.not(provider: nil).detect do |g|
|
9
|
+
member = g.ldap_members.detect do |m|
|
10
|
+
m[:login] == registration_request.mail
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
return unless member
|
15
|
+
|
16
|
+
registration_request.update(
|
17
|
+
status: 'accepted',
|
18
|
+
internal_note:
|
19
|
+
'Automaticky schválen na základě členství v LDAP skupině'
|
20
|
+
)
|
21
|
+
|
22
|
+
EgovUtils::RegistrationRequestMailer
|
23
|
+
.auto_accepted(registration_request.id)
|
24
|
+
.deliver_now
|
25
|
+
|
26
|
+
registration_request
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
module RegistrationRequests
|
3
|
+
class Create < ActiveInteraction::Base
|
4
|
+
string :mail
|
5
|
+
string :firstname
|
6
|
+
string :lastname
|
7
|
+
string :organization
|
8
|
+
string :note
|
9
|
+
|
10
|
+
def execute
|
11
|
+
request = RegistrationRequest.create(inputs.merge(status: :pending))
|
12
|
+
|
13
|
+
if request.persisted?
|
14
|
+
EgovUtils::RegistrationRequestMailer.created(request.id).deliver_now
|
15
|
+
CheckAutoAcceptJob.perform_async(request.id)
|
16
|
+
else
|
17
|
+
errors.merge!(request.errors)
|
18
|
+
end
|
19
|
+
|
20
|
+
request
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module EgovUtils
|
2
|
+
module RegistrationRequests
|
3
|
+
class HandleRequest < ActiveInteraction::Base
|
4
|
+
record :registration_request, class: 'EgovUtils::RegistrationRequest'
|
5
|
+
string :status
|
6
|
+
string :reason, default: nil
|
7
|
+
string :internal_reason, default: nil
|
8
|
+
array :roles, default: [] do
|
9
|
+
string
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
registration_request.update(
|
14
|
+
status: status,
|
15
|
+
reason: reason,
|
16
|
+
internal_reason: internal_reason
|
17
|
+
)
|
18
|
+
|
19
|
+
case status
|
20
|
+
when 'accepted'
|
21
|
+
user = create_user!
|
22
|
+
EgovUtils::RegistrationRequestMailer
|
23
|
+
.accepted(registration_request.id, user.id, password)
|
24
|
+
.deliver_now
|
25
|
+
when 'rejected'
|
26
|
+
EgovUtils::RegistrationRequestMailer
|
27
|
+
.rejected(registration_request.id)
|
28
|
+
.deliver_now
|
29
|
+
end
|
30
|
+
|
31
|
+
registration_request
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def create_user!
|
37
|
+
user = User.create(
|
38
|
+
mail: registration_request.mail,
|
39
|
+
login: registration_request.mail,
|
40
|
+
firstname: registration_request.firstname,
|
41
|
+
lastname: registration_request.lastname,
|
42
|
+
password: password,
|
43
|
+
password_confirmation: password,
|
44
|
+
roles: roles.compact_blank,
|
45
|
+
must_change_password: true,
|
46
|
+
active: true,
|
47
|
+
last_login_at: Time.current
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def password
|
52
|
+
@password ||= SecureRandom.hex(8)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%h1= t('.title')
|
2
|
+
= bootstrap_form_for(current_user, url: current_user_path) do |form|
|
3
|
+
= form.text_field :login
|
4
|
+
= form.text_field :firstname
|
5
|
+
= form.text_field :lastname
|
6
|
+
.passwords
|
7
|
+
%h2= t('.password_change')
|
8
|
+
%em= t('.password_change_note')
|
9
|
+
= form.password_field :password
|
10
|
+
= form.password_field :password_confirmation
|
11
|
+
= form.submit
|
12
|
+
|