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

Some validation of existence of OUJS accounts for collaboration #1639

Merged
merged 1 commit into from
Jul 27, 2019
Merged
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
69 changes: 68 additions & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,75 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
}

aInnerCallback(null);
}
},
function (aInnerCallback) {
// OpenUserJS `@author` validations
var author = null;

author = findMeta(aMeta, 'OpenUserJS.author.0.value');

if (author) {
User.findOne({
name: author
}, function (aErr, aUser) {
if (aErr) {
aInnerCallback(new statusError({
message: 'DB error finding `@author` in OpenUserJS block',
code: 500
}), null);
return;
}

if (!aUser) {
aInnerCallback(new statusError({
message: '`@author ' + author +
'` in OpenUserJS block does not exist or is incorrectly cased.',
code: 400
}), null);
return;
}

aInnerCallback(null);
});
} else {
aInnerCallback(null);
}
},
function (aOuterCallback) {
// OpenUserJS block `@collaborator` validations
var collaborators = null;

collaborators = findMeta(aMeta, 'OpenUserJS.collaborator.value');
if (collaborators) {
async.eachSeries(collaborators, function (aCollaborator, aInnerCallback) {
User.findOne({
name: aCollaborator
}, function (aErr, aUser) {
if (aErr) {
aOuterCallback(new statusError({
message: 'DB error finding `@collaborator` ' +
aCollaborator + ' in OpenUserJS block',
code: 500
}), null);
return;
}

if (!aUser) {
aOuterCallback(new statusError({
message: '`@collaborator ' + aCollaborator +
'` in OpenUserJS block does not exist or is incorrectly cased',
code: 400
}), null);
return;
}

aInnerCallback();
});
}, aOuterCallback);
} else {
aOuterCallback(null);
}
}

], function (aErr, aResults) {
var author = null;
Expand Down