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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffa1c03fd57447ef4b33050b2fea5150a9c4b2665675fdb0894f1a914c7e24af
4
- data.tar.gz: 05be7f0b16e1a3e0a9f3c3adc0e89c3e3b1c0554afd122777fce06ec2ab1dad9
3
+ metadata.gz: 59800fcfc64665ad1873fc20ef004bffe54edd38c2bb4da6263e702c0caba571
4
+ data.tar.gz: e32ddec1e3707e5cf8fab1232de729a6c8df75d30f2520dc1620eec57bf857c7
5
5
  SHA512:
6
- metadata.gz: 20100e7ada6a8715ffefe5d2210c4c4cdd20007e0f410ef9d66a192851deca4a86e4b4fb1e91e25a00ac639641d7210c2bf64cf1f8dec36b9476bc73edfd46cb
7
- data.tar.gz: 9f6e8a2abcb4ac1e067420e88e1691a6fb0f63cc1ddb3ffaa1a0be8043985dd072735b2e1316c8e0a413dcde474e743c446ed65d2b815dc29da140866a820245
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">
@@ -3,8 +3,6 @@ Mautic::Engine.routes.draw do
3
3
  member do
4
4
  get :authorize
5
5
  get :oauth2
6
-
7
6
  end
8
- # post "webhook/:mautic_connection_id", action: "webhook", on: :collection
9
7
  end
10
8
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Mautic
2
- VERSION = '2.3.8'
2
+ VERSION = '2.3.9'
3
3
  end
@@ -46,6 +46,9 @@ RSpec.configure do |config|
46
46
 
47
47
  config.before(:each) do
48
48
  DatabaseCleaner.strategy = :transaction
49
+ Mautic.configure do |config|
50
+ config.authorize_mautic_connections = ->(controller) { true }
51
+ end
49
52
  end
50
53
 
51
54
  config.before(:each) do
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.8
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-06-25 00:00:00.000000000 Z
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.8
225
+ rubygems_version: 3.0.6
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: Ruby on Rails Mautic integration