mautic 2.3.6 → 2.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/app/controllers/concerns/mautic/connections_controller_concern.rb +2 -2
- data/app/controllers/mautic/connections_controller.rb +10 -0
- data/app/models/mautic/connection.rb +3 -3
- data/app/models/mautic/connections/oauth2.rb +7 -6
- data/app/models/mautic/contact.rb +10 -4
- data/app/models/mautic/tag.rb +32 -0
- data/app/models/mautic/web_hook.rb +2 -2
- data/app/views/mautic/connections/_form.html.erb +1 -1
- data/config/routes.rb +0 -2
- data/lib/mautic.rb +5 -1
- data/lib/mautic/model.rb +18 -4
- data/lib/mautic/submissions/form.rb +7 -1
- data/lib/mautic/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54130da5f454542319794381488da40d7ddf9b44ae18e9071cee61a4ae6cee65
|
4
|
+
data.tar.gz: f81597d7b092e25ed9cc7f18905e681ae92f1afc61e1cd143f2fecb1f704b026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf11781f6797c3174c5e49612d0369660b7fde520cdfecc237396879b110bbe3ac56fd23c6ffd20dc9cf1878ea76faec45e0132930c3992afffd92c3b66cd53
|
7
|
+
data.tar.gz: 5d82c6eed700f377967347e8bc0bb759557d3f006a7a3ec4fb709a78026086eb8dfaedc6be3c0d3fef667a17a9b2cf472f8819ddfcfae757f2442d6b077c11b6
|
data/README.md
CHANGED
@@ -32,13 +32,40 @@ Mautic.configure do |config|
|
|
32
32
|
# OR it can be Proc
|
33
33
|
# *optional* This is your default mautic URL - used in form helper
|
34
34
|
config.mautic_url = "https://mautic.my.app"
|
35
|
+
# Set authorize condition for manage Mautic::Connections
|
36
|
+
config.authorize_mautic_connections = ->(controller) { false }
|
35
37
|
end
|
36
38
|
```
|
39
|
+
### Manage mautic connections
|
40
|
+
You can use builtin Mautic:ConnectionsController:
|
37
41
|
|
38
42
|
add to `config/routes.rb`
|
39
43
|
```ruby
|
40
44
|
mount Mautic::Engine => "/mautic"
|
41
45
|
```
|
46
|
+
note: Make sure that you have some user authorization. There is builtin mechanism, in `Mautic.config.authorize_mautic_connections` = which return `false` to prevent all access by default (see: app/controllers/mautic/connections_controller.rb:3). For change this, you need add to `config/initializers/mautic.rb`:
|
47
|
+
```ruby
|
48
|
+
Mautic.config.authorize_mautic_connections = ->(controller) { current_user.admin? }
|
49
|
+
```
|
50
|
+
|
51
|
+
OR use your own controller, by including concern
|
52
|
+
```ruby
|
53
|
+
class MyOwnController < ApplicationController
|
54
|
+
before_action :authorize_user
|
55
|
+
|
56
|
+
include Mautic::ConnectionsControllerConcern
|
57
|
+
end
|
58
|
+
```
|
59
|
+
Concern require additional routes (authorize and oauth2) in `routes.rb`
|
60
|
+
```ruby
|
61
|
+
resources :my_resources do
|
62
|
+
member do
|
63
|
+
get :authorize
|
64
|
+
get :oauth2
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
42
69
|
### Create mautic connection
|
43
70
|
|
44
71
|
1. In your mautic, create new
|
@@ -85,12 +85,12 @@ module Mautic
|
|
85
85
|
# ==--==--==--==--
|
86
86
|
|
87
87
|
def authorize
|
88
|
-
redirect_to @mautic_connection.authorize
|
88
|
+
redirect_to @mautic_connection.authorize(self)
|
89
89
|
end
|
90
90
|
|
91
91
|
def oauth2
|
92
92
|
begin
|
93
|
-
response = @mautic_connection.get_code(params.require(:code))
|
93
|
+
response = @mautic_connection.get_code(params.require(:code), self)
|
94
94
|
@mautic_connection.update(token: response.token, refresh_token: response.refresh_token)
|
95
95
|
return render plain: t('mautic.text_mautic_authorize_successfully')
|
96
96
|
rescue OAuth2::Error => e
|
@@ -1,5 +1,15 @@
|
|
1
1
|
module Mautic
|
2
2
|
class ConnectionsController < ApplicationController
|
3
|
+
before_action :authorize_me
|
3
4
|
include ::Mautic::ConnectionsControllerConcern
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def authorize_me
|
9
|
+
unless Mautic.config.authorize_mautic_connections.call(self)
|
10
|
+
logger.warn "Mautic::ConnectionsController unauthorized, you can change this by Mautic.config.authorize_mautic_connections. See: lib/mautic.rb:77"
|
11
|
+
render plain: "Unauthorized", status: 403
|
12
|
+
end
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
@@ -17,11 +17,11 @@ module Mautic
|
|
17
17
|
raise NotImplementedError
|
18
18
|
end
|
19
19
|
|
20
|
-
def authorize
|
20
|
+
def authorize(context)
|
21
21
|
raise NotImplementedError
|
22
22
|
end
|
23
23
|
|
24
|
-
def get_code(code)
|
24
|
+
def get_code(code, context)
|
25
25
|
raise NotImplementedError
|
26
26
|
end
|
27
27
|
|
@@ -55,7 +55,7 @@ module Mautic
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
def callback_url
|
58
|
+
def callback_url(context)
|
59
59
|
if (conf = Mautic.config.base_url).is_a?(Proc)
|
60
60
|
conf = conf.call(self)
|
61
61
|
end
|
@@ -11,12 +11,12 @@ module Mautic
|
|
11
11
|
})
|
12
12
|
end
|
13
13
|
|
14
|
-
def authorize
|
15
|
-
client.auth_code.authorize_url(redirect_uri: callback_url)
|
14
|
+
def authorize(context)
|
15
|
+
client.auth_code.authorize_url(redirect_uri: callback_url(context))
|
16
16
|
end
|
17
17
|
|
18
|
-
def get_code(code)
|
19
|
-
client.auth_code.get_token(code, redirect_uri: callback_url)
|
18
|
+
def get_code(code, context)
|
19
|
+
client.auth_code.get_token(code, redirect_uri: callback_url(context))
|
20
20
|
end
|
21
21
|
|
22
22
|
def connection
|
@@ -37,9 +37,10 @@ module Mautic
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
def callback_url
|
40
|
+
def callback_url(context)
|
41
41
|
uri = super
|
42
|
-
uri.path = Mautic::Engine.routes.url_helpers.oauth2_connection_path(self)
|
42
|
+
# uri.path = Mautic::Engine.routes.url_helpers.oauth2_connection_path(self)
|
43
|
+
uri.path = context.url_for(action: "oauth2", id: self , only_path: true)
|
43
44
|
uri.to_s
|
44
45
|
end
|
45
46
|
|
@@ -19,7 +19,7 @@ module Mautic
|
|
19
19
|
def owner=(hash)
|
20
20
|
raise ArgumentError, "must be a hash !" unless hash.is_a?(Hash)
|
21
21
|
|
22
|
-
@table[
|
22
|
+
@table[:owner] = hash["id"]
|
23
23
|
@owner = hash
|
24
24
|
end
|
25
25
|
|
@@ -33,7 +33,7 @@ module Mautic
|
|
33
33
|
# @see https://developer.mautic.org/#edit-contact set owner
|
34
34
|
# @param [Integer] int
|
35
35
|
def owner_id=(int)
|
36
|
-
@table[
|
36
|
+
@table[:owner] = int
|
37
37
|
end
|
38
38
|
|
39
39
|
def assign_attributes(source = nil)
|
@@ -41,14 +41,20 @@ module Mautic
|
|
41
41
|
|
42
42
|
if source
|
43
43
|
self.owner = source['owner'] || {}
|
44
|
+
tags = (source['tags'] || []).map { |t| Mautic::Tag.new(self, t) }.sort_by(&:name)
|
44
45
|
self.attributes = {
|
45
|
-
tags:
|
46
|
+
tags: Tag::Collection.new(self, *tags),
|
46
47
|
doNotContact: source['doNotContact'] || [],
|
47
48
|
owner: owner['id'],
|
48
49
|
}
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
def to_mautic(data = @table)
|
54
|
+
data.delete(:doNotContact)
|
55
|
+
super(data)
|
56
|
+
end
|
57
|
+
|
52
58
|
def events
|
53
59
|
@proxy_events ||= Proxy.new(connection, "contacts/#{id}/events", klass: "Mautic::Event")
|
54
60
|
end
|
@@ -90,7 +96,7 @@ module Mautic
|
|
90
96
|
self.errors = e.errors
|
91
97
|
end
|
92
98
|
|
93
|
-
|
99
|
+
errors.blank?
|
94
100
|
end
|
95
101
|
|
96
102
|
alias add_dnc do_not_contact!
|
data/app/models/mautic/tag.rb
CHANGED
@@ -1,11 +1,43 @@
|
|
1
1
|
module Mautic
|
2
2
|
class Tag < Model
|
3
3
|
|
4
|
+
class Collection < Array
|
5
|
+
attr_reader :model
|
6
|
+
|
7
|
+
# @param [Mautic::Model] model
|
8
|
+
def initialize(model, *several_variants)
|
9
|
+
@model = model
|
10
|
+
@tags_to_remove = []
|
11
|
+
super(several_variants)
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(item)
|
15
|
+
@model.changed = true
|
16
|
+
item = Tag.new(@model, { tag: item }) if item.is_a?(String)
|
17
|
+
super(item)
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(item)
|
21
|
+
@model.changed = true
|
22
|
+
item = detect { |t| t.name == item } if item.is_a?(String)
|
23
|
+
@tags_to_remove << "-#{item}"
|
24
|
+
delete item
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_mautic
|
28
|
+
map(&:name) + @tags_to_remove
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
4
32
|
# alias for attribute :tag
|
5
33
|
def name
|
6
34
|
tag
|
7
35
|
end
|
8
36
|
|
37
|
+
def to_s
|
38
|
+
name
|
39
|
+
end
|
40
|
+
|
9
41
|
def name=(name)
|
10
42
|
self.tag = name
|
11
43
|
end
|
@@ -12,10 +12,10 @@ module Mautic
|
|
12
12
|
|
13
13
|
def form_submissions
|
14
14
|
@forms ||= Array.wrap(@params.require("mautic.form_on_submit")).collect do |data|
|
15
|
-
p = data.permit(submission: [:id, form: {}, lead: {}, results: {}]).to_h
|
15
|
+
p = data.permit(submission: [:id, :referer, form: {}, lead: {}, results: {}]).to_h
|
16
16
|
::Mautic::Submissions::Form.new(@connection, p["submission"]) if p["submission"]
|
17
17
|
end.compact
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<% if form.object.persisted? %>
|
25
25
|
<div class="field">
|
26
26
|
<label>Now generate pair of tokens with this callback url:</label>
|
27
|
-
<pre><%= @mautic_connection.send :callback_url %></pre>
|
27
|
+
<pre><%= @mautic_connection.send :callback_url, controller %></pre>
|
28
28
|
</div>
|
29
29
|
|
30
30
|
<div class="field">
|
data/config/routes.rb
CHANGED
data/lib/mautic.rb
CHANGED
@@ -67,10 +67,14 @@ module Mautic
|
|
67
67
|
end
|
68
68
|
|
69
69
|
configure do |config|
|
70
|
-
# This is URL your application - its for oauth callbacks
|
70
|
+
# This is URL of your application - its for oauth callbacks
|
71
71
|
config.base_url = "http://localhost:3000"
|
72
|
+
|
72
73
|
# *optional* This is your default mautic URL - used in form helper
|
73
74
|
config.mautic_url = "https://mautic.my.app"
|
75
|
+
|
76
|
+
# Set authorize condition for manage Mautic::Connections
|
77
|
+
config.authorize_mautic_connections = ->(controller) { false }
|
74
78
|
end
|
75
79
|
# Your code goes here...
|
76
80
|
|
data/lib/mautic/model.rb
CHANGED
@@ -39,6 +39,7 @@ module Mautic
|
|
39
39
|
|
40
40
|
attr_reader :connection
|
41
41
|
attr_accessor :errors
|
42
|
+
attr_writer :changed
|
42
43
|
|
43
44
|
# @param [Mautic::Connection] connection
|
44
45
|
def initialize(connection, hash = nil)
|
@@ -58,7 +59,7 @@ module Mautic
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def update(force = false)
|
61
|
-
return false
|
62
|
+
return false unless changed?
|
62
63
|
|
63
64
|
begin
|
64
65
|
json = @connection.request((force && :put || :patch), "api/#{endpoint}/#{id}/edit", body: to_mautic)
|
@@ -68,7 +69,7 @@ module Mautic
|
|
68
69
|
self.errors = e.errors
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
+
errors.blank?
|
72
73
|
end
|
73
74
|
|
74
75
|
def update_columns(attributes = {})
|
@@ -88,7 +89,7 @@ module Mautic
|
|
88
89
|
self.errors = e.errors
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
errors.blank?
|
92
93
|
end
|
93
94
|
|
94
95
|
def destroy
|
@@ -105,6 +106,12 @@ module Mautic
|
|
105
106
|
@table.changes
|
106
107
|
end
|
107
108
|
|
109
|
+
def changed?
|
110
|
+
return @changed unless @changed.nil?
|
111
|
+
|
112
|
+
@changed = !changes.empty?
|
113
|
+
end
|
114
|
+
|
108
115
|
def attributes
|
109
116
|
@table.to_h
|
110
117
|
end
|
@@ -118,13 +125,20 @@ module Mautic
|
|
118
125
|
|
119
126
|
def to_mautic(data = @table)
|
120
127
|
data.each_with_object({}) do |(key, val), mem|
|
121
|
-
mem[key] = val.
|
128
|
+
mem[key] = if val.respond_to?(:to_mautic)
|
129
|
+
val.to_mautic
|
130
|
+
elsif val.is_a?(Array)
|
131
|
+
val.join("|")
|
132
|
+
else
|
133
|
+
val
|
134
|
+
end
|
122
135
|
end
|
123
136
|
end
|
124
137
|
|
125
138
|
private
|
126
139
|
|
127
140
|
def clear_changes
|
141
|
+
@changed = nil
|
128
142
|
@table.instance_variable_set(:@changes, nil)
|
129
143
|
end
|
130
144
|
|
data/lib/mautic/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mautic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|