2014-11-12 10:54:55 -05:00
|
|
|
module.exports = AuthorizationManager =
|
|
|
|
assertClientCanViewProject: (client, callback = (error) ->) ->
|
|
|
|
AuthorizationManager._assertClientHasPrivilegeLevel client, ["readOnly", "readAndWrite", "owner"], callback
|
2014-11-13 12:07:05 -05:00
|
|
|
|
|
|
|
assertClientCanEditProject: (client, callback = (error) ->) ->
|
|
|
|
AuthorizationManager._assertClientHasPrivilegeLevel client, ["readAndWrite", "owner"], callback
|
|
|
|
|
2014-11-12 10:54:55 -05:00
|
|
|
_assertClientHasPrivilegeLevel: (client, allowedLevels, callback = (error) ->) ->
|
2020-02-24 08:32:20 -05:00
|
|
|
if client.ol_context["privilege_level"] in allowedLevels
|
|
|
|
callback null
|
|
|
|
else
|
|
|
|
callback new Error("not authorized")
|
2016-09-02 11:35:00 -04:00
|
|
|
|
|
|
|
assertClientCanViewProjectAndDoc: (client, doc_id, callback = (error) ->) ->
|
|
|
|
AuthorizationManager.assertClientCanViewProject client, (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
AuthorizationManager._assertClientCanAccessDoc client, doc_id, callback
|
|
|
|
|
|
|
|
assertClientCanEditProjectAndDoc: (client, doc_id, callback = (error) ->) ->
|
|
|
|
AuthorizationManager.assertClientCanEditProject client, (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
AuthorizationManager._assertClientCanAccessDoc client, doc_id, callback
|
|
|
|
|
|
|
|
_assertClientCanAccessDoc: (client, doc_id, callback = (error) ->) ->
|
2020-02-24 08:32:20 -05:00
|
|
|
if client.ol_context["doc:#{doc_id}"] is "allowed"
|
|
|
|
callback null
|
|
|
|
else
|
|
|
|
callback new Error("not authorized")
|
2016-09-02 11:35:00 -04:00
|
|
|
|
|
|
|
addAccessToDoc: (client, doc_id, callback = (error) ->) ->
|
2020-02-24 08:32:20 -05:00
|
|
|
client.ol_context["doc:#{doc_id}"] = "allowed"
|
|
|
|
callback(null)
|
2016-09-02 11:35:00 -04:00
|
|
|
|
|
|
|
removeAccessToDoc: (client, doc_id, callback = (error) ->) ->
|
2020-02-24 08:32:20 -05:00
|
|
|
delete client.ol_context["doc:#{doc_id}"]
|
|
|
|
callback(null)
|