slate-studio / activeadmin-settings

Settings backend for activeadmin based projects - pretty handy tool.
88 stars 65 forks source link

401 unauthorised issue #16

Closed creativetechnologist closed 9 years ago

creativetechnologist commented 11 years ago

Hi,

I'm getting the following error when updating a setting ...

Started PUT "/admin/settings/32" for 127.0.0.1 at 2013-07-17 08:31:55 +0100 Processing by ActiveadminSettings::SettingsController#update as / Parameters: {"utf8"=>"✓", "authenticity_token"=>"DXK9R5Pb2uwvlPT+xTk3WytF15w6yLvpF6TSqDtZRFg=", "setting"=>{"string"=>"33333"}, "id"=>"32"} Completed 401 Unauthorized in 61ms

I'm using the following gem versions ...

I'm not sure if this is related to the issue but I recently changed the model that activeadmin uses for login/authentication.

Any help most appreciated as this gem is now being used in a production environment.

anthonyb commented 11 years ago

Could you give us a little more info on this? Is this happening for every setting? Does it work again (in dev env) if you roll back the changes to the auth model? Can we get a look at the auth model to try it out ourselves?

Thanks!

creativetechnologist commented 11 years ago

Hi,

I rolled back the changes to the auth model and it worked fine, I narrowed the issue down to the following case.

When active_admin.rb contains ...

config.before_filter :checkadminrole

And the ApplicationController contains the matching function ...

class ApplicationController < ActionController::Base protect_from_forgery

def checkadminrole if current_msuser.canaccessadmin return true end flash[:notice] = "You need to be an admin to access this part of the application" redirect_to root_path end

end

It stops working and generates the error in the original post.

rlupiichuk commented 11 years ago

I've created test project and added your changes. It works fine for me, please take a look at: https://dl.dropboxusercontent.com/u/52847171/activeadmin_settings_test.zip

Make sure that logic from checkadminrole method works fine. Let us know if you get any additional details of this issue.

creativetechnologist commented 11 years ago

I just created a brand new Rails 3.2.13 app and tried the gem again with the standard ActiveAdmin setup and it's got the same issue, also as the screenshot shows it also seems to mangle the view. My gemfile is included too. It's a shame this is happening as I've been making good use of the gem on some quite substantial apps.

The test app works perfectly though so I'm going to try and see what the differences are.

source 'https://rubygems.org'

gem 'rails', '3.2.13' gem 'mysql2'

gem "activeadmin", github: "gregbell/active_admin" gem "meta_search", '>= 1.1.0.pre' gem 'active_admin_editor'

gem "aws-s3" gem "fog" gem "mini_magick" gem "carrierwave"

gem "bson_ext" gem "activeadmin-settings"

gem 'devise' gem 'omniauth' gem 'omniauth-facebook' gem 'omniauth-twitter'

gem 'formtastic'

group :development do gem "pg" gem "activerecord-postgresql-adapter"

end

group :production do gem 'therubyracer' gem 'libv8', '~> 3.11.8' end

group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'uglifier', '>= 1.0.3' gem 'jquery-ui-rails' end

screen shot 2013-07-23 at 17 23 59

caifara commented 9 years ago

I'm going to make a pull-request for this, but for now:

When I changed the authentication settings of ActiveAdmin I bumped into this issue. I let refinery handle the logic, so in ActiveAdmin I use:

config.authentication_method = :authenticate_refinery_user!

ActiveAdmin-Settings should make use of this authentication method, but it does not (for now). To work around that problem you can hack it (I've put this in lib load with an initializer). (Still only solves the problem for that controller, but it's a start)

ActiveadminSettings::SettingsController.class_eval do
  def authenticate_admin_user!
    send ActiveAdmin.application.authentication_method
  end
end