-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
36 lines (27 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const debug = require('debug')('loopback:component:access')
const AccessUtils = require('./utils')
const accessLogger = require('./middleware/access-logger')
const userContext = require('./middleware/user-context')
module.exports = function loopbackComponentAccess(app, options) {
debug('initializing component')
const { loopback } = app
const loopbackMajor = (loopback && loopback.version && loopback.version.split('.')[0]) || 1
if (loopbackMajor < 2) {
throw new Error('loopback-component-access-groups requires loopback 2.0 or newer')
}
// Initialize middleware.
app.middleware('auth:after', userContext())
app.middleware('routes:before', accessLogger())
// Initialise helper class.
app.accessUtils = new AccessUtils(app, options)
// Initialize remoting phase.
app.accessUtils.setupRemotingPhase()
// Set up role resolvers.
app.accessUtils.setupRoleResolvers()
// Set up model opertion hooks.
if (options.applyToStatic) {
app.accessUtils.setupFilters()
}
// TODO: Create Group Access model automatically if one hasn't been specified
}