Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid public notifications about private resources #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sudo: false
language: node_js
node_js:
- "0.12"
- "10"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done as a specific PR IMO, but apart from that this PR looks good ^_^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I did it as three commits in one PR, but I can split it out as one PR per commit, no problem!

54 changes: 18 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,28 @@ var path = require('path')

module.exports = function attachToServer (server, app, opts) {
var solidWs = new SolidWs(server, opts)

if (app) {

app.post('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after post')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.patch('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after patch')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.put('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after put')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.delete('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after delete')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
function publish (req, res, next) {
req.acl.can(null, 'Read').then(isPublic => {
if (isPublic) {
debug('pub ' + req.originalUrl + ' after edit')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
} else {
debug('do not pub ' + req.originalUrl + ' after edit')
}
next()
})
}

if (app) {
app.post('/*', publish)
app.patch('/*', publish)
app.put('/*', publish)
app.delete('/*', publish)
}

return solidWs
}