Dragonfly and RefineryCMS resources authentification

65 views
Skip to first unread message

Boris

unread,
Feb 11, 2012, 7:23:41 AM2/11/12
to Refinery CMS
Hi,

I would like to control resource access based on Devise user
authentification. I am aware of Dragonfly's option to override
responses:

app.configure do |c|
c.server.before_serve do |job, env|
throw :halt, [200, {'Content-type' => 'text/plain'}, ['hello']]
end
end

However, I am unsure how to use this hook in order to apply a session-
based access control.

Thanks for any help.

Cheers,
Boris

The Vagabond Programmer

unread,
Nov 4, 2019, 4:32:31 PM11/4/19
to Refinery CMS
I'm looking to do the exact same thing.

For some reason when you try to configure Dragonfly directly it doesn't pick it up. E.g.

Dragonfly.app.configure do
  puts
"config for dragonfly"


  before_serve
do |job, env|
   
# Check to see if the user is authenticated
   
# Looks like we might have to use Warden to access the Session APIs
   
# bit.ly/2Nrx82y
    puts
'before serve' * 70
    binding
.pry
   
throw :halt, [403, {'Content-Type' => 'text/plain'}, ["You shall not pass"]]
 
end
end

When attempting to configure through `Refinery::Dragonfly` an error is raised.

In `config/initializers/refinery/dragonfly.rb`:

Refinery::Dragonfly.configure do |config|
 config
.before_serve           = proc do |job, env|
   
# Check to see if the user is authenticated
   
# Looks like we might have to use Warden to access the Session APIs
   
# bit.ly/2Nrx82y
    puts
'before serve in Refinery::Dragonfly' * 70
    binding
.pry
   
throw :halt, [403, {'Content-Type' => 'text/plain'}, ["You shall not pass"]]
 
end
end

Sadly when you run the server with that configuration an error is raised. Here's the stacktrace.

7: refinerycms-images-4.0.3/lib/refinery/images/engine.rb:12:in `block in <class:Engine>'
6: refinerycms-dragonfly-1.0.1/lib/refinery/dragonfly/dragonfly.rb:10:in `
configure!'
5: dragonfly-1.2.0/lib/dragonfly/configurable.rb:89:in `configure'

4: dragonfly-1.2.0/lib/dragonfly/configurable.rb:51:in `configure'
3: dragonfly-1.2.0/lib/dragonfly/configurable.rb:51:in `
instance_eval'
2: refinerycms-dragonfly-1.0.1/lib/refinery/dragonfly/dragonfly.rb:35:in `block in configure!'

1: dragonfly-1.2.0/lib/dragonfly/configurable.rb:30:in `block (2 levels) in meth'
   dragonfly-1.2.0/lib/dragonfly/server.rb:43:in `
before_serve': wrong number of arguments (given 1, expected 0) (ArgumentError)


It looks like the block isn't passed into Dragonfly correctly.

This is one of the downsides to a dynamic language like ruby, you're not sure what the expected structure is supposed to be. 

Anita Graham

unread,
Nov 5, 2019, 8:05:40 PM11/5/19
to Refinery CMS
What version of Refinery are you using? 
 ditto Dragonfly?

Running your config I don't get an error,   otoh I don't throw a halt either.
(refinerycms-e49a6bebefe3 [recent, Rails 5.2 compatible], dragonfly-1.2.0)

I'll look deeper.



Anita Graham

unread,
Nov 5, 2019, 11:25:54 PM11/5/19
to Refinery CMS

Quick answer - using your first example, accessing Dragonfly directly, use the dragonfly app name :refinery_images, thus:

Dragonfly.app(:refinery_images).configure do
end


will get the configuration through.

1. still looking at why the Refinery::Dragonfly config doesn't go through
2. Perhaps we should use the default app for Refinery::Images (this is configured in refinery/images/configuration.rb)

I get errors with binding.pry after that - but I'll leave that to you.

Anita

Anita Graham

unread,
Nov 6, 2019, 8:01:16 AM11/6/19
to Refinery CMS
I have a fix for this problem and have submitted a PR.

Anita Graham

unread,
Nov 6, 2019, 8:05:49 AM11/6/19
to Refinery CMS

Withdrawn my PR as someone has already submitted one for the same problem.
Reply all
Reply to author
Forward
0 new messages