Skip to content

Instantly share code, notes, and snippets.

@rodmcnew
Last active June 18, 2019 16:27
Show Gist options
  • Save rodmcnew/666d192c90a0226b55652bcc22ebcf4a to your computer and use it in GitHub Desktop.
Save rodmcnew/666d192c90a0226b55652bcc22ebcf4a to your computer and use it in GitHub Desktop.
loopback 4 ACL possible implementations usage
import {
Filter, repository,
} from '@loopback/repository';
import {
get,
getFilterSchemaFor,
HttpErrors,
param,
Request,
RestBindings,
} from '@loopback/rest';
import RcmRedirect from './RcmRedirect';
import { inject } from '@loopback/core';
import RcmRedirectRepository from './RcmRedirectRepository';
export default class RcmRedirectController {
constructor(
@repository(RcmRedirectRepository) public redirectRepo: RcmRedirectRepository,
@inject('acl') protected acl: { isAllowed: Function },
) { }
@get('/api/v2/rcm-redirects', {
responses: {
200: {
description: 'Array of RcmRedirect model instances',
content: {
'application/json': {
schema: { type: 'array', items: { 'x-ts-type': RcmRedirect } },
},
},
},
},
})
public async find(
@inject(RestBindings.Http.REQUEST) request: Request
@param.query.object('filter', getFilterSchemaFor(RcmRedirect)) filter?: Filter
) {
if (!this.acl.isAllowed(request, 'sites', 'admin')) {
throw new HttpErrors.Unauthorized();
}
return await this.redirectRepo.find(filter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment