agilibox 1.3.6 → 1.4.0

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: 4f15e9e0b1db8b6b6735af5aa25e30390bfecbc8556c1f3a460e123335dde463
4
- data.tar.gz: 1bacaf3648533dfc130a0a77256e5a11c1583aaec0d2c5299a1a85cba862c7ae
3
+ metadata.gz: 698634df72b0e0a386b55326f55b22246c392bbf4488d0c78b0fb97b7f230c4f
4
+ data.tar.gz: 9cf623860c2e7dc514435ac01116a46948b6d415d0113b765bb239407fd44b72
5
5
  SHA512:
6
- metadata.gz: 4b03b38d3f15eed681d0cb69e8d620acaa1b95b900233a42ad4f2b7bc46d98600162baefc077af9f69c875b6c426a7a3ac0671afda9cefde23e2c67ec199aa24
7
- data.tar.gz: 469426483f126c9fc06f475799e741bcde20e9e64d7cf3e2a7c7239681efa3add46a9c251f2d2d9e9da7662e35c135bf410a89872f4436833e33680f8d30ffdf
6
+ metadata.gz: 1da109149aa05456d4d5b156f103788a66e998436218137a5aca38dc9d66a5e78eefdd7df302d2d3dc86708468f2e58e73b0a1067e4a5a227e6642260cdd6f63
7
+ data.tar.gz: dde577f9d385392ba9aa5546cc1e9882989a58edb1ec5956bdf51cd1f61f1128efa5820e0d3bb812b7eb41512000f34ed26747f23ced3e053310933418d5236e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 1.4.0
6
+
7
+ - Add `Agilibox::Email`
8
+ - Add `Agilibox.parent_controller` config
9
+ - Add `Agilibox.parent_mailer` config
10
+ - Filters improvements
11
+
5
12
  ## 1.3.6
6
13
 
7
14
  - Remove deprecated `Agilibox::SortableUUIDGenerator::generate`
@@ -1,5 +1,3 @@
1
- module Agilibox
2
- class ApplicationController < ActionController::Base
3
- protect_from_forgery with: :exception
4
- end
1
+ class Agilibox::ApplicationController < Agilibox.parent_controller
2
+ protect_from_forgery with: :exception
5
3
  end
@@ -1,4 +1,8 @@
1
1
  class Agilibox::SmallData::FiltersController < ::Agilibox::ApplicationController
2
+ skip_after_action :verify_authorized, raise: false
3
+ skip_after_action :verify_policy_scoped, raise: false
4
+ skip_before_action :verify_authenticity_token, raise: false
5
+
2
6
  def create
3
7
  skip_authorization if respond_to?(:skip_authorization)
4
8
  skip_policy_scope if respond_to?(:skip_policy_scope)
@@ -0,0 +1,113 @@
1
+ class Agilibox::Email
2
+ include ActiveModel::Model
3
+ include Agilibox::ModelToS
4
+ include Agilibox::ModelI18n
5
+
6
+ validates :to, presence: true
7
+ validates :subject, presence: true
8
+ validates :body, presence: true
9
+
10
+ validate :validate_addr_formats
11
+
12
+ attr_accessor(
13
+ :current_user,
14
+ :from,
15
+ :reply_to,
16
+ :to,
17
+ :cc,
18
+ :subject,
19
+ :body,
20
+ :attachments,
21
+ )
22
+
23
+ def initialize(*)
24
+ super
25
+ assign_default_values
26
+ end
27
+
28
+ def attachment_names
29
+ attachments.keys.join(", ")
30
+ end
31
+
32
+ def validate_and_deliver
33
+ ok = valid?
34
+ deliver if ok
35
+ ok
36
+ end
37
+
38
+ def data
39
+ {
40
+ :from => from,
41
+ :reply_to => reply_to,
42
+ :to => to,
43
+ :cc => cc,
44
+ :subject => subject,
45
+ :body => body,
46
+ :attachments => attachments,
47
+ }
48
+ end
49
+
50
+ def deliver
51
+ deliver_now
52
+ end
53
+
54
+ def deliver_now
55
+ Agilibox::GenericMailer.generic_email(data).deliver_now
56
+ end
57
+
58
+ def deliver_later
59
+ Agilibox::GenericMailer.generic_email(data).deliver_later
60
+ end
61
+
62
+ private
63
+
64
+ def assign_default_values
65
+ self.from ||= default_from
66
+ self.reply_to ||= default_reply_to
67
+ self.to ||= default_to
68
+ self.cc ||= default_cc
69
+ self.subject ||= default_subject
70
+ self.body ||= default_body
71
+ self.attachments ||= default_attachments
72
+ end
73
+
74
+ def default_from
75
+ end
76
+
77
+ def default_reply_to
78
+ "#{current_user} <#{current_user.email}>" if current_user
79
+ end
80
+
81
+ def default_to
82
+ end
83
+
84
+ def default_cc
85
+ end
86
+
87
+ def default_subject
88
+ end
89
+
90
+ def default_body
91
+ end
92
+
93
+ def default_attachments
94
+ {}
95
+ end
96
+
97
+ def validate_addr_formats
98
+ validate_addr_formats_for(:from)
99
+ validate_addr_formats_for(:reply_to)
100
+ validate_addr_formats_for(:to)
101
+ validate_addr_formats_for(:cc)
102
+ end
103
+
104
+ def validate_addr_formats_for(attr)
105
+ require "mail"
106
+
107
+ string = public_send(attr).to_s
108
+ return if string.blank?
109
+ addrs = Mail.new(to: string).to_addrs
110
+ return true if addrs.any? && addrs.all? { |addr| URI::MailTo::EMAIL_REGEXP.match?(addr) }
111
+ errors.add(attr, :invalid)
112
+ end
113
+ end
@@ -8,7 +8,7 @@ class Agilibox::SmallData::Filter
8
8
  end
9
9
 
10
10
  def strategies
11
- self.class::STRATEGIES
11
+ self.class::STRATEGIES.with_indifferent_access
12
12
  end
13
13
 
14
14
  def apply(query)
@@ -0,0 +1,2 @@
1
+ class Agilibox::ApplicationMailer < Agilibox.parent_mailer
2
+ end
@@ -0,0 +1,9 @@
1
+ class Agilibox::GenericMailer < Agilibox::ApplicationMailer
2
+ def generic_email(data)
3
+ data.delete(:attachments).to_h.each do |filename, content|
4
+ attachments[filename] = content
5
+ end
6
+
7
+ mail(data)
8
+ end
9
+ end
@@ -94,3 +94,15 @@ en:
94
94
 
95
95
  labels:
96
96
  <<: *attributes
97
+
98
+ activemodel:
99
+ attributes:
100
+ agilibox/email:
101
+ from: "From"
102
+ reply_to: "Reply to"
103
+ to: "To"
104
+ cc: "Copy"
105
+ subject: "Subject"
106
+ body: "Message"
107
+ attachments: "Attachments"
108
+ attachment_names: "Attachments"
@@ -94,3 +94,15 @@ fr:
94
94
 
95
95
  labels:
96
96
  <<: *attributes
97
+
98
+ activemodel:
99
+ attributes:
100
+ agilibox/email:
101
+ from: "Expéditeur"
102
+ reply_to: "Répondre à"
103
+ to: "Destinataire"
104
+ cc: "Copie"
105
+ subject: "Objet"
106
+ body: "Message"
107
+ attachments: "Pièces jointes"
108
+ attachment_names: "Pièces jointes"
@@ -0,0 +1,19 @@
1
+ class << Agilibox
2
+ attr_writer :parent_controller
3
+
4
+ def parent_controller
5
+ @parent_controller ||= [
6
+ "ApplicationController",
7
+ "ActionController::Base",
8
+ ].map(&:safe_constantize).compact.first
9
+ end
10
+
11
+ attr_writer :parent_mailer
12
+
13
+ def parent_mailer
14
+ @parent_mailer ||= [
15
+ "ApplicationMailer",
16
+ "ActionMailer::Base",
17
+ ].map(&:safe_constantize).compact.first
18
+ end
19
+ end
@@ -13,5 +13,6 @@ module Agilibox
13
13
  end
14
14
  end
15
15
 
16
+ require_relative "config"
16
17
  require_relative "engine_file"
17
18
  require_relative "core_and_rails_ext"
@@ -1,3 +1,3 @@
1
1
  module Agilibox
2
- VERSION = "1.3.6"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agilibox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - agilidée
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-i18n
@@ -82,6 +82,7 @@ files:
82
82
  - app/controllers/agilibox/small_data/filters_controller.rb
83
83
  - app/controllers/concerns/agilibox/api_controller_concern.rb
84
84
  - app/controllers/concerns/agilibox/back_url_concern.rb
85
+ - app/emails/agilibox/email.rb
85
86
  - app/filters/agilibox/small_data/filter.rb
86
87
  - app/filters/agilibox/small_data/filter_strategy.rb
87
88
  - app/filters/agilibox/small_data/filter_strategy_by_date.rb
@@ -118,6 +119,8 @@ files:
118
119
  - app/libs/agilibox/phone_number_sanitizer.rb
119
120
  - app/libs/agilibox/sortable_uuid_generator.rb
120
121
  - app/libs/agilibox/token_generator.rb
122
+ - app/mailers/agilibox/application_mailer.rb
123
+ - app/mailers/agilibox/generic_mailer.rb
121
124
  - app/models/concerns/agilibox/active_record_uuid_concern.rb
122
125
  - app/models/concerns/agilibox/default_values_concern.rb
123
126
  - app/models/concerns/agilibox/model_i18n.rb
@@ -154,6 +157,7 @@ files:
154
157
  - lib/agilibox.rb
155
158
  - lib/agilibox/active_model_custom_error_messages.rb
156
159
  - lib/agilibox/active_record_comma_type_cast.rb
160
+ - lib/agilibox/config.rb
157
161
  - lib/agilibox/core_and_rails_ext.rb
158
162
  - lib/agilibox/cucumber_config.rb
159
163
  - lib/agilibox/cucumber_helpers/agilibox.rb