mr_common 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -9
- data/app/controllers/mr_common/dashboard_controller.rb +1 -0
- data/app/controllers/mr_common/pre_registrations/import_controller.rb +26 -0
- data/app/controllers/mr_common/pre_registrations/pre_registrations_controller.rb +48 -0
- data/app/controllers/mr_common/registrations/confirmations_controller.rb +54 -0
- data/app/controllers/mr_common/registrations/export_controller.rb +35 -4
- data/app/controllers/mr_common/registrations/public_controller.rb +24 -1
- data/app/controllers/mr_common/registrations/registrations_controller.rb +2 -0
- data/app/controllers/mr_common/registrations/resend_notifications_controller.rb +27 -0
- data/app/controllers/mr_common/registrations/success_controller.rb +1 -0
- data/app/mailers/mr_common/registration_mailer.rb +13 -3
- data/app/models/concerns/mr_common/csv_exportable.rb +6 -2
- data/app/models/mr_common/country.rb +9 -0
- data/app/models/mr_common/csv_renderer.rb +38 -0
- data/app/models/mr_common/pattern.rb +10 -0
- data/app/models/mr_common/pre_registration.rb +52 -0
- data/app/models/mr_common/pre_registration_importer.rb +91 -0
- data/app/models/mr_common/registration.rb +11 -2
- data/app/models/mr_common/registration_decorator.rb +20 -0
- data/app/models/mr_common/reminder.rb +6 -0
- data/app/models/mr_common/timezone.rb +5 -0
- data/app/views/layouts/mr_common/_navigation.html.erb +7 -0
- data/app/views/mr_common/pre_registrations/import/new.html.erb +27 -0
- data/app/views/mr_common/pre_registrations/pre_registrations/_form.html.erb +29 -0
- data/app/views/mr_common/pre_registrations/pre_registrations/index.html.erb +32 -0
- data/{lib/generators/mr_common/views/templates/mr_common/registrations/public → app/views/mr_common/pre_registrations/pre_registrations}/new.html.erb +2 -1
- data/{lib/generators/mr_common/views/templates/mr_common/registration_mailer/confirmation.html.erb → app/views/mr_common/registration_mailer/confirmed_registration.html.erb} +3 -0
- data/app/views/mr_common/registration_mailer/{confirmation.text.erb → confirmed_registration.text.erb} +2 -0
- data/app/views/mr_common/registration_mailer/revoked_registration.html.erb +5 -0
- data/app/views/mr_common/registration_mailer/revoked_registration.text.erb +6 -0
- data/app/views/mr_common/registration_mailer/unconfirmed_registration.html.erb +3 -0
- data/app/views/mr_common/registration_mailer/unconfirmed_registration.text.erb +4 -0
- data/app/views/mr_common/registrations/registrations/_form.html.erb +6 -0
- data/app/views/mr_common/registrations/registrations/index.html.erb +4 -0
- data/app/views/mr_common/registrations/registrations/show.html.erb +34 -3
- data/config/routes.rb +13 -1
- data/db/migrate/20190522151523_create_pre_registrations.rb +12 -0
- data/db/migrate/20190530220614_add_confirmed_to_registrations.rb +5 -0
- data/lib/generators/mr_common/controllers/USAGE +9 -0
- data/lib/generators/mr_common/controllers/controllers_generator.rb +24 -0
- data/lib/generators/mr_common/mailers/USAGE +16 -0
- data/lib/generators/mr_common/mailers/mailers_generator.rb +31 -0
- data/lib/generators/mr_common/models/USAGE +8 -0
- data/lib/generators/mr_common/models/models_generator.rb +23 -0
- data/lib/generators/mr_common/views/USAGE +1 -4
- data/lib/generators/mr_common/views/views_generator.rb +7 -8
- data/lib/mr_common.rb +14 -2
- data/lib/mr_common/version.rb +1 -1
- data/spec/dummy/config/initializers/mr_common.rb +10 -0
- data/spec/dummy/db/schema.rb +14 -4
- data/spec/dummy/log/development.log +1969 -50958
- data/spec/dummy/log/test.log +647 -14437
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-G/-gyHBJNssgJVEwk7sD1F9nK_dT1D1R5NjlAvcESJxME.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3d/3DI5adLgOKj6Q76fFxrLy_hKYkrlht0MEWksNkYgoXk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3n/3NK03OBfUwDPKVYV6_11AOo3IGNUQPed4dqB-Ddv6-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7d/7DbSMErmkAd0cL6q_WyLMfx7gLYQB0h9smKZ0xGjOjY.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9m/9MK1AG2zx0HVFVRULpQQnQQY0HiNroKnYEz2FUBzw6k.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/CO/cojbSP1f9tYoCyycggqXgW3OYb3atOkOpf-h-Axn36o.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/H6/h6GO-mL-rzWHmoiFw-uuwdny5zj_zSb1Xzun5jkza5k.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LG/LG2fyButWQgZoNvH4qD2dBMQhl35dSysUbxsvw_2PA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LZ/lZ_yNthdvXeWexZW9TZuMWs6lZBLMEF5rp7aA5Bl9uU.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lh/LhBzrZLgp6fzHcgWFt_B-TqHzHaPyKv9Uk67brUycZE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/N-/N-7bXt4Ck0q2VWzHHuRPKL0a0CH_1W_eyAU59tZraxE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Pi/PI3-Xhs-TBYEqgGeCf3hWGn6vj1qCdqBqgYRY2jNr4Q.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QQ/qqtvJX4CrLCTv4jjIg0LwoNxJUyDpLus0RIbg6D6muk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Se/setx2SgK-JX4zwjgbekiVnvWJnbp0-2XnO0TQJfCOHU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ue/UecY7KKAHkP6oiqpx1zkXAL9WWGqWdhgqhixQyJ82is.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VF/VfH7y0fTeHy8aLBK_bu5OKprS0c1-GCHUzrMzp-O0_I.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WC/WCV-7lpbJsFHZueodYuN5542p56UPNtby1LVPUjvuJU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WV/wvfl97Gci1mpw00EFHWc0Q9x0DLBar03PTd9BrZ7MF0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/eP/ePjuIgA1bwfnJWATz7q6EjGfNnpvYEaKW_2aozCJFBQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ge/GegLYwRNBYKvfYR1-WWnx3ssHerCO6M94VPxwUTYHtM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/h9/H95rpLdUakuAt6lpkUhlZvxsYlSb-VrfpiznZYmWnGo.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p_/P_kWJKPROj6qDVkyzNQgx8wZmba8YaTqtWMQyGHFtuY.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/w3/w34qFl6hbbodwCEAr9Px_jzso7svjewL5BaOf6QMIN4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wi/wi_OyVKzMxj9CcM3e2Bhab5PQSg4wh0nD-7QJQ3SVPw.cache +1 -0
- data/spec/dummy/tmp/pids/server.pid +1 -1
- data/spec/factories/registrations.rb +5 -5
- data/spec/models/registration_spec.rb +40 -0
- metadata +80 -11
- data/app/helpers/mr_common/form_helper.rb +0 -11
- data/app/models/mr_common/csv_exporter.rb +0 -35
- data/app/models/mr_common/default_csv_export_adapter.rb +0 -23
- data/app/views/mr_common/registration_mailer/confirmation.html.erb +0 -4
- data/lib/generators/mr_common/views/templates/mr_common/registration_mailer/confirmation.text.erb +0 -6
- data/lib/generators/mr_common/views/templates/mr_common/registrations/success/index.html.erb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54451845d3b9872d8263616b7cd840d794e9ec6c5ad523065e3a9706bb426e3e
|
4
|
+
data.tar.gz: '0564509763ef97f22dbec7798998ad2c7f590387413e8a3842a094cec50d551f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca8b97d5a0d98de6fc4d0fb955367df3d4460bccb8e01be610b9763af7c954415c7d393c9e6e2d9846f8245a00c1d803ed22b1cee7e78196b00bdb64aa488ce6
|
7
|
+
data.tar.gz: 22e0354f7d4661a67529ecdc5fa26db58518c9f3c792183de385364596983c724377a99943f78fa8c181a1a819f76fc6287b20788e73c9eba7e8a9b2ee7af13c
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Common utilities extracted from starter-reg-site for use elsewhere
|
|
4
4
|
## Features
|
5
5
|
* Dashboard at the mount point that relies on the host app for authentication
|
6
6
|
* [MrCommon::Registration](/doc/mr_common/registration.md) - default registration model and controller with csv export exposed via the dashboard
|
7
|
+
* MrCommon::PreRegistration - whitelist firstname + lastname combos, or emails for automatic registration confirmation, requires `MrCommon.registration_confirmation_strategy == :pre_register`
|
7
8
|
* [MrCommon::Reminder](/doc/mr_common/reminder.md) - model for generating downloadable ical reminders
|
8
9
|
* MrCommon::Country - convenient wrapper around the Carmen gem
|
9
10
|
* MrCommon::Pattern - a utility class for sharing common regex patterns
|
@@ -16,7 +17,7 @@ Add to Gemfile
|
|
16
17
|
|
17
18
|
```ruby
|
18
19
|
# Gemfile
|
19
|
-
gem 'mr_common', '~>
|
20
|
+
gem 'mr_common', '~> 2'
|
20
21
|
```
|
21
22
|
|
22
23
|
Add to routes.rb
|
@@ -29,10 +30,13 @@ mount MrCommon::Engine, at: '/common'
|
|
29
30
|
root to: "mr_common/registrations/public#new"
|
30
31
|
```
|
31
32
|
|
32
|
-
|
33
|
+
Copy model/controller/views into the host app for overriding/customizing.
|
33
34
|
|
34
35
|
```
|
36
|
+
$ bin/rails g mr_common:models
|
35
37
|
$ bin/rails g mr_common:views
|
38
|
+
$ bin/rails g mr_common:mailers
|
39
|
+
$ bin/rails g mr_common:controllers
|
36
40
|
```
|
37
41
|
|
38
42
|
Configure an initializer if you need different values than the defaults listed here
|
@@ -46,19 +50,36 @@ MrCommon.current_user_authorization_method_name = :mr_common_admin?
|
|
46
50
|
MrCommon.logout_path_helper = :destroy_user_session_path
|
47
51
|
MrCommon.logout_path_method = :delete
|
48
52
|
MrCommon.sign_in_path_helper = :new_user_session_path
|
49
|
-
MrCommon.registration_success_notice = "Registration completed successfully."
|
50
|
-
MrCommon.registration_failure_alert = "Registration could not be completed."
|
51
53
|
MrCommon.host_app_layout = "application"
|
52
|
-
|
53
|
-
|
54
|
+
|
55
|
+
# Alert/Notice strings
|
56
|
+
MrCommon.registration_failure_alert = "Registration could not be completed."
|
57
|
+
MrCommon.registration_success_notice = "Registration created successfully."
|
58
|
+
|
59
|
+
# RegistrationMailer subjects
|
60
|
+
MrCommon.registration_confirmed_subject = "Your registration is confirmed."
|
61
|
+
MrCommon.registration_unconfirmed_subject = "Thanks for your interest."
|
62
|
+
MrCommon.registration_revoked_subject = "Your registration is not confirmed."
|
63
|
+
|
64
|
+
# Dashboard Title
|
65
|
+
MrCommon.title = "Mreach Common Utils"
|
66
|
+
|
67
|
+
# All Registrations will be automatically confirmed (default)
|
68
|
+
# MrCommon.registration_confirmation_strategy = :auto
|
69
|
+
|
70
|
+
# Registrations will be confirmed automatically if a PreRegistration is found
|
71
|
+
# MrCommon.registration_confirmation_strategy = :pre_register
|
72
|
+
|
73
|
+
# An admin will need to log in and click the confirm button for each registration
|
74
|
+
# MrCommon.registration_confirmation_strategy = :manual
|
54
75
|
```
|
55
76
|
|
56
77
|
## Development
|
57
78
|
|
58
79
|
1. `gem install foreman mailcatcher`
|
59
|
-
1.
|
60
|
-
1.
|
61
|
-
1.
|
80
|
+
1. clone
|
81
|
+
1. bundle Install
|
82
|
+
1. don't use yarn/npm, engines have to use old school sprockets manifests
|
62
83
|
1. run `bin/rails run` to start the app + mailcatcher.
|
63
84
|
|
64
85
|
## License
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
|
5
|
+
module MrCommon
|
6
|
+
module PreRegistrations
|
7
|
+
# Implements PreRegistration import for the admin panel. Expects the user to
|
8
|
+
# upload a CSV file with a header line and columns ordered like:
|
9
|
+
# first_name, last_name, email
|
10
|
+
class ImportController < BaseController
|
11
|
+
def new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
csv = import_params[:csv_file]
|
16
|
+
importer = MrCommon::PreRegistrationImporter.new(csv.read)
|
17
|
+
result = importer.import
|
18
|
+
redirect_to new_pre_registrations_import_path, notice: "Imported #{result.created} and skipped #{result.skipped} duplicate or invalid entries."
|
19
|
+
end
|
20
|
+
|
21
|
+
def import_params
|
22
|
+
params.require(:import).permit(:csv_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MrCommon
|
4
|
+
module PreRegistrations
|
5
|
+
class PreRegistrationsController < BaseController
|
6
|
+
def index
|
7
|
+
@pre_registration = PreRegistration.order(email: :asc)
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@pre_registration = PreRegistration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@pre_registration = PreRegistration.new(pre_registration_params)
|
16
|
+
|
17
|
+
if @pre_registration.save
|
18
|
+
redirect_to pre_registrations_path, notice: "Pre-registration saved."
|
19
|
+
else
|
20
|
+
flash.now[:alert] = "There was a problem saving the pre-registration."
|
21
|
+
render :new, status: :unprocessable_entity
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
@pre_registration = PreRegistration.find(params[:id])
|
27
|
+
|
28
|
+
if @pre_registration.destroy
|
29
|
+
redirect_to pre_registrations_path, notice: "Pre-registration deleted."
|
30
|
+
else
|
31
|
+
redirect_to pre_registrations_path, notice: "There was a problem deleting the pre-registration."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def pre_registration_params
|
38
|
+
params.require(
|
39
|
+
:confirmed_registration
|
40
|
+
).permit(
|
41
|
+
:email,
|
42
|
+
:first_name,
|
43
|
+
:last_name
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MrCommon
|
4
|
+
module Registrations
|
5
|
+
class ConfirmationsController < BaseController
|
6
|
+
# Confirm a registration.
|
7
|
+
def create
|
8
|
+
find_registration
|
9
|
+
|
10
|
+
if confirm_registration
|
11
|
+
send_notification
|
12
|
+
redirect_to @registration, notice: "Registration confirmed. Registrant will receive an email."
|
13
|
+
else
|
14
|
+
Rails.logger.debug(@registration.errors.full_messages)
|
15
|
+
redirect_to @registration, alert: "Unable to confirm registration"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Revoke a registration's confirmation.
|
20
|
+
def destroy
|
21
|
+
find_registration
|
22
|
+
|
23
|
+
if unconfirm_registration
|
24
|
+
send_notification
|
25
|
+
redirect_to @registration, notice: "Confirmation revoked. Registrant will receive an email."
|
26
|
+
else
|
27
|
+
Rails.logger.debug(@registration.errors.full_messages)
|
28
|
+
redirect_to @registration, alert: "Unable to revoke confirmation"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def find_registration
|
34
|
+
@registration = MrCommon::Registration.find(params[:registration_id])
|
35
|
+
end
|
36
|
+
|
37
|
+
def confirm_registration
|
38
|
+
@registration.update(confirmed: true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def unconfirm_registration
|
42
|
+
@registration.update(confirmed: false)
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_notification
|
46
|
+
if @registration.confirmed?
|
47
|
+
RegistrationMailer.confirmed_registration(@registration.id).deliver_now
|
48
|
+
else
|
49
|
+
RegistrationMailer.revoked_registration(@registration.id).deliver_now
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -3,12 +3,43 @@
|
|
3
3
|
module MrCommon
|
4
4
|
module Registrations
|
5
5
|
class ExportController < BaseController
|
6
|
+
# Generates CSV data and sends as file download.
|
6
7
|
def index
|
7
|
-
send_data(
|
8
|
-
Registration.as_csv(format_rules: Registration.try(:csv_format_rules)),
|
9
|
-
filename: "Registrations-#{Date.today}.csv"
|
10
|
-
)
|
8
|
+
send_data(registrations_csv, filename: filename)
|
11
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def registrations_csv
|
14
|
+
fields = csv_fields
|
15
|
+
fields.delete(:pre_registered?) unless MrCommon.registration_confirmation_strategy == :pre_register
|
16
|
+
|
17
|
+
CSVRenderer.new(
|
18
|
+
collection: MrCommon::Registration.all,
|
19
|
+
decorator: MrCommon::RegistrationDecorator,
|
20
|
+
fields: fields
|
21
|
+
).render
|
22
|
+
end
|
23
|
+
|
24
|
+
def csv_fields
|
25
|
+
[
|
26
|
+
:first_name,
|
27
|
+
:last_name,
|
28
|
+
:email,
|
29
|
+
:company_name,
|
30
|
+
:telephone,
|
31
|
+
:zip_code,
|
32
|
+
:country,
|
33
|
+
:pre_registered?,
|
34
|
+
:confirmed?,
|
35
|
+
:created_at,
|
36
|
+
:updated_at
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def filename
|
41
|
+
"Registrations-#{Date.today}.csv"
|
42
|
+
end
|
12
43
|
end
|
13
44
|
end
|
14
45
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module MrCommon
|
4
4
|
module Registrations
|
5
|
+
# Implements public Registration actions available from the landing page.
|
5
6
|
class PublicController < PublicBaseController
|
6
7
|
def new
|
7
8
|
@registration = Registration.new
|
@@ -9,9 +10,10 @@ module MrCommon
|
|
9
10
|
|
10
11
|
def create
|
11
12
|
@registration = Registration.new(registration_params)
|
13
|
+
@registration.confirmed = true if should_confirm_registration?
|
12
14
|
|
13
15
|
if @registration.save
|
14
|
-
|
16
|
+
send_notification
|
15
17
|
redirect_to registrations_success_index_path, notice: MrCommon.registration_success_notice
|
16
18
|
else
|
17
19
|
flash.now[:alert] = MrCommon.registration_failure_alert if MrCommon.registration_failure_alert.present?
|
@@ -21,6 +23,27 @@ module MrCommon
|
|
21
23
|
|
22
24
|
private
|
23
25
|
|
26
|
+
def should_confirm_registration?
|
27
|
+
case MrCommon.registration_confirmation_strategy
|
28
|
+
when :auto
|
29
|
+
true
|
30
|
+
when :pre_register
|
31
|
+
PreRegistration.exists_for?(@registration)
|
32
|
+
when :manual
|
33
|
+
false
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def send_notification
|
40
|
+
if @registration.confirmed?
|
41
|
+
RegistrationMailer.confirmed_registration(@registration.id).deliver_now
|
42
|
+
else
|
43
|
+
RegistrationMailer.unconfirmed_registration(@registration.id).deliver_now
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
24
47
|
def registration_params
|
25
48
|
params.require(
|
26
49
|
:registration
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module MrCommon
|
4
4
|
module Registrations
|
5
|
+
# Admin CRUD for Registrations.
|
5
6
|
class RegistrationsController < BaseController
|
6
7
|
def index
|
7
8
|
@registrations = Registration.order(first_name: :asc, last_name: :asc)
|
@@ -63,6 +64,7 @@ module MrCommon
|
|
63
64
|
:company_name,
|
64
65
|
:telephone,
|
65
66
|
:job_title,
|
67
|
+
:confirmed,
|
66
68
|
:contact_via_email,
|
67
69
|
:contact_via_phone,
|
68
70
|
)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MrCommon
|
4
|
+
module Registrations
|
5
|
+
class ResendNotificationsController < BaseController
|
6
|
+
def create
|
7
|
+
find_registration
|
8
|
+
send_notification
|
9
|
+
redirect_to @registration, notice: "Notification sent."
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def find_registration
|
15
|
+
@registration = MrCommon::Registration.find(params[:registration_id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_notification
|
19
|
+
if @registration.confirmed?
|
20
|
+
MrCommon::RegistrationMailer.confirmed_registration(@registration.id).deliver_now
|
21
|
+
else
|
22
|
+
MrCommon::RegistrationMailer.unconfirmed_registration(@registration.id).deliver_now
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,10 +2,20 @@
|
|
2
2
|
|
3
3
|
module MrCommon
|
4
4
|
class RegistrationMailer < ApplicationMailer
|
5
|
-
def
|
5
|
+
def unconfirmed_registration(registration_id)
|
6
6
|
@registration = Registration.find(registration_id)
|
7
|
-
@
|
8
|
-
|
7
|
+
mail(to: @registration.email, subject: MrCommon.registration_unconfirmed_subject)
|
8
|
+
end
|
9
|
+
|
10
|
+
def confirmed_registration(registration_id)
|
11
|
+
@registration = Registration.find(registration_id)
|
12
|
+
@reminders = Reminder.for_confirmed_notice
|
13
|
+
mail(to: @registration.email, subject: MrCommon.registration_confirmed_subject)
|
14
|
+
end
|
15
|
+
|
16
|
+
def revoked_registration(registration_id)
|
17
|
+
@registration = Registration.find(registration_id)
|
18
|
+
mail(to: @registration.email, subject: MrCommon.registration_revoked_subject)
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
@@ -5,8 +5,12 @@ module MrCommon
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
class_methods do
|
8
|
-
def as_csv(
|
9
|
-
|
8
|
+
def as_csv(scope: :all, fields: nil, decorator: nil)
|
9
|
+
CSVRenderer.new(
|
10
|
+
collection: self.send(scope),
|
11
|
+
fields: fields || self.column_names,
|
12
|
+
decorator: decorator
|
13
|
+
).render
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module MrCommon
|
4
|
+
# Wrapper doing common tasks with the Carmen gem
|
4
5
|
class Country
|
5
6
|
class << self
|
7
|
+
# @param top [Array<String>] a list of country codes that should be
|
8
|
+
# promoted to the top of the list.
|
9
|
+
# @return [Array<Array<String, String>>] an array of label-value pairs for
|
10
|
+
# building country select options.
|
6
11
|
def all(top = [])
|
7
12
|
all_countries = label_value_pairs.dup
|
8
13
|
|
@@ -13,14 +18,18 @@ module MrCommon
|
|
13
18
|
all_countries
|
14
19
|
end
|
15
20
|
|
21
|
+
# @return [Array<String>] two letter country codes in alphabetical order
|
16
22
|
def codes
|
17
23
|
Carmen::Country.all.map(&:code).sort
|
18
24
|
end
|
19
25
|
|
26
|
+
# @return [Array<String>] country names in alphabetical order
|
20
27
|
def names
|
21
28
|
Carmen::Country.all.map(&:name).sort
|
22
29
|
end
|
23
30
|
|
31
|
+
# @param code [String] a two letter country code
|
32
|
+
# @return [String] the name of the country for that code
|
24
33
|
def name_for(code)
|
25
34
|
Carmen::Country.alpha_2_coded(code).name
|
26
35
|
end
|