From 7a7d972069d2c8a87a89cdf3b10f62037b8ca8df Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Mon, 9 Sep 2013 12:20:28 +0200 Subject: [PATCH] Foxx: Added the same for onlyIf and onlyIfAuthenticated --- Documentation/UserManual/Foxx.md | 8 ++++ .../org/arangodb/foxx/request_context.js | 44 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Documentation/UserManual/Foxx.md b/Documentation/UserManual/Foxx.md index 36ed01be03..f9950788c9 100644 --- a/Documentation/UserManual/Foxx.md +++ b/Documentation/UserManual/Foxx.md @@ -191,6 +191,14 @@ The following methods are available: @copydetails JSF_foxx_RequestContextBuffer_errorResponse +### onlyIf + +@copydetails JSF_foxx_RequestContextBuffer_onlyIf + +### onlyIfAuthenticated + +@copydetails JSF_foxx_RequestContextBuffer_onlyIfAuthenticated + Before and After Hooks ---------------------- diff --git a/js/server/modules/org/arangodb/foxx/request_context.js b/js/server/modules/org/arangodb/foxx/request_context.js index fd57606189..5493cbc676 100644 --- a/js/server/modules/org/arangodb/foxx/request_context.js +++ b/js/server/modules/org/arangodb/foxx/request_context.js @@ -389,7 +389,49 @@ _.each([ /// }); /// @endcode //////////////////////////////////////////////////////////////////////////////// - "errorResponse" + "errorResponse", + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSF_foxx_RequestContextBuffer_onlyIf +/// @brief Defines a controller-wide onlyIf +/// +/// @FUN{RequestContextBuffer::onlyIf(@FA{code}, @FA{reason})} +/// +/// Defines an `onlyIf` for all routes of this controller. For details on +/// `onlyIf` see the according method on routes. +/// +/// @EXAMPLES +/// +/// @code +/// app.allroutes.onlyIf(myPersonalCheck); +/// +/// app.get("/foxx", function { +/// // Do something +/// }); +/// @endcode +//////////////////////////////////////////////////////////////////////////////// + "onlyIf", + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSF_foxx_RequestContextBuffer_onlyIfAuthenticated +/// @brief Defines a controller-wide onlyIfAuthenticated +/// +/// @FUN{RequestContextBuffer::errorResponse(@FA{errorClass}, @FA{code}, @FA{description})} +/// +/// Defines an `onlyIfAuthenticated` for all routes of this controller. For details on +/// `onlyIfAuthenticated` see the according method on routes. +/// +/// @EXAMPLES +/// +/// @code +/// app.allroutes.onlyIfAuthenticated(401, "You need to be authenticated"); +/// +/// app.get("/foxx", function { +/// // Do something +/// }); +/// @endcode +//////////////////////////////////////////////////////////////////////////////// + "onlyIfAuthenticated" ], function(functionName) { extend(RequestContextBuffer.prototype[functionName] = function () { this.applyChain.push({