luk4s / mautic-rails

Mautic ruby client / wrapper
MIT License
23 stars 23 forks source link

How to setup a connection #20

Closed EnziinSystem closed 3 years ago

EnziinSystem commented 3 years ago

I have an application Mautic is running.

Now, I add the gem to exist Rails app.

In the Gemfile:

gem 'mautic'

In the config/initializers/mautic.rb:

Mautic.configure do |config|
  # This is for oauth handshake token url. I need to know where your app listen
  config.base_url = "http://www.domain.com"
  # OR it can be Proc
  # *optional* This is your default mautic URL - used in form helper
  config.mautic_url = "http://sub.domain.com"
  # Set authorize condition for manage Mautic::Connections
  config.authorize_mautic_connections = ->(controller) { current_user.admin? }
end

In the config/routes.rb

  mount Mautic::Engine => "/mautic"

When I get "/mautic/connections"

NameError in Mautic::ConnectionsController#index
undefined local variable or method `current_user' for main:Object

Because you created this gem, it is very simple for you but not for everyone. I can't set it up to work, please be more detailed instructions.

luk4s commented 3 years ago

Hi @EnziinSystem , usually access to manage of mautic connections should be restricted only for authorized users - not for everyone in applicatin.

See comment: "Set authorize condition for manage Mautic::Connections" Thats why you need adjuct configuration according to you application. For example in devise or authlogic is method current_user with User object... See https://github.com/luk4s/mautic-rails/blob/aaf2e4c2b2562be2cad45d5bab871b9710be446e/app/controllers/mautic/connections_controller.rb#L9

So ajdust this setting (authorize_mautic_connections) according to your application. OR you can include connections concern to YOUR controller https://github.com/luk4s/mautic-rails/blob/master/app/controllers/concerns/mautic/connections_controller_concern.rb and deal with permissions by yourself.

I hope this will help you.

EnziinSystem commented 3 years ago

I solved by remove Mautic.config.authorize_mautic_connections and change routes:

  authenticate :user, ->(u) { AdminUser.exists?(email: u.email) } do
    mount Mautic::Engine => "/mautic"
  end

Then I login with admin account, go to the "/mautic/connections" but I get the error assset compiled.


Sprockets::Rails::Helper::AssetNotPrecompiled in Mautic::Connections#index

Showing /usr/local/bundle/bundler/gems/mautic-rails-044d413a2f09/app/views/layouts/mautic/application.html.erb where line #5 raised:

mautic/application.css

Rails 6.1.0 Ruby 2.7.2 gem 'sass-rails', '~> 6.0'

luk4s commented 3 years ago

Yop, thats because mautic_manifest missing probably. But you are right, its unecessary completely - because there is no JS or CSS for gem. I will remove it...

EnziinSystem commented 3 years ago

It's worked! Thank you.