Skip to content

enhance context passing in OWNER role resolver #3250

Closed

Description

@ebarault

Description

In regards to: #3230

With the move to explicit context passing of an options object, internal calls to find etc needed to be updated to pass the necessary information along, too. In this case, isOwner calls findById on a Model, but does not pass an access token in options.

In #3230, @bajtos fixed the content of passed options to {accessToken: context.accessToken} (see here whereas a way to customize the passed options is generally available (see doc)

But what if a user wants extra customization on top of that to get extra parameters in the passed options? An extreme solution could be for the developer to override the whole Role model to specify his own way of registering the role resolver, but we can probably provide an easier way of customizing the passed options.

NOTE: We should also address other internal calls of built-in CRUD methods that would require passing options.

Activity

  1. bajtos commented on Mar 6, 2017

    @bajtos
    Member

    One option is to add a new Role method to build the "options" object passed to Role.isOwner. Subclassed models then can override this method, although I am not sure how easy it is to configure LoopBack app to use own Role model.

    Role.createIsOwnerOptions = function(accessContext) {
      return {accessToken:accessContext.accessToken};
    }

    Another option that comes to my mind is to add support for 4-arg role resolvers with the signature (role, context, options, callback). The catch is how to support promise-based resolvers and distinguish between (role, context, callback) and (role, context, options)?

    Any other ideas?

  2. ebarault commented on Mar 13, 2017

    @ebarault
    ContributorAuthor

    still thinking about this. For the record in #2957 i chose to use a method that can be overriden, as you suggest in your first proposition.
    I think it should be rather easy for a user to use a custom Role or ACL model i personally did this a couple of time with no pb.

  3. stale commented on Aug 23, 2017

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  4. stale commented on Sep 6, 2017

    @stale

    This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions