MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / addPermissions

Function addPermissions

lib/header.mjs:114–131  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

112
113// Adds a header that describes the user's permissions
114export async function addPermissions (req, res, next) {
115 const { acl, session } = req
116 if (!acl) return next()
117
118 // Turn permissions for the public and the user into a header
119 const ldp = req.app.locals.ldp
120 const resource = ldp.resourceMapper.resolveUrl(req.hostname, req.path)
121 let [publicPerms, userPerms] = await Promise.all([
122 getPermissionsFor(acl, null, req),
123 getPermissionsFor(acl, session.userId, req)
124 ])
125 if (resource.endsWith('.acl') && userPerms === '' && await ldp.isOwner(session.userId, req.hostname)) userPerms = 'control'
126 debug.ACL(`Permissions on ${resource} for ${session.userId || '(none)'}: ${userPerms}`)
127 debug.ACL(`Permissions on ${resource} for public: ${publicPerms}`)
128 // Set the header
129 res.set('WAC-Allow', `user="${userPerms}",public="${publicPerms}"`)
130 next()
131}
132
133// Gets the permissions string for the given user and resource
134async function getPermissionsFor (acl, user, req) {

Callers

nothing calls this directly

Calls 3

getPermissionsForFunction · 0.85
resolveUrlMethod · 0.80
isOwnerMethod · 0.80

Tested by

no test coverage detected