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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d483ae93a2a968f5ff4fb74cecac3790bc9942a7e5488dba7500672e8ae570e
4
- data.tar.gz: 4324879d422fd21c52dab7193957b4ca25a5e1998f01121df79b527b4c1e052f
3
+ metadata.gz: 645db7eb940442f396800108992bba65e51e538f37f813ace77d2c6e2834fa62
4
+ data.tar.gz: e5e345da32a0ca06f627ee8be1fe623eb8f4c67491946a1e58067f6e75195c34
5
5
  SHA512:
6
- metadata.gz: 4efad04faa1075277da1fa431f0161d5552e696e86d62934a675b18e8fd78f0b2969e9354ac66150acd2a6a4f8a73cd6283c425e34d8d4b4ca938195c7f818f4
7
- data.tar.gz: 7f3d2077e44771b85f3e853cc34fe8b016d30d268c4bcd022e8f5e46aa49f8d4bce662eedb9f2da00f79611ed997f46366fa4ae0b09c61b5aa0eaf568cc546d6
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
- pickers = $('[data-provide="datepicker"]', $container)
29
- pickers.datetimepicker()
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 main_app.root_path
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
- format.html{ redirect_to main_app.root_path, notice: t('activerecord.successful.messages.created', model: Group.model_name.human) }
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
@@ -37,5 +37,8 @@ module EgovUtils
37
37
  end
38
38
  s << "}"
39
39
  end
40
+
41
+ def additional_grid_edit_buttons(schema)
42
+ end
40
43
  end
41
44
  end
@@ -1,6 +1,6 @@
1
1
  module EgovUtils
2
2
  class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
3
+ default from: 'noreply@justice.cz'
4
4
  layout 'mailer'
5
5
  end
6
6
  end
@@ -0,0 +1,10 @@
1
+ module EgovUtils
2
+ class UserMailer < ApplicationMailer
3
+
4
+ def confirmation_email(user)
5
+ @user = user
6
+ mail(to: user.mail, subject: t(:app_name))
7
+ end
8
+
9
+ end
10
+ end
@@ -1,9 +1,11 @@
1
- begin
2
- require_dependency "#{Rails.application.class.parent_name.underscore}/roles"
3
- rescue LoadError => e
4
- Rails.logger.warn "!! You have not defined roles."
5
- Rails.logger.warn "!! Please define it in lib/#{Rails.application.class.parent_name.underscore}/roles."
6
- Rails.logger.warn "!! EgovUtils roles management will not work without it."
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
- validates :login, uniqueness: true
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
@@ -0,0 +1,5 @@
1
+ - grid_id ||= grid.schema.model.model_name.plural.to_s+'_grid'
2
+ %div{id: grid_id}
3
+
4
+ :javascript
5
+ #{raw render 'common/grid', grid_id: grid_id, schema: grid.schema}
@@ -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 %>
@@ -2,4 +2,4 @@
2
2
  = f.text_field(:username)
3
3
  = f.password_field(:password)
4
4
  = f.submit t(:label_login)
5
- -# link_to t('label_register'), new_user_path
5
+ = link_to t('label_signup'), new_user_path, class: 'btn btn-secondary'
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
1
+ Klikněte prosím na následující url: <%= confirm_user_url(@user.confirmation_code) %>
@@ -1,5 +1,5 @@
1
1
  = form.text_field :login
2
- = form.text_field :mail
2
+ /= form.text_field :mail
3
3
  = form.password_field :password
4
4
  = form.password_field :password_confirmation
5
5
  = form.text_field :firstname
@@ -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 '&times;'
7
6
  = msg
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -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áš přístup čeká na schválení správce aplikace
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} vytvořen"
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
@@ -0,0 +1,5 @@
1
+ class AddConfirmationCodeToUsers < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :egov_utils_users, :confirmation_code, :string
4
+ end
5
+ end
@@ -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
@@ -3,6 +3,8 @@ require 'cancancan'
3
3
  require 'audited'
4
4
  require 'azahara_schema'
5
5
 
6
+ require 'modernizr-rails'
7
+
6
8
  module EgovUtils
7
9
  class Engine < ::Rails::Engine
8
10
  isolate_namespace EgovUtils
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.17'
2
+ VERSION = '0.1.18'
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.17
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-15 00:00:00.000000000 Z
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