cmor_contact 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +32 -0
- data/Rakefile +19 -0
- data/app/assets/config/cmor_contact_manifest.js +2 -0
- data/app/assets/javascripts/cmor/contact/application.js +13 -0
- data/app/assets/javascripts/cmor/contact/application/keep.js +0 -0
- data/app/assets/stylesheets/cmor/contact/application.css +15 -0
- data/app/assets/stylesheets/cmor/contact/application/keep.css +0 -0
- data/app/controllers/cmor/contact/application_controller.rb +7 -0
- data/app/controllers/cmor/contact/contact_requests_controller.rb +57 -0
- data/app/helpers/cmor/contact/application_helper.rb +6 -0
- data/app/jobs/cmor/contact/application_job.rb +6 -0
- data/app/jobs/cmor/contact/notify_new_contact_request_job.rb +25 -0
- data/app/mailers/cmor/contact/application_mailer.rb +8 -0
- data/app/mailers/cmor/contact/contact_request_mailer.rb +31 -0
- data/app/models/cmor/contact/application_record.rb +7 -0
- data/app/models/cmor/contact/contact_request.rb +36 -0
- data/app/views/cmor/contact/contact_request_mailer/notify.html.haml +7 -0
- data/app/views/cmor/contact/contact_request_mailer/notify.text.erb +5 -0
- data/app/views/cmor/contact/contact_requests/_form.haml +6 -0
- data/app/views/cmor/contact/contact_requests/_form_errors.haml +6 -0
- data/app/views/cmor/contact/contact_requests/new.haml +8 -0
- data/app/views/layouts/cmor/contact/application.html.erb +14 -0
- data/app/views/layouts/cmor/contact/mailer.html.erb +13 -0
- data/app/views/layouts/cmor/contact/mailer.text.erb +1 -0
- data/config/locales/de.yml +50 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20170813142704_create_cmor_contact_contact_requests.rb +15 -0
- data/lib/cmor/contact.rb +10 -0
- data/lib/cmor/contact/configuration.rb +60 -0
- data/lib/cmor/contact/engine.rb +16 -0
- data/lib/cmor/contact/version.rb +7 -0
- data/lib/cmor_contact.rb +3 -0
- data/lib/generators/cmor/contact/install/install_generator.rb +26 -0
- data/lib/generators/cmor/contact/install/templates/initializer.rb +83 -0
- data/lib/generators/cmor/contact/install/templates/routes.source +3 -0
- data/lib/tasks/cmor_contact_tasks.rake +4 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/i18n.rb +2 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20190325174020_create_active_storage_tables.active_storage.rb +27 -0
- data/spec/dummy/db/migrate/20190325174040_create_cmor_contact_contact_requests.cmor_contact.rb +16 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +108 -0
- data/spec/dummy/log/test.log +345 -0
- data/spec/dummy/tmp/development_secret.txt +1 -0
- data/spec/dummy~/Rakefile +6 -0
- data/spec/dummy~/app/assets/config/manifest.js +5 -0
- data/spec/dummy~/app/assets/javascripts/application.js +13 -0
- data/spec/dummy~/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy~/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy~/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy~/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy~/app/controllers/application_controller.rb +3 -0
- data/spec/dummy~/app/helpers/application_helper.rb +2 -0
- data/spec/dummy~/app/jobs/application_job.rb +2 -0
- data/spec/dummy~/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy~/app/models/application_record.rb +3 -0
- data/spec/dummy~/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy~/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy~/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy~/bin/bundle +3 -0
- data/spec/dummy~/bin/rails +4 -0
- data/spec/dummy~/bin/rake +4 -0
- data/spec/dummy~/bin/setup +38 -0
- data/spec/dummy~/bin/update +29 -0
- data/spec/dummy~/bin/yarn +11 -0
- data/spec/dummy~/config.ru +5 -0
- data/spec/dummy~/config/application.rb +26 -0
- data/spec/dummy~/config/boot.rb +5 -0
- data/spec/dummy~/config/cable.yml +10 -0
- data/spec/dummy~/config/database.yml +25 -0
- data/spec/dummy~/config/environment.rb +5 -0
- data/spec/dummy~/config/environments/development.rb +54 -0
- data/spec/dummy~/config/environments/production.rb +91 -0
- data/spec/dummy~/config/environments/test.rb +42 -0
- data/spec/dummy~/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy~/config/initializers/assets.rb +14 -0
- data/spec/dummy~/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy~/config/initializers/cmor_contact.rb +83 -0
- data/spec/dummy~/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy~/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy~/config/initializers/inflections.rb +16 -0
- data/spec/dummy~/config/initializers/mime_types.rb +4 -0
- data/spec/dummy~/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy~/config/locales/en.yml +33 -0
- data/spec/dummy~/config/puma.rb +56 -0
- data/spec/dummy~/config/routes.rb +3 -0
- data/spec/dummy~/config/secrets.yml +32 -0
- data/spec/dummy~/config/spring.rb +6 -0
- data/spec/dummy~/db/development.sqlite3 +0 -0
- data/spec/dummy~/db/migrate/20170813150718_create_cmor_contact_contact_requests.cmor_contact.rb +16 -0
- data/spec/dummy~/db/schema.rb +27 -0
- data/spec/dummy~/db/test.sqlite3 +0 -0
- data/spec/dummy~/log/test.log +0 -0
- data/spec/dummy~/package.json +5 -0
- data/spec/dummy~/public/404.html +67 -0
- data/spec/dummy~/public/422.html +67 -0
- data/spec/dummy~/public/500.html +66 -0
- data/spec/dummy~/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy~/public/apple-touch-icon.png +0 -0
- data/spec/dummy~/public/favicon.ico +0 -0
- data/spec/factories/cmor_contact_contact_requests.rb +10 -0
- data/spec/fixtures/cmor/contact/contact_request_mailer/notify +3 -0
- data/spec/jobs/cmor/contact/notify_new_contact_request_job_spec.rb +22 -0
- data/spec/mailers/cmor/contact/contact_request_mailer_spec.rb +24 -0
- data/spec/mailers/previews/cmor/contact/contact_request_mailer_preview.rb +11 -0
- data/spec/models/cmor/contact/contact_request_spec.rb +48 -0
- data/spec/models/generic_spec.rb +49 -0
- data/spec/models/i18n_spec.rb +40 -0
- data/spec/rails_helper.rb +62 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/support/action_mailer.rb +13 -0
- data/spec/support/active_job.rb +9 -0
- data/spec/support/capybara.rb +1 -0
- data/spec/support/factory_bot.rb +9 -0
- data/spec/support/rao-shoulda_matchers.rb +5 -0
- data/spec/support/shoulda_matchers.rb +8 -0
- 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,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
|
File without changes
|
@@ -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
|
+
*/
|
File without changes
|
@@ -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,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,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,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,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 @@
|
|
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"
|