Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with implementation in Rails API #22

Closed
kinsomicrote opened this issue Nov 12, 2019 · 4 comments
Closed

Issue with implementation in Rails API #22

kinsomicrote opened this issue Nov 12, 2019 · 4 comments

Comments

@kinsomicrote
Copy link

Hello, thanks for this gem, it fits perfectly with what my team wants, but I am having issues with implementing it in the API we have. Using the demo app as a guide, alongside the documentation of the gem, I have been able to create a business process, role and controller actions. I was also able to assign the role to a user that I have in my DB. But when I try to access the resource that the user assigned role has access to I get a 500 status error, I am unsure where that's coming from.
Here is what my application_controller.rb file looks like.

class ApplicationController < ActionController::API
  # include MailerUrlHelper
  # before_action :set_mailer_url_options, if: :devise_controller?
  include DeviseTokenAuth::Concerns::SetUserByToken
  before_action :configure_permitted_parameters, if: :devise_controller?
  include ActionController::Helpers

  before_action :authenticate_api_v1_user! # Typical for devise
  include Authz::Controllers::AuthorizationManager
  rescue_from Authz::Controllers::AuthorizationManager::NotAuthorized, with: :unauthorized_handler

  helper_method :current_user_authz

  private

  def current_user_authz
    current_api_v1_user.try(:user)
  end

  protected

  def configure_permitted_parameters
    keys = %i[full_name work_phone company_role role team_size phone_number]
    devise_parameter_sanitizer.permit(:sign_up, keys: keys)
    devise_parameter_sanitizer.permit(:account_update, keys: keys)
  end

  def unauthorized_handler
    msg = 'Ooops! It seems that you are not authorized to do that!'
    render json: { success: false, response: msg }
  end
end

Here is the controller action

def index
	authorize skip_scoping: true
    data = ::V1::TaskParam.new(params).index
    @tasks = Campaigns::Task.includes(assignee: :user).where(data).before(with_cursor).limit(per_page)
    render json: ::V1::TaskSerializer.new(@tasks, index_options).serializable_hash
end

I didn't tamper with the configuration file. Any idea what I could possibly be doing wrong? Thanks.

@serodriguez68
Copy link
Owner

serodriguez68 commented Nov 12, 2019

Hi Kingsley! Thanks for using Authz!

We need a bit more information to help you debug this issue.

  • If your repo is public, please send us the link.
  • If not, please post the trace of the 500 error to help us know where to start looking.

@kinsomicrote
Copy link
Author

Surprisingly, there's no stack trace for the error, here's what gets logged to the console.

Screenshot 2019-11-12 at 11 21 09 AM

@serodriguez68
Copy link
Owner

Any chance we can get access to the repo so that we can take a look OR get access to a dummy app that is configured similarly and exhibits the same behaviour?

If not, can you install the Better Errors gem
to see where the error points to in the code?

@serodriguez68
Copy link
Owner

Closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants