mautic 2.3.8 → 2.3.9
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/views/mautic/connections/_form.html.erb +1 -1
- data/config/routes.rb +0 -2
- data/lib/mautic.rb +5 -1
- data/lib/mautic/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59800fcfc64665ad1873fc20ef004bffe54edd38c2bb4da6263e702c0caba571
|
4
|
+
data.tar.gz: e32ddec1e3707e5cf8fab1232de729a6c8df75d30f2520dc1620eec57bf857c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b8433f04ee7a96e9474a0f8b39a883637d68b5b2135203f150fc697d5a495e3a7447311c1d27171fe7545c74b979ee4b7727397ba279fde1ce9472b2ed29809
|
7
|
+
data.tar.gz: 495c134933d712de9598cc618bf308f5b297e59bf86040d3e1c25b7ad636ee910932b08adc46c3a1a7144459b3f17e49dbb8cb57b167d28084715f8e19ed8197
|
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
|
|
@@ -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/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.9
|
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-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.0.
|
225
|
+
rubygems_version: 3.0.6
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Ruby on Rails Mautic integration
|