egov_utils 0.1.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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/config/egov_utils_manifest.js +2 -0
  6. data/app/assets/javascripts/egov_utils/application.js +23 -0
  7. data/app/assets/javascripts/egov_utils/eGovUtilities.coffee.erb +70 -0
  8. data/app/assets/javascripts/egov_utils/groups.js +2 -0
  9. data/app/assets/javascripts/egov_utils/roles.coffee.erb +56 -0
  10. data/app/assets/javascripts/egov_utils/setup_locale.coffee.erb +2 -0
  11. data/app/assets/javascripts/egov_utils/users.js +2 -0
  12. data/app/assets/stylesheets/egov_utils/application.scss +15 -0
  13. data/app/assets/stylesheets/egov_utils/groups.css +4 -0
  14. data/app/assets/stylesheets/egov_utils/roles.css +4 -0
  15. data/app/assets/stylesheets/egov_utils/users.css +4 -0
  16. data/app/attributes/egov_utils/district.rb +13 -0
  17. data/app/attributes/egov_utils/full_address.rb +17 -0
  18. data/app/attributes/egov_utils/region.rb +13 -0
  19. data/app/controllers/egov_utils/addresses_controller.rb +34 -0
  20. data/app/controllers/egov_utils/application_controller.rb +7 -0
  21. data/app/controllers/egov_utils/groups_controller.rb +27 -0
  22. data/app/controllers/egov_utils/roles_controller.rb +28 -0
  23. data/app/controllers/egov_utils/sessions_controller.rb +83 -0
  24. data/app/controllers/egov_utils/users_controller.rb +64 -0
  25. data/app/helpers/egov_utils/application_helper.rb +4 -0
  26. data/app/helpers/egov_utils/grid_helper.rb +40 -0
  27. data/app/helpers/egov_utils/groups_helper.rb +4 -0
  28. data/app/helpers/egov_utils/roles_helper.rb +4 -0
  29. data/app/helpers/egov_utils/users_helper.rb +4 -0
  30. data/app/jobs/egov_utils/application_job.rb +4 -0
  31. data/app/mailers/egov_utils/application_mailer.rb +6 -0
  32. data/app/models/ability.rb +17 -0
  33. data/app/models/egov_utils/address.rb +79 -0
  34. data/app/models/egov_utils/application_record.rb +5 -0
  35. data/app/models/egov_utils/audit_detail.rb_bac +28 -0
  36. data/app/models/egov_utils/audit_record.rb_bac +98 -0
  37. data/app/models/egov_utils/group.rb +26 -0
  38. data/app/models/egov_utils/person.rb +9 -0
  39. data/app/models/egov_utils/principal.rb +20 -0
  40. data/app/models/egov_utils/user.rb +108 -0
  41. data/app/schemas/egov_utils/address_schema.rb +30 -0
  42. data/app/validators/email_validator.rb +8 -0
  43. data/app/validators/ico_validator.rb +7 -0
  44. data/app/views/common/_grid.html.coffee +130 -0
  45. data/app/views/common/_modal.html.haml +11 -0
  46. data/app/views/egov_utils/addresses/_form.html.haml +51 -0
  47. data/app/views/egov_utils/people/_form.html.haml +3 -0
  48. data/app/views/egov_utils/roles/index.html.haml +29 -0
  49. data/app/views/egov_utils/sessions/new.html.haml +5 -0
  50. data/app/views/egov_utils/users/_form.html.haml +6 -0
  51. data/app/views/egov_utils/users/index.html.haml +62 -0
  52. data/app/views/egov_utils/users/new.html.haml +3 -0
  53. data/app/views/egov_utils/users/show.html.haml +1 -0
  54. data/app/views/errors/error_403.html.haml +1 -0
  55. data/app/views/layouts/egov_utils/_messages.html.haml +7 -0
  56. data/app/views/layouts/egov_utils/application.html.erb +14 -0
  57. data/config/kraj.csv +16 -0
  58. data/config/locales/cs.yml +80 -0
  59. data/config/okres.csv +79 -0
  60. data/config/routes.rb +21 -0
  61. data/db/migrate/20170313100505_create_egov_utils_addresses.rb +18 -0
  62. data/db/migrate/20170315134217_create_egov_utils_users.rb +16 -0
  63. data/db/migrate/20170513115712_create_egov_utils_audit_records.rb_bac +11 -0
  64. data/db/migrate/20170513120006_create_egov_utils_audit_details.rb_bac +13 -0
  65. data/db/migrate/20170630150633_add_provider_to_user.rb +5 -0
  66. data/db/migrate/20170801154511_install_audited.rb +30 -0
  67. data/db/migrate/20170809150646_create_egov_utils_people.rb +12 -0
  68. data/db/migrate/20170824111701_create_egov_utils_groups.rb +12 -0
  69. data/lib/bootstrap_form/datetimepicker.rb +17 -0
  70. data/lib/bootstrap_form/helpers/bootstrap4.rb +12 -0
  71. data/lib/egov_utils/auth_source.rb +326 -0
  72. data/lib/egov_utils/engine.rb +84 -0
  73. data/lib/egov_utils/has_audit_trail.rb +68 -0
  74. data/lib/egov_utils/user_utils/application_controller_patch.rb +92 -0
  75. data/lib/egov_utils/user_utils/role.rb +26 -0
  76. data/lib/egov_utils/version.rb +3 -0
  77. data/lib/egov_utils.rb +5 -0
  78. data/lib/grid/shield_grid.rb +9 -0
  79. data/lib/tasks/egov_utils_tasks.rake +4 -0
  80. metadata +306 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1326389e276358d5474d13f8d62bf21ff1a4bdb9
4
+ data.tar.gz: f364b9d541c136e08736fc290bb2eafd54c16b0a
5
+ SHA512:
6
+ metadata.gz: a4bca9ba5dac51fc1bb59875a136ce73ddbab8f9737e8a41a4a6600e2b23a4fa6f3f42fe26258f29b4044da307206c6494837f66e00aadb6e3bcdb01ec2a71d4
7
+ data.tar.gz: 6a57d7bda4a1dba2d0307f486fa64148d384ea03594d6b8aa94ec599aa0909382a7b9a77a4c25c859e2565d07966d05ea97699be2095a3bbfda0360ee6bb39bf
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Ondřej Ezr
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # EgovUtils
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'egov_utils'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install egov_utils
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'EgovUtils'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/egov_utils .js
2
+ //= link_directory ../stylesheets/egov_utils .css
@@ -0,0 +1,23 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require i18n
14
+ //= require moment
15
+ //= require moment/cs
16
+ //= require popper
17
+ //= require bootstrap-sprockets
18
+ //= require bootstrap-datetimepicker
19
+ //= require shieldui-all.min
20
+ //= require egov_utils/setup_locale
21
+ //= require i18n/translations
22
+ //= require egov_utils/eGovUtilities
23
+ //= require egov_utils/roles
@@ -0,0 +1,70 @@
1
+
2
+ window.eGovUtilities =
3
+ setup: ()->
4
+ $.extend $.fn.datetimepicker.defaults.icons, {
5
+ time: 'fa fa-clock-o',
6
+ date: 'fa fa-calendar',
7
+ up: 'fa fa-chevron-up',
8
+ down: 'fa fa-chevron-down',
9
+ previous: 'fa fa-chevron-left',
10
+ next: 'fa fa-chevron-right',
11
+ today: 'fa fa-calendar-check-o',
12
+ clear: 'fa fa-trash-o',
13
+ close: 'fa fa-close'
14
+ }
15
+
16
+ initPage: ()->
17
+ eGovUtilities.initDatepickers()
18
+
19
+ initDatepickers: ($container)->
20
+ $container ||= $(document)
21
+ pickers = $('[data-provide="datepicker"]', $container)
22
+ pickers.datetimepicker()
23
+
24
+ initModal: (modalId, options)->
25
+ options = options || {}
26
+ modalId = modalId || 'modal'
27
+ $modal = $('#'+modalId)
28
+ if $modal.length != 1
29
+ $modal = $('<div id="'+modalId+'" class="modal fade"'+(if options['backdrop'] then ' data-backdrop="static"' else '')+'><div class="modal-dialog">
30
+ <div class="modal-content">
31
+ <div class="modal-header">
32
+ <h5 class="modal-title"></h5>
33
+ <button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
34
+ </div>
35
+ <div class="modal-body"></div>
36
+ <div class="modal-footer"></div>
37
+ </div></div></div>').appendTo('body')
38
+ $modal.on 'submit', 'form', (evt)->
39
+ evt.preventDefault()
40
+ $form = $(this)
41
+ data = $form.serializeArray()
42
+ $.ajax($form.attr('action')+'.json', {method: $form.attr('method'), data: data, dataType: 'json'}).done (xhr)->
43
+ $modal.trigger('egov:submitted', [xhr])
44
+ $modal.modal('hide')
45
+ .fail (xhr) ->
46
+ if xhr.status == 422
47
+ $.ajax($form.attr('action'), {method: $form.attr('method'), data: data, dataType: 'html'}).done (xhr)->
48
+ eGovUtilities.setModalContent($modal, xhr)
49
+
50
+ $modal
51
+
52
+ setModalContent: ($modal, body, title) ->
53
+ $modal.find('.modal-title').text(title)
54
+ $modal.find('.modal-body').html(body)
55
+ eGovUtilities.initDatepickers($modal)
56
+
57
+ showModal: (body, options) ->
58
+ options = options || {}
59
+ $modal = this.initModal((options['modalId']), {backdrop: options['backdrop']})
60
+ title = options['title']
61
+ delete options['modalId']
62
+ delete options['backdrop']
63
+ delete options['title']
64
+ eGovUtilities.setModalContent($modal, body, title)
65
+ $modal.modal(options)
66
+ $modal
67
+
68
+ $(eGovUtilities.setup)
69
+ $(document).on 'turbolinks:load', (evt)->
70
+ eGovUtilities.initPage()
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,56 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+
3
+ $ = jQuery
4
+
5
+ $.widget 'egov_utils.roles',
6
+ options:
7
+ editBtnClass: 'btn btn-sm btn-info'
8
+ submitBtnClass: 'btn btn-xs btn-primary'
9
+ editIconClass: 'fa fa-pencil'
10
+ allRoles: ['<%= EgovUtils::UserUtils::Role.roles.keys.join("', '") %>']
11
+ url: null
12
+ idParamName: 'id'
13
+ valueName: 'roles'
14
+
15
+ _create: ()->
16
+ this.allRoles = this.element.data('all_roles') || this.options.allRoles || []
17
+ this._initialize();
18
+
19
+ _initialize: ()->
20
+
21
+ btn = this._edit_btn()
22
+ this.element.find('.roles').append(btn)
23
+
24
+ _edit_btn: ()->
25
+ that = this
26
+ $('<a/>', {href: 'javascript:void(0);', class: this.options.editBtnClass})
27
+ .html('<i class="'+this.options.editIconClass+'"></i>')
28
+ .on 'click', (evt)->
29
+ evt.preventDefault()
30
+ that._create_form($(this).closest('.roles'))
31
+
32
+ _create_form: ($elem)->
33
+ that = this
34
+ $elem.html('')
35
+ entity_id = $elem.data('id')
36
+ roles = $elem.data('roles')
37
+ if typeof this.options.url == 'function'
38
+ url = this.options.url(entity_id)
39
+ else
40
+ url = this.options.url
41
+
42
+ $form = $('<form/>', {action: url, method: 'post'})
43
+ $form.append('<input type="hidden" name="authenticity_token" value="'+$('meta[name=csrf-token]').attr('content')+'">')
44
+ $form.append('<input type="hidden" name="utf8" value="✔">')
45
+ $form.append('<input type="hidden" name="'+this.options.idParamName+'" value="'+entity_id.toString()+'">')
46
+ $form.append('<input type="hidden" name="'+this.options.valueName+'[]" value="">')
47
+ for r in this.allRoles
48
+ $form.append('<label><input type="checkbox" value="'+r+'" '+(if r in roles then 'checked="true"' else '')+' name="'+this.options.valueName+'[]">'+r+'</label>')
49
+ $form.append('<input type="submit" name="commit" value="Submit" class="'+this.options.submitBtnClass+'">')
50
+ $elem.append($form)
51
+ $form.on 'submit', (evt)->
52
+ evt.preventDefault()
53
+ $.ajax(url, {data: $form.serializeArray(), dataType: 'json', method: 'POST'}).done (data, textStatus, jqXHR)->
54
+ $elem.html(data.toString())
55
+ $elem.data('roles', data)
56
+ $elem.append(that._edit_btn())
@@ -0,0 +1,2 @@
1
+ window.I18n.defaultLocale = "<%= I18n.default_locale %>";
2
+ window.I18n.locale = "<%= I18n.locale %>";
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,13 @@
1
+ module EgovUtils
2
+ class District < AzaharaSchema::Attribute
3
+
4
+ def initialize
5
+ super(EgovUtils::Address, 'district', 'list')
6
+ end
7
+
8
+ def available_values
9
+ EgovUtils::Address.districts.collect{|d| [d[:name],d[:name]] }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module EgovUtils
2
+ class FullAddress < AzaharaSchema::Attribute
3
+
4
+ def initialize
5
+ super(EgovUtils::Address, 'full_address', 'string')
6
+ end
7
+
8
+ def arel_field
9
+ Arel::Nodes::NamedFunction.new 'CONCAT', [EgovUtils::Address.arel_table[:city], Arel::Nodes::SqlLiteral.new('\' \'') , EgovUtils::Address.arel_table[:street]]
10
+ end
11
+
12
+ def path
13
+ 'full_address'
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module EgovUtils
2
+ class Region < AzaharaSchema::Attribute
3
+
4
+ def initialize
5
+ super(EgovUtils::Address, 'region', 'list')
6
+ end
7
+
8
+ def available_values
9
+ EgovUtils::Address.regions.collect{|d| [d[:name],d[:name]] }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require 'egon_gate/egsb/messages/e37_vyhledej_adresu'
2
+
3
+ module EgovUtils
4
+ class AddressesController < ApplicationController
5
+
6
+ def validate_ruian
7
+ # TODO: shoud be in some validator - external class
8
+ addr_params = params.require(:address).permit(:city, :postcode, :street, :orientation_number, :house_number)
9
+ address = Address.new(addr_params)
10
+ if (address.city || address.postcode) && (( address.street && address.orientation_number ) || address.house_number)
11
+ message = EgonGate::Egsb::Messages::E37VyhledejAdresu.new
12
+ address.prepare_egon_message(message)
13
+ kobra_reqest = EgonGate::Kobra::Request.new
14
+ response = kobra_reqest.send_message(message)
15
+ if response.error?
16
+ respond_to do |format|
17
+ format.json { render json: { error: response.error_message }, status: 404 }
18
+ end
19
+ else
20
+ egon_address_info = message.parse_response( response.egsb_response )
21
+ address.from_egon_info(egon_address_info)
22
+ respond_to do |format|
23
+ format.json { render json: address }
24
+ end
25
+ end
26
+ else
27
+ respond_to do |format|
28
+ format.json { render json: { error: t(:error_not_found) }, status: 404 }
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ module EgovUtils
2
+ class ApplicationController < ::ApplicationController
3
+ protect_from_forgery with: :exception
4
+
5
+ layout 'application'
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require_dependency "egov_utils/application_controller"
2
+
3
+ module EgovUtils
4
+ class GroupsController < ApplicationController
5
+
6
+ load_and_authorize_resource
7
+
8
+ def create
9
+ respond_to do |format|
10
+ if @group.save
11
+ format.html{ redirect_to main_app.root_path, notice: t('success_created') }
12
+ format.json{ render json: @group, status: :created }
13
+ else
14
+ format.html{ render 'new' }
15
+ format.json{ render json: @group.errors.full_messages, status: :unprocessable_entity }
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def create_params
23
+ params.require(:group).permit(:name, :provider, :ldap_uid)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require_dependency "egov_utils/application_controller"
2
+
3
+ module EgovUtils
4
+ class RolesController < ApplicationController
5
+ def index
6
+ authorize! :manage, User
7
+ authorize! :manage, Group
8
+ @users = User.all
9
+ @groups = Group.all
10
+ end
11
+
12
+ def create
13
+ entity = params[:entity_class].safe_constantize.try(:find, params[:id])
14
+ return render_404 unless entity
15
+ authorize! :manage, entity
16
+ entity.roles = params[:roles].map(&:presence).compact if params[:roles].is_a?(Array)
17
+ if entity.save
18
+ respond_to do |format|
19
+ format.json { render json: entity.roles }
20
+ end
21
+ else
22
+ respond_to do |format|
23
+ format.json { render json: entity.errors.full_messages, status: :unprocessable_entity }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,83 @@
1
+ module EgovUtils
2
+ class SessionsController < ApplicationController
3
+
4
+ skip_before_action :verify_authenticity_token, only: [:create]
5
+
6
+ def new
7
+ if current_user.logged?
8
+ redirect_to main_app.root_path
9
+ end
10
+ end
11
+
12
+ def create
13
+ password_authentication
14
+ end
15
+
16
+ def destroy
17
+ reset_session
18
+ redirect_to login_path, notice: t(:notice_logout)
19
+ end
20
+
21
+ private
22
+
23
+ def password_authentication
24
+ user = User.authenticate(params[:session][:username], params[:session][:password], false)
25
+
26
+ if user.nil?
27
+ invalid_credentials
28
+ elsif user.new_record?
29
+ onthefly_creation_failed(user, {:login => user.login, :provider => user.provider })
30
+ else
31
+ # Valid user
32
+ if user.active?
33
+ successful_authentication(user)
34
+ else
35
+ handle_inactive_user(user)
36
+ end
37
+ end
38
+ end
39
+
40
+ def invalid_credentials(redirect_path=signin_path)
41
+ logger.warn "Failed login for '#{params[:session][:username]}' from #{request.remote_ip} at #{Time.now.utc}"
42
+ flash[:error] = t(:notice_account_invalid_credentials)
43
+ redirect_to redirect_path
44
+ end
45
+
46
+ def successful_authentication(user)
47
+ logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}"
48
+ # Valid user
49
+ self.logged_user = user
50
+ # generate a key and set cookie if autologin
51
+ if params[:autologin]
52
+ set_autologin_cookie(user)
53
+ end
54
+ redirect_to main_app.root_path
55
+ # redirect_back(fallback_location: root_path)
56
+ end
57
+
58
+ def handle_inactive_user(user, redirect_path=signin_path)
59
+ if user.locked?
60
+ account_locked(user, redirect_path)
61
+ else
62
+ account_pending(user, redirect_path)
63
+ end
64
+ end
65
+
66
+ def onthefly_creation_failed(user, provider_info={})
67
+ logger.warn "Failed onthefly_creation for '#{user.login}' (provider '#{user.provider}') from #{request.remote_ip} at #{Time.now.utc}"
68
+ flash[:error] = t(:notice_onthefly_failure)
69
+ redirect_to redirect_path
70
+ end
71
+
72
+ def account_pending(user, redirect_path=signin_path)
73
+ flash[:error] = t(:notice_account_pending)
74
+ redirect_to redirect_path
75
+ end
76
+
77
+ def account_locked(user, redirect_path=signin_path)
78
+ flash[:error] = t(:notice_account_locked)
79
+ redirect_to redirect_path
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,64 @@
1
+ require_dependency "egov_utils/application_controller"
2
+ require_dependency "egov_utils/auth_source"
3
+
4
+ module EgovUtils
5
+ class UsersController < ApplicationController
6
+
7
+ load_and_authorize_resource only: :index
8
+
9
+ def index
10
+ providers
11
+ end
12
+
13
+ def new
14
+ @user = User.new
15
+ end
16
+
17
+ def create
18
+ @user = User.new(create_params)
19
+ respond_to do |format|
20
+ if @user.save
21
+ format.html{ redirect_to main_app.root_path, notice: t('activerecord.successful.messages.created', model: Group.model_name.human) }
22
+ format.json{ render json: @user, status: :created }
23
+ else
24
+ format.html{ render 'new' }
25
+ format.json{ render json: @user.errors.full_messages, status: :unprocessable_entity }
26
+ end
27
+ end
28
+ end
29
+
30
+ def show
31
+ end
32
+
33
+ def approve
34
+ @user = User.find_by(id: params[:id])
35
+ render_404 and return unless @user || @user.active?
36
+ authorize!(:manage, User)
37
+ @user.update(active: true)
38
+ redirect_back(fallback_location: @user)
39
+ end
40
+
41
+ def search
42
+ authorize!(:read, User)
43
+ authorize!(:read, Group)
44
+ user_results = []; group_results = []
45
+ providers.each do |provider|
46
+ user_results.concat( provider.search_user(params[:q]) )
47
+ group_results.concat( provider.search_group(params[:q]) )
48
+ end if params[:q].present?
49
+ respond_to do |format|
50
+ format.json{ render json: {users: user_results, groups: group_results} }
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def providers
57
+ @providers = EgovUtils::AuthSource.providers.collect{|p| EgovUtils::AuthSource.new(p)}
58
+ end
59
+
60
+ def create_params
61
+ params.require(:user).permit(:login, :mail, :password, :password_confirmation, :provider, :firstname, :lastname)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,4 @@
1
+ module EgovUtils
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,40 @@
1
+ module EgovUtils
2
+ module GridHelper
3
+ def type_for_grid(type)
4
+ case type
5
+ when 'integer', 'float'
6
+ 'Number'
7
+ when 'string', 'list'
8
+ 'String'
9
+ when 'date', 'datetime'
10
+ 'Date'
11
+ when 'boolean'
12
+ 'Boolean'
13
+ else
14
+ raise "Undefined grid type for type #{type}"
15
+ end
16
+ end
17
+
18
+ def field_for_grid(attribute)
19
+ s = "\'"
20
+ s << attribute.name
21
+ s << '\': {path: "'
22
+ s << attribute.path
23
+ s << '", type: '
24
+ s << type_for_grid(attribute.type)
25
+ s << '}'
26
+ s
27
+ end
28
+
29
+ def column_for_grid(grid, attribute)
30
+ s = "{"
31
+ s << "field: '#{attribute.name}'"
32
+ s << ", title: '#{I18n.t('model_attributes.'+grid.model_i18n_key.to_s+'.'+attribute.name)}'"
33
+ s << ", columnTemplate: '<a href=\"#{polymorphic_path(grid.schema.model)}/{id}\">{#{attribute.name}}</div>'" if attribute.name == grid.schema.main_attribute_name
34
+ if attribute.type == 'list'
35
+ s << ", format: ( (value) -> I18n.t(value, {scope: 'activerecord.attributes.#{attribute.model.model_name.i18n_key}.#{attribute.name.to_s.pluralize}'}) ) "
36
+ end
37
+ s << "}"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module EgovUtils
2
+ module GroupsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module EgovUtils
2
+ module RolesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module EgovUtils
2
+ module UsersHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module EgovUtils
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module EgovUtils
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end