egov_utils 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/egov_utils/eGovUtilities.coffee.erb +9 -2
- data/app/controllers/egov_utils/sessions_controller.rb +2 -1
- data/app/controllers/egov_utils/users_controller.rb +13 -1
- data/app/helpers/egov_utils/application_helper.rb +12 -0
- data/app/helpers/egov_utils/grid_helper.rb +3 -0
- data/app/mailers/egov_utils/application_mailer.rb +1 -1
- data/app/mailers/egov_utils/user_mailer.rb +10 -0
- data/app/models/ability.rb +8 -6
- data/app/models/egov_utils/user.rb +18 -2
- data/app/views/azahara_schema/outputs/_grid.html.haml +5 -0
- data/app/views/common/_grid.html.coffee +2 -1
- data/app/views/egov_utils/sessions/new.html.haml +1 -1
- data/app/views/egov_utils/user_mailer/confirmation_email.html.erb +7 -0
- data/app/views/egov_utils/user_mailer/confirmation_email.text.erb +1 -0
- data/app/views/egov_utils/users/_form.html.haml +1 -1
- data/app/views/layouts/egov_utils/_messages.html.haml +1 -2
- data/app/views/layouts/egov_utils/mailer.html.erb +13 -0
- data/app/views/layouts/egov_utils/mailer.text.erb +1 -0
- data/config/locales/cs.yml +12 -3
- data/config/routes.rb +2 -0
- data/db/migrate/20171115142450_add_confirmation_code_to_users.rb +5 -0
- data/lib/bootstrap_form/datetimepicker.rb +16 -0
- data/lib/egov_utils/engine.rb +2 -0
- data/lib/egov_utils/user_utils/application_controller_patch.rb +36 -2
- data/lib/egov_utils/version.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 645db7eb940442f396800108992bba65e51e538f37f813ace77d2c6e2834fa62
|
4
|
+
data.tar.gz: e5e345da32a0ca06f627ee8be1fe623eb8f4c67491946a1e58067f6e75195c34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cde297896021821c290807c06ca689e145e1da3d96d1af1c4d654e1263bb2ff94f874eda73a2c079ded8d0f1050eb8c36ca9d79966aee0c1f1ceb564ec20caa
|
7
|
+
data.tar.gz: 34ea0683107c72945a89726ea377145d75c1f966d41ec1b8600e2204b08fe9693a9d014f461db5483f7c90f720148e89459c98818e33f179b9d383bf049ea8c1
|
@@ -25,8 +25,15 @@ window.eGovUtilities =
|
|
25
25
|
|
26
26
|
initDatepickers: ($container)->
|
27
27
|
$container ||= $(document)
|
28
|
-
|
29
|
-
|
28
|
+
if !Modernizr.inputtypes.date
|
29
|
+
pickers = $('[type="date"][data-provide="datepicker"]', $container)
|
30
|
+
pickers.parent().datetimepicker()
|
31
|
+
if !Modernizr.inputtypes.datetime
|
32
|
+
pickers = $('[type="datetime"][data-provide="datepicker"]', $container)
|
33
|
+
pickers.parent().datetimepicker()
|
34
|
+
if !Modernizr.inputtypes['datetime-local']
|
35
|
+
pickers = $('[type="datetime-local"][data-provide="datepicker"]', $container)
|
36
|
+
pickers.parent().datetimepicker()
|
30
37
|
|
31
38
|
initSelect2: ($container)->
|
32
39
|
$container ||= $(document)
|
@@ -2,6 +2,7 @@ module EgovUtils
|
|
2
2
|
class SessionsController < ApplicationController
|
3
3
|
|
4
4
|
skip_before_action :verify_authenticity_token, only: [:create]
|
5
|
+
skip_before_action :require_login, only: [:new, :create]
|
5
6
|
|
6
7
|
def new
|
7
8
|
if current_user.logged?
|
@@ -51,7 +52,7 @@ module EgovUtils
|
|
51
52
|
if params[:autologin]
|
52
53
|
set_autologin_cookie(user)
|
53
54
|
end
|
54
|
-
redirect_to
|
55
|
+
redirect_to '/'
|
55
56
|
# redirect_back(fallback_location: root_path)
|
56
57
|
end
|
57
58
|
|
@@ -4,6 +4,8 @@ require_dependency "egov_utils/auth_source"
|
|
4
4
|
module EgovUtils
|
5
5
|
class UsersController < ApplicationController
|
6
6
|
|
7
|
+
skip_before_action :require_login, only: [:new, :create, :confirm]
|
8
|
+
|
7
9
|
load_and_authorize_resource only: :index
|
8
10
|
|
9
11
|
def index
|
@@ -16,9 +18,11 @@ module EgovUtils
|
|
16
18
|
|
17
19
|
def create
|
18
20
|
@user = User.new(create_params)
|
21
|
+
@user.mail ||= @user.login
|
19
22
|
respond_to do |format|
|
20
23
|
if @user.save
|
21
|
-
|
24
|
+
UserMailer.confirmation_email(@user).deliver_later unless current_user.logged?
|
25
|
+
format.html{ redirect_to main_app.root_path, notice: t('activerecord.successful.messages.created', model: User.model_name.human) }
|
22
26
|
format.json{ render json: @user, status: :created }
|
23
27
|
else
|
24
28
|
format.html{ render 'new' }
|
@@ -38,6 +42,14 @@ module EgovUtils
|
|
38
42
|
redirect_back(fallback_location: @user)
|
39
43
|
end
|
40
44
|
|
45
|
+
def confirm
|
46
|
+
@user = User.find_by(confirmation_code: params[:id])
|
47
|
+
render_404 and return unless @user || @user.active? || @user.updated_at < (Time.now - 24.hours)
|
48
|
+
@user.update(active: true)
|
49
|
+
logged_user = @user
|
50
|
+
redirect_to('/')
|
51
|
+
end
|
52
|
+
|
41
53
|
def search
|
42
54
|
authorize!(:read, User)
|
43
55
|
authorize!(:read, Group)
|
@@ -9,5 +9,17 @@ module EgovUtils
|
|
9
9
|
javascript_tag s
|
10
10
|
end
|
11
11
|
|
12
|
+
def main_schema_attribute(schema)
|
13
|
+
schema.available_attributes_hash[schema.main_attribute_name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def role_based_render(name, *attributes)
|
17
|
+
res = ''.html_safe
|
18
|
+
current_user.all_role_names.each do |role_name|
|
19
|
+
res << render(name+'_'+role_name, *attributes) if lookup_context.exists?(name+'_'+role_name, [], true)
|
20
|
+
end
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
12
24
|
end
|
13
25
|
end
|
data/app/models/ability.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
ActiveSupport::Reloader.to_prepare do
|
2
|
+
begin
|
3
|
+
require_dependency "#{Rails.application.class.parent_name.underscore}/roles"
|
4
|
+
rescue LoadError => e
|
5
|
+
Rails.logger.warn "!! You have not defined roles."
|
6
|
+
Rails.logger.warn "!! Please define it in lib/#{Rails.application.class.parent_name.underscore}/roles."
|
7
|
+
Rails.logger.warn "!! EgovUtils roles management will not work without it."
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
11
|
class Ability
|
@@ -3,15 +3,23 @@ require 'request_store_rails'
|
|
3
3
|
|
4
4
|
module EgovUtils
|
5
5
|
class User < Principal
|
6
|
-
has_secure_password validations: false
|
7
6
|
|
8
7
|
serialize :roles, Array
|
9
8
|
|
10
|
-
|
9
|
+
has_secure_password validations: false
|
10
|
+
|
11
|
+
validates_confirmation_of :password, if: lambda { |m| m.password.present? }
|
12
|
+
validates_presence_of :password, on: :create, unless: :provider?
|
13
|
+
validates :login, uniqueness: true
|
14
|
+
|
15
|
+
before_validation :generate_confirmation_code, unless: :provider?
|
11
16
|
|
12
17
|
scope :active, -> { where(active: true) }
|
13
18
|
scope :inactive, -> { where(active: false) }
|
14
19
|
|
20
|
+
cattr_accessor :default_role
|
21
|
+
self.default_role = nil
|
22
|
+
|
15
23
|
def self.authenticate(login, password, active_only=true)
|
16
24
|
login = login.to_s
|
17
25
|
password = password.to_s
|
@@ -90,6 +98,8 @@ module EgovUtils
|
|
90
98
|
@all_role_names ||= Rails.cache.fetch("#{cache_key}/all_role_names", expires_in: 1.hours) do
|
91
99
|
groups.collect{|g| g.roles}.reduce([], :concat) + roles
|
92
100
|
end
|
101
|
+
@all_role_names << self.class.default_role if self.class.default_role && !@all_role_names.any?
|
102
|
+
@all_role_names
|
93
103
|
end
|
94
104
|
|
95
105
|
def all_roles
|
@@ -117,5 +127,11 @@ module EgovUtils
|
|
117
127
|
end
|
118
128
|
end
|
119
129
|
|
130
|
+
private
|
131
|
+
|
132
|
+
def generate_confirmation_code
|
133
|
+
self.confirmation_code ||= SecureRandom.hex
|
134
|
+
end
|
135
|
+
|
120
136
|
end
|
121
137
|
end
|
@@ -97,8 +97,9 @@ $ ->
|
|
97
97
|
title: " "
|
98
98
|
buttons: [
|
99
99
|
<% if can?(:update, schema.model) %>
|
100
|
-
{cls: 'btn btn-sm btn-primary', caption: '<%= t('label_edit') %>', click: editRecord}
|
100
|
+
{cls: 'btn btn-sm btn-primary', caption: '<%= t('label_edit') %>', click: editRecord},
|
101
101
|
<% end %>
|
102
|
+
<%= additional_grid_edit_buttons(schema) %>
|
102
103
|
# <% if can?(:destroy, schema.model) %>
|
103
104
|
# {commandName: 'delete', caption: '<%= t('label_delete') %>'}
|
104
105
|
# <% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Klikněte prosím na následující url: <%= confirm_user_url(@user.confirmation_code) %>
|
@@ -1,7 +1,6 @@
|
|
1
|
-
-# Rails flash messages styled for Zurb Foundation
|
2
1
|
- flash.each do |name, msg|
|
3
2
|
- if msg.is_a?(String)
|
4
|
-
%div{:class => "alert alert-#{name.to_s == 'notice' ? "info" : "alert"} alert-dismissible fade show", "role" => "alert"}
|
3
|
+
%div{:class => "alert alert-#{name.to_s == 'notice' ? "info" : (name.to_s == 'error' ? "alert" : name.to_s)} alert-dismissible fade show", "role" => "alert"}
|
5
4
|
%button.close{'type' => 'button', 'data-dismiss' => 'alert'}
|
6
5
|
%span{'aria-hidden' => 'true'}= raw '×'
|
7
6
|
= msg
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/config/locales/cs.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
---
|
2
2
|
cs:
|
3
|
+
time:
|
4
|
+
formats:
|
5
|
+
default: "%a %d. %B %Y %H:%M"
|
6
|
+
|
3
7
|
ministery_justice_name: Ministerstvo spravedlnosti ČR
|
4
8
|
label_no_records: Žádné záznamy k zobrazení
|
5
9
|
|
6
10
|
notice_account_invalid_credentials: Přihlašovací údaje jsou nesprávné
|
7
11
|
notice_onthefly_failure: Nemáte oprávnění k přístupu do aplikace
|
8
|
-
notice_account_pending: Váš
|
12
|
+
notice_account_pending: Váš účet čeká na schválení/ověření
|
9
13
|
notice_account_locked: Váš účet byl uzamčen správcem aplikace
|
10
14
|
notice_logout: Byl/a jste úspěšně odhlášen/a
|
11
15
|
|
@@ -15,14 +19,14 @@ cs:
|
|
15
19
|
label_profile: Profil
|
16
20
|
label_login: Přihlásit
|
17
21
|
label_logout: Odhlásit
|
22
|
+
label_signup: Registrovat
|
18
23
|
label_validate_address: Zvalidovat
|
19
24
|
|
20
25
|
text_born_on_at: "Narozen %{date} v %{place}"
|
21
26
|
|
22
27
|
common_labels:
|
23
28
|
new_record: "Nový %{model}"
|
24
|
-
notice_saved: "%{model}
|
25
|
-
|
29
|
+
notice_saved: "%{model} uložen"
|
26
30
|
|
27
31
|
|
28
32
|
models: &my_models
|
@@ -37,6 +41,11 @@ cs:
|
|
37
41
|
other: Adresy
|
38
42
|
|
39
43
|
model_attributes: &my_attributes
|
44
|
+
egov_utils/user:
|
45
|
+
login: Přihlašovací email
|
46
|
+
password_confirmation: Potvrzení hesla
|
47
|
+
firstname: Jméno
|
48
|
+
lastname: Příjmení
|
40
49
|
egov_utils/address:
|
41
50
|
full_address: Adresa
|
42
51
|
street: Ulice
|
data/config/routes.rb
CHANGED
@@ -3,11 +3,13 @@ EgovUtils::Engine.routes.draw do
|
|
3
3
|
get '/login', to: 'sessions#new', as: 'signin'
|
4
4
|
post '/login', to: 'sessions#create'
|
5
5
|
delete '/logout', to: 'sessions#destroy', as: 'signout'
|
6
|
+
get '/signup', to: 'users#new', as: 'signup'
|
6
7
|
|
7
8
|
resources :sessions
|
8
9
|
resources :users do
|
9
10
|
get :search, on: :collection
|
10
11
|
post :approve, on: :member
|
12
|
+
get :confirm, on: :member
|
11
13
|
end
|
12
14
|
|
13
15
|
resources :people
|
@@ -3,6 +3,7 @@ module BootstrapForm
|
|
3
3
|
def date_field(name, *args)
|
4
4
|
options = args.extract_options!.symbolize_keys!
|
5
5
|
options[:data] = {provide: 'datepicker', 'date-format' => 'L'}.merge(options[:data] || {})
|
6
|
+
options[:append] = calendar_addon
|
6
7
|
args << options
|
7
8
|
super
|
8
9
|
end
|
@@ -10,8 +11,23 @@ module BootstrapForm
|
|
10
11
|
def datetime_field(name, *args)
|
11
12
|
options = args.extract_options!.symbolize_keys!
|
12
13
|
options[:data] = {provide: 'datepicker'}.merge(options[:data] || {})
|
14
|
+
options[:append] = calendar_addon
|
13
15
|
args << options
|
14
16
|
super
|
15
17
|
end
|
18
|
+
|
19
|
+
def datetime_local_field(name, *args)
|
20
|
+
options = args.extract_options!.symbolize_keys!
|
21
|
+
options[:data] = {provide: 'datepicker'}.merge(options[:data] || {})
|
22
|
+
options[:append] = calendar_addon
|
23
|
+
args << options
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def calendar_addon
|
30
|
+
content_tag('i', '', class: 'fa fa-calendar')
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
data/lib/egov_utils/engine.rb
CHANGED
@@ -7,6 +7,7 @@ module EgovUtils
|
|
7
7
|
included do
|
8
8
|
|
9
9
|
before_action :user_setup, :set_locale
|
10
|
+
before_action :require_login
|
10
11
|
|
11
12
|
rescue_from CanCan::AccessDenied do |exception|
|
12
13
|
respond_to do |format|
|
@@ -31,7 +32,7 @@ module EgovUtils
|
|
31
32
|
def user_setup
|
32
33
|
# Find the current user
|
33
34
|
User.current = find_current_user || find_kerberos_user || User.anonymous
|
34
|
-
logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
|
35
|
+
logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})(roles=#{User.current.all_role_names.join(',')})" : "anonymous")) if logger
|
35
36
|
User.current
|
36
37
|
end
|
37
38
|
|
@@ -72,7 +73,7 @@ module EgovUtils
|
|
72
73
|
# Sets the logged in user
|
73
74
|
def logged_user=(user)
|
74
75
|
reset_session
|
75
|
-
if user && user.is_a?(EgovUtils::User)
|
76
|
+
if user && user.is_a?(EgovUtils::User) && user.active?
|
76
77
|
User.current = user
|
77
78
|
start_user_session(user)
|
78
79
|
else
|
@@ -84,6 +85,39 @@ module EgovUtils
|
|
84
85
|
session[:user_id] = user.id
|
85
86
|
end
|
86
87
|
|
88
|
+
def require_login
|
89
|
+
if require_login? && !current_user.logged?
|
90
|
+
# Extract only the basic url parameters on non-GET requests
|
91
|
+
if request.get?
|
92
|
+
url = request.original_url
|
93
|
+
else
|
94
|
+
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
|
95
|
+
end
|
96
|
+
respond_to do |format|
|
97
|
+
format.html {
|
98
|
+
if request.xhr?
|
99
|
+
head :unauthorized
|
100
|
+
else
|
101
|
+
redirect_to egov_utils.login_path(:back_url => url)
|
102
|
+
end
|
103
|
+
}
|
104
|
+
format.any(:atom, :pdf, :csv) {
|
105
|
+
redirect_to egov_utils.login_path(:back_url => url)
|
106
|
+
}
|
107
|
+
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' }
|
108
|
+
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' }
|
109
|
+
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' }
|
110
|
+
format.any { head :unauthorized }
|
111
|
+
end
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
true
|
115
|
+
end
|
116
|
+
|
117
|
+
def require_login?
|
118
|
+
false
|
119
|
+
end
|
120
|
+
|
87
121
|
private
|
88
122
|
def set_locale
|
89
123
|
I18n.default_locale = :cs
|
data/lib/egov_utils/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.18
|
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: 2017-11-
|
11
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '2.17'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: modernizr-rails
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '2.7'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '2.7'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: azahara_schema
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -303,6 +317,7 @@ files:
|
|
303
317
|
- app/helpers/egov_utils/users_helper.rb
|
304
318
|
- app/jobs/egov_utils/application_job.rb
|
305
319
|
- app/mailers/egov_utils/application_mailer.rb
|
320
|
+
- app/mailers/egov_utils/user_mailer.rb
|
306
321
|
- app/models/ability.rb
|
307
322
|
- app/models/egov_utils/address.rb
|
308
323
|
- app/models/egov_utils/application_record.rb
|
@@ -319,12 +334,15 @@ files:
|
|
319
334
|
- app/validators/email_validator.rb
|
320
335
|
- app/validators/fileuid_validator.rb
|
321
336
|
- app/validators/ico_validator.rb
|
337
|
+
- app/views/azahara_schema/outputs/_grid.html.haml
|
322
338
|
- app/views/common/_grid.html.coffee
|
323
339
|
- app/views/common/_modal.html.haml
|
324
340
|
- app/views/egov_utils/addresses/_form.html.haml
|
325
341
|
- app/views/egov_utils/people/_form.html.haml
|
326
342
|
- app/views/egov_utils/roles/index.html.haml
|
327
343
|
- app/views/egov_utils/sessions/new.html.haml
|
344
|
+
- app/views/egov_utils/user_mailer/confirmation_email.html.erb
|
345
|
+
- app/views/egov_utils/user_mailer/confirmation_email.text.erb
|
328
346
|
- app/views/egov_utils/users/_form.html.haml
|
329
347
|
- app/views/egov_utils/users/index.html.haml
|
330
348
|
- app/views/egov_utils/users/new.html.haml
|
@@ -332,6 +350,8 @@ files:
|
|
332
350
|
- app/views/errors/error_403.html.haml
|
333
351
|
- app/views/layouts/egov_utils/_messages.html.haml
|
334
352
|
- app/views/layouts/egov_utils/application.html.erb
|
353
|
+
- app/views/layouts/egov_utils/mailer.html.erb
|
354
|
+
- app/views/layouts/egov_utils/mailer.text.erb
|
335
355
|
- config/kraj.csv
|
336
356
|
- config/locales/cs.yml
|
337
357
|
- config/okres.csv
|
@@ -346,6 +366,7 @@ files:
|
|
346
366
|
- db/migrate/20170824111701_create_egov_utils_groups.rb
|
347
367
|
- db/migrate/20171103141234_add_birth_place_and_residence_to_people.rb
|
348
368
|
- db/migrate/20171109172909_add_external_uid_to_groups.rb
|
369
|
+
- db/migrate/20171115142450_add_confirmation_code_to_users.rb
|
349
370
|
- lib/bootstrap_form/datetimepicker.rb
|
350
371
|
- lib/bootstrap_form/fileuid.rb
|
351
372
|
- lib/bootstrap_form/helpers/bootstrap4.rb
|