cmor_contact 0.0.1.pre

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 (122) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +32 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/config/cmor_contact_manifest.js +2 -0
  6. data/app/assets/javascripts/cmor/contact/application.js +13 -0
  7. data/app/assets/javascripts/cmor/contact/application/keep.js +0 -0
  8. data/app/assets/stylesheets/cmor/contact/application.css +15 -0
  9. data/app/assets/stylesheets/cmor/contact/application/keep.css +0 -0
  10. data/app/controllers/cmor/contact/application_controller.rb +7 -0
  11. data/app/controllers/cmor/contact/contact_requests_controller.rb +57 -0
  12. data/app/helpers/cmor/contact/application_helper.rb +6 -0
  13. data/app/jobs/cmor/contact/application_job.rb +6 -0
  14. data/app/jobs/cmor/contact/notify_new_contact_request_job.rb +25 -0
  15. data/app/mailers/cmor/contact/application_mailer.rb +8 -0
  16. data/app/mailers/cmor/contact/contact_request_mailer.rb +31 -0
  17. data/app/models/cmor/contact/application_record.rb +7 -0
  18. data/app/models/cmor/contact/contact_request.rb +36 -0
  19. data/app/views/cmor/contact/contact_request_mailer/notify.html.haml +7 -0
  20. data/app/views/cmor/contact/contact_request_mailer/notify.text.erb +5 -0
  21. data/app/views/cmor/contact/contact_requests/_form.haml +6 -0
  22. data/app/views/cmor/contact/contact_requests/_form_errors.haml +6 -0
  23. data/app/views/cmor/contact/contact_requests/new.haml +8 -0
  24. data/app/views/layouts/cmor/contact/application.html.erb +14 -0
  25. data/app/views/layouts/cmor/contact/mailer.html.erb +13 -0
  26. data/app/views/layouts/cmor/contact/mailer.text.erb +1 -0
  27. data/config/locales/de.yml +50 -0
  28. data/config/locales/en.yml +50 -0
  29. data/config/routes.rb +9 -0
  30. data/db/migrate/20170813142704_create_cmor_contact_contact_requests.rb +15 -0
  31. data/lib/cmor/contact.rb +10 -0
  32. data/lib/cmor/contact/configuration.rb +60 -0
  33. data/lib/cmor/contact/engine.rb +16 -0
  34. data/lib/cmor/contact/version.rb +7 -0
  35. data/lib/cmor_contact.rb +3 -0
  36. data/lib/generators/cmor/contact/install/install_generator.rb +26 -0
  37. data/lib/generators/cmor/contact/install/templates/initializer.rb +83 -0
  38. data/lib/generators/cmor/contact/install/templates/routes.source +3 -0
  39. data/lib/tasks/cmor_contact_tasks.rake +4 -0
  40. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  41. data/spec/dummy/config/initializers/i18n.rb +2 -0
  42. data/spec/dummy/config/storage.yml +34 -0
  43. data/spec/dummy/db/development.sqlite3 +0 -0
  44. data/spec/dummy/db/migrate/20190325174020_create_active_storage_tables.active_storage.rb +27 -0
  45. data/spec/dummy/db/migrate/20190325174040_create_cmor_contact_contact_requests.cmor_contact.rb +16 -0
  46. data/spec/dummy/db/test.sqlite3 +0 -0
  47. data/spec/dummy/log/development.log +108 -0
  48. data/spec/dummy/log/test.log +345 -0
  49. data/spec/dummy/tmp/development_secret.txt +1 -0
  50. data/spec/dummy~/Rakefile +6 -0
  51. data/spec/dummy~/app/assets/config/manifest.js +5 -0
  52. data/spec/dummy~/app/assets/javascripts/application.js +13 -0
  53. data/spec/dummy~/app/assets/javascripts/cable.js +13 -0
  54. data/spec/dummy~/app/assets/stylesheets/application.css +15 -0
  55. data/spec/dummy~/app/channels/application_cable/channel.rb +4 -0
  56. data/spec/dummy~/app/channels/application_cable/connection.rb +4 -0
  57. data/spec/dummy~/app/controllers/application_controller.rb +3 -0
  58. data/spec/dummy~/app/helpers/application_helper.rb +2 -0
  59. data/spec/dummy~/app/jobs/application_job.rb +2 -0
  60. data/spec/dummy~/app/mailers/application_mailer.rb +4 -0
  61. data/spec/dummy~/app/models/application_record.rb +3 -0
  62. data/spec/dummy~/app/views/layouts/application.html.erb +14 -0
  63. data/spec/dummy~/app/views/layouts/mailer.html.erb +13 -0
  64. data/spec/dummy~/app/views/layouts/mailer.text.erb +1 -0
  65. data/spec/dummy~/bin/bundle +3 -0
  66. data/spec/dummy~/bin/rails +4 -0
  67. data/spec/dummy~/bin/rake +4 -0
  68. data/spec/dummy~/bin/setup +38 -0
  69. data/spec/dummy~/bin/update +29 -0
  70. data/spec/dummy~/bin/yarn +11 -0
  71. data/spec/dummy~/config.ru +5 -0
  72. data/spec/dummy~/config/application.rb +26 -0
  73. data/spec/dummy~/config/boot.rb +5 -0
  74. data/spec/dummy~/config/cable.yml +10 -0
  75. data/spec/dummy~/config/database.yml +25 -0
  76. data/spec/dummy~/config/environment.rb +5 -0
  77. data/spec/dummy~/config/environments/development.rb +54 -0
  78. data/spec/dummy~/config/environments/production.rb +91 -0
  79. data/spec/dummy~/config/environments/test.rb +42 -0
  80. data/spec/dummy~/config/initializers/application_controller_renderer.rb +6 -0
  81. data/spec/dummy~/config/initializers/assets.rb +14 -0
  82. data/spec/dummy~/config/initializers/backtrace_silencers.rb +7 -0
  83. data/spec/dummy~/config/initializers/cmor_contact.rb +83 -0
  84. data/spec/dummy~/config/initializers/cookies_serializer.rb +5 -0
  85. data/spec/dummy~/config/initializers/filter_parameter_logging.rb +4 -0
  86. data/spec/dummy~/config/initializers/inflections.rb +16 -0
  87. data/spec/dummy~/config/initializers/mime_types.rb +4 -0
  88. data/spec/dummy~/config/initializers/wrap_parameters.rb +14 -0
  89. data/spec/dummy~/config/locales/en.yml +33 -0
  90. data/spec/dummy~/config/puma.rb +56 -0
  91. data/spec/dummy~/config/routes.rb +3 -0
  92. data/spec/dummy~/config/secrets.yml +32 -0
  93. data/spec/dummy~/config/spring.rb +6 -0
  94. data/spec/dummy~/db/development.sqlite3 +0 -0
  95. data/spec/dummy~/db/migrate/20170813150718_create_cmor_contact_contact_requests.cmor_contact.rb +16 -0
  96. data/spec/dummy~/db/schema.rb +27 -0
  97. data/spec/dummy~/db/test.sqlite3 +0 -0
  98. data/spec/dummy~/log/test.log +0 -0
  99. data/spec/dummy~/package.json +5 -0
  100. data/spec/dummy~/public/404.html +67 -0
  101. data/spec/dummy~/public/422.html +67 -0
  102. data/spec/dummy~/public/500.html +66 -0
  103. data/spec/dummy~/public/apple-touch-icon-precomposed.png +0 -0
  104. data/spec/dummy~/public/apple-touch-icon.png +0 -0
  105. data/spec/dummy~/public/favicon.ico +0 -0
  106. data/spec/factories/cmor_contact_contact_requests.rb +10 -0
  107. data/spec/fixtures/cmor/contact/contact_request_mailer/notify +3 -0
  108. data/spec/jobs/cmor/contact/notify_new_contact_request_job_spec.rb +22 -0
  109. data/spec/mailers/cmor/contact/contact_request_mailer_spec.rb +24 -0
  110. data/spec/mailers/previews/cmor/contact/contact_request_mailer_preview.rb +11 -0
  111. data/spec/models/cmor/contact/contact_request_spec.rb +48 -0
  112. data/spec/models/generic_spec.rb +49 -0
  113. data/spec/models/i18n_spec.rb +40 -0
  114. data/spec/rails_helper.rb +62 -0
  115. data/spec/spec_helper.rb +96 -0
  116. data/spec/support/action_mailer.rb +13 -0
  117. data/spec/support/active_job.rb +9 -0
  118. data/spec/support/capybara.rb +1 -0
  119. data/spec/support/factory_bot.rb +9 -0
  120. data/spec/support/rao-shoulda_matchers.rb +5 -0
  121. data/spec/support/shoulda_matchers.rb +8 -0
  122. metadata +429 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bd3e49ab47604a45fe4cb0f00be068df69227366bd31c385fbf077dd900f7149
4
+ data.tar.gz: d7caba59cf0a2466bedbda67cd6bd4481d44f2980d6b434fe76e23aac99762e9
5
+ SHA512:
6
+ metadata.gz: c900d3e78299ee87150cfd62ba8048cabdb5b04da36ea96807df20c9be6aed00dee07bc3a2f185eeed7246b678e7277adb4765c01ea6d26e229baa3ac62b2b21
7
+ data.tar.gz: 9cfb94b37103c387e77438ba7a0e6d53d1e2c390f13d351ea731e34842b27a8ac944d8ff1104b4e2304695b21f9cba7c465756342d2f0250a53ca2cfbad89d74
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Roberto Vasquez Angel
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,32 @@
1
+ # Cmor::Contact
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 'cmor_contact'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install cmor_contact
22
+ ```
23
+
24
+ ## Configuration
25
+
26
+ You can use the environment variable CMOR_CONTACT_RECIPIENTS to override the recipients in config/initializers/cmor_contact.rb
27
+
28
+ ## Contributing
29
+ Contribution directions go here.
30
+
31
+ ## License
32
+ 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,19 @@
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 = 'Cmor::Contact'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rails/dummy/tasks'
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/cmor/contact .js
2
+ //= link_directory ../stylesheets/cmor/contact .css
@@ -0,0 +1,13 @@
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_tree ./application
@@ -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 ./application
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ module Cmor
2
+ module Contact
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ module Cmor
2
+ module Contact
3
+ class ContactRequestsController < Cmor::Contact::Configuration.base_controller.constantize
4
+ before_action :initialize_resource, only: [:index, :new]
5
+ before_action :initialize_resource_for_create, only: [:create]
6
+
7
+ respond_to :html
8
+ responders :flash
9
+
10
+ def self.resource_class
11
+ Cmor::Contact::ContactRequest
12
+ end
13
+
14
+ def index
15
+ new
16
+ render :new
17
+ end
18
+
19
+ def new; end
20
+
21
+ def create
22
+ @resource.ip_address = request.remote_ip
23
+ if @resource.save
24
+ respond_with @resource, location: after_create_url
25
+ else
26
+ respond_with @resource
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def initialize_resource_for_create
33
+ @resource = initialize_scope.new(permitted_params)
34
+ end
35
+
36
+ def initialize_resource
37
+ @resource = initialize_scope.new
38
+ end
39
+
40
+ def initialize_scope
41
+ resource_class
42
+ end
43
+
44
+ def resource_class
45
+ self.class.resource_class
46
+ end
47
+
48
+ def permitted_params
49
+ params.require(:contact_request).permit(:nickname, :name, :email, :phone, :message, :accept_terms_of_service)
50
+ end
51
+
52
+ def after_create_url
53
+ Cmor::Contact::Configuration.after_create_url.call(self)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ module Cmor
2
+ module Contact
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Cmor
2
+ module Contact
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ module Cmor::Contact
2
+ class NotifyNewContactRequestJob < ApplicationJob
3
+ queue_as :contact_requests
4
+
5
+ def perform(contact_request_id)
6
+ load_contact_request(contact_request_id)
7
+ deliver
8
+ mark_as_notified
9
+ end
10
+
11
+ private
12
+
13
+ def load_contact_request(id)
14
+ @contact_request = ContactRequest.find(id)
15
+ end
16
+
17
+ def deliver
18
+ ContactRequestMailer.notify(@contact_request).deliver_now
19
+ end
20
+
21
+ def mark_as_notified
22
+ @contact_request.update(notified_at: Time.zone.now)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module Cmor
2
+ module Contact
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module Cmor::Contact
2
+ class ContactRequestMailer < ApplicationMailer
3
+
4
+ # Subject can be set in your I18n file at config/locales/en.yml
5
+ # with the following lookup:
6
+ #
7
+ # en.contact_request_mailer.notify.subject
8
+ #
9
+ def notify(contact_request)
10
+ @contact_request = contact_request
11
+
12
+ mail to: notification_recipients,
13
+ from: notification_sender(contact_request),
14
+ subject: notification_subject
15
+ end
16
+
17
+ private
18
+
19
+ def notification_subject
20
+ default_i18n_subject(application_name: Rails.application.class.to_s.split('::').first.underscore.humanize.titleize)
21
+ end
22
+
23
+ def notification_sender(contact_request)
24
+ "#{contact_request.name} <#{contact_request.email}>"
25
+ end
26
+
27
+ def notification_recipients
28
+ ENV.fetch('CMOR_CONTACT_RECIPIENTS') { Cmor::Contact::Configuration.recipients[Rails.env] }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Cmor
2
+ module Contact
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Cmor::Contact
2
+ class ContactRequest < ApplicationRecord
3
+ validates :name, presence: true
4
+ validates :email, presence: true
5
+ validates :phone, presence: true
6
+ validates :ip_address, presence: true
7
+ validates :message, presence: true
8
+ validates :accept_terms_of_service, acceptance: true
9
+
10
+ module SpamProtection
11
+ attr_accessor :nickname
12
+
13
+ def save
14
+ if nickname.present?
15
+ valid?
16
+ return true
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end
22
+
23
+ module Notification
24
+ def self.included(base)
25
+ base.after_save :notify, if: -> { notified_at.nil? }
26
+ end
27
+
28
+ def notify
29
+ NotifyNewContactRequestJob.perform_later(id)
30
+ end
31
+ end
32
+
33
+ prepend SpamProtection
34
+ include Notification
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ %h1= t('.title')
2
+
3
+ %ul
4
+ - @contact_request.attributes.each do |attribute, value|
5
+ %li
6
+ %span.key= @contact_request.class.human_attribute_name(attribute)
7
+ %span.value= value
@@ -0,0 +1,5 @@
1
+ <%= t('.title') %>
2
+
3
+ <% @contact_request.attributes.each do |attribute, value| %>
4
+ <%= @contact_request.class.human_attribute_name(attribute) %>: <%= value %>
5
+ <% end %>
@@ -0,0 +1,6 @@
1
+ = form.input :name
2
+ = form.input :email
3
+ = form.input :nickname, input_html: { style: 'display: none;' }, label_html: { style: 'display: none;' }
4
+ = form.input :phone
5
+ = form.input :message, as: :text
6
+ = form.input :accept_terms_of_service
@@ -0,0 +1,6 @@
1
+ - if resource.errors.any?
2
+ .error-explanation.alert.alert-danger
3
+ .error-heading= t('errors.template.header', count: resource.errors.count, model: resource.model_name.human)
4
+ %ul
5
+ - resource.errors.full_messages.each do |msg|
6
+ %li= msg
@@ -0,0 +1,8 @@
1
+ %h1= t('.title')
2
+
3
+ = Cmor::Contact::Configuration.additional_contact_information.call(self) if Cmor::Contact::Configuration.additional_contact_information.respond_to?(:call)
4
+
5
+ = simple_form_for(@resource) do |f|
6
+ = render 'form_errors', resource: f.object
7
+ = render 'form', form: f
8
+ = f.submit class: 'btn btn-primary'
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Cmor contact</title>
5
+ <%= stylesheet_link_tag "cmor/contact/application", media: "all" %>
6
+ <%= javascript_include_tag "cmor/contact/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -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 %>
@@ -0,0 +1,50 @@
1
+ de:
2
+ classes:
3
+ cmor/contact/engine: Kontakt
4
+ activerecord:
5
+ models:
6
+ cmor/contact/contact_request:
7
+ one: Kontaktanfrage
8
+ other: Kontaktanfragen
9
+ attributes:
10
+ cmor/contact/contact_request:
11
+ id: ID
12
+ accept_terms_of_service: 'Hiermit erlaube ich dem Seitenbetreiber die Nutzung meiner Daten zwecks Beantwortung dieser Kontaktanfrage.'
13
+ name: Name
14
+ email: E-Mail
15
+ phone: Telefonnummer
16
+ ip_address: IP Adresse
17
+ message: Nachricht
18
+ notified_at: Benachrichtigt am
19
+ created_at: Erstellt am
20
+ updated_at: Aktualisiert am
21
+ additional_actions: Zusatzliche Aktionen
22
+ cmor:
23
+ contact:
24
+ contact_requests:
25
+ new:
26
+ title: "Kontaktanfrage"
27
+ contact_request_mailer:
28
+ notify:
29
+ subject: "[%{application_name}] Neue Kontaktanfrage"
30
+ title: "Neue Kontaktanfrage"
31
+ flash:
32
+ cmor:
33
+ contact:
34
+ contact_requests:
35
+ create:
36
+ notice: "Ihre Kontaktanfrage wurde versandt."
37
+ helpers:
38
+ submit:
39
+ contact_request:
40
+ create: Absenden
41
+ routes:
42
+ cmor_contact_engine: kontakt
43
+ contact_requests: anfrage
44
+ simple_form:
45
+ placeholders:
46
+ contact_request:
47
+ name: "Max Mustermann"
48
+ email: "max.mustermann@example.com"
49
+ message: "Meine Nachricht"
50
+ phone: "+49 69 12345678"