-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add read/write permissions for sandstorm sharing
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var davReadMethods = { | ||
'GET': true, | ||
'HEAD': true, | ||
'OPTIONS': true, | ||
'PROPFIND': true, | ||
'REPORT': true | ||
}; | ||
|
||
var webReadMethods = { | ||
'GET': true, | ||
'HEAD': true, | ||
'OPTIONS': true | ||
} | ||
|
||
var validate = { | ||
edit: function validateEdit(req) { | ||
return true; | ||
}, | ||
|
||
view: function validateView(req) { | ||
return webReadMethods[req.method]; | ||
}, | ||
|
||
sync: function validateSync(req) { | ||
return davReadMethods[req.method]; | ||
} | ||
}; | ||
|
||
module.exports = function(req, res, next) { | ||
var permissions = req.headers['x-sandstorm-permissions']; | ||
|
||
if(permissions) { | ||
permissions = permissions.split(','); | ||
|
||
for(var i = 0; i < permissions.length; i++) { | ||
var permission = permissions[i]; | ||
console.log(permission); | ||
console.log(validate[permissions]); | ||
|
||
if(validate[permission] && validate[permission](req)) { | ||
return next(); | ||
} | ||
} | ||
res.writeHead(403, {}); | ||
res.end("Access denied."); | ||
} else { | ||
next(); | ||
} | ||
}; |