-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send 403 when a user does not have permission to add writers
- Loading branch information
1 parent
9c9214c
commit ce8f00d
Showing
13 changed files
with
205 additions
and
88 deletions.
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
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,66 @@ | ||
/** | ||
* Copyright (c) 2016, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* api/v1/helpers/verbs/doPostBToMAssoc.js | ||
*/ | ||
'use strict'; | ||
|
||
const u = require('./utils'); | ||
const httpStatus = require('../../constants').httpStatus; | ||
|
||
/** | ||
* Creates an one to many association between a instance of the model name | ||
* identified by "props.Name" and the instances of the model in assocArray. The | ||
* association is defined through "assocName" | ||
* | ||
* @param {IncomingMessage} req - The request object` | ||
* @param {ServerResponse} res - The response object | ||
* @param {Function} next - The next middleware function in the stack | ||
* @param {Module} props - The module containing the properties of the resource | ||
* whose association has to be deleted | ||
* @param {String} assocName - The name of the association associated with the | ||
* model | ||
* @param {Array} assocArray - The instances of a model for which the | ||
* association has to be created. | ||
* | ||
*/ | ||
function doPostBToMAssoc(req, res, next, props, assocName, assocArray) { // eslint-disable-line | ||
const params = req.swagger.params; | ||
let modelInst; | ||
u.findByKey(props, params) | ||
.then((o) => { | ||
modelInst = o; | ||
return u.isWritable(req, o); | ||
}) | ||
.then((ok) => { | ||
if (ok) { | ||
const addAssocfuncName = `add${u.capitalizeFirstLetter(assocName)}`; | ||
return modelInst[addAssocfuncName](assocArray); | ||
} | ||
|
||
return u.forbidden(next); | ||
}) | ||
.then((o) => { | ||
if (o) { | ||
|
||
/** | ||
* | ||
* The resolved object is either an array of arrays (when | ||
* writers are added) or just an empty array when no writers are added. | ||
* The popping is done to get the array from the array of arrays | ||
*/ | ||
let retval = o.length ? o.pop() : o; | ||
retval = u.responsify(retval, props, req.method); | ||
res.status(httpStatus.CREATED).json(retval); | ||
} | ||
}) | ||
.catch((err) => u.handleError(next, err, props.modelName)); | ||
} | ||
|
||
module.exports = doPostBToMAssoc; |
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
Oops, something went wrong.