Skip to content

Commit

Permalink
Swap out @collaborator and @author for prefixed keys
Browse files Browse the repository at this point in the history
* Needs total verification that I haven't missed something.
* I do have some redundant tests in for `meta.oujs` existence but I'll remove those on demand.
* Hopefully this is everything needed.

Applies to OpenUserJS#226 and OpenUserJS#208
  • Loading branch information
Martii committed Jun 29, 2014
1 parent 5134914 commit b6fd452
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ var getScriptPageTasks = function (options) {
tasks.push(countTask(scriptOpenIssueCountQuery, options, 'issueCount'));

// Show collaborators of the script
if (script.meta.author && script.meta.collaborator) {
if (script.meta.oujs && script.meta.oujs.author && script.meta.oujs && script.meta.oujs.collaborator) {
options.hasCollab = true;
if (typeof script.meta.collaborator === 'string') {
options.script.collaborators = [{ url: encodeURIComponent(script.meta.collaborator), text: script.meta.collaborator }];
if (typeof script.meta.oujs.collaborator === 'string') {
options.script.collaborators = [{ url: encodeURIComponent(script.meta.oujs.collaborator), text: script.meta.oujs.collaborator }];
} else {
options.script.collaborators = [];
script.meta.collaborator.forEach(function (collaborator) {
script.meta.oujs.collaborator.forEach(function (collaborator) {
options.script.collaborators.push({ url: encodeURIComponent(collaborator), text: collaborator });
});
}
Expand Down
15 changes: 7 additions & 8 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ function parseMeta(aString) {
'namespace': true,
'description': true,
'version': true,
'author': true,
'oujs:author': true
};
var unique = null;
Expand Down Expand Up @@ -291,14 +290,14 @@ exports.storeScript = function (user, meta, buf, callback, update) {
// Can't install a script without a @name (maybe replace with random value)
if (!scriptName) { return callback(null); }

if (!isLibrary && meta.author
&& meta.author != user.name && meta.collaborator) {
collaborators = meta.collaborator;
if (!isLibrary && meta.oujs && meta.oujs.author
&& meta.oujs.author != user.name && meta.oujs && meta.oujs.collaborator) {
collaborators = meta.oujs.collaborator;
if ((typeof collaborators === 'string'
&& collaborators === user.name)
|| (collaborators instanceof Array
&& collaborators.indexOf(user.name) > -1)) {
installName = meta.author + '/';
installName = meta.oujs.author + '/';
} else {
collaborators = null;
}
Expand Down Expand Up @@ -349,9 +348,9 @@ exports.storeScript = function (user, meta, buf, callback, update) {
});
} else {
if (!script.isLib) {
if (collaborators && (script.meta.author != meta.author
|| JSON.stringify(script.meta.collaborator) !=
JSON.stringify(meta.collaborator))) {
if (collaborators && (script.meta.oujs && script.meta.oujs.author != meta.oujs.author
|| (script.meta.oujs && JSON.stringify(script.meta.oujs.collaborator) !=
JSON.stringify(meta.oujs.collaborator)))) {
return callback(null);
}
script.meta = meta;
Expand Down
8 changes: 4 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1374,11 +1374,11 @@ function getExistingScript(req, options, authedUser, callback) {

if (!script) { return callback(null); }

if (script.meta.collaborator) {
if (typeof script.meta.collaborator === 'string') {
collaborators.push(script.meta.collaborator);
if (script.meta.oujs && script.meta.oujs.collaborator) {
if (typeof script.meta.oujs.collaborator === 'string') {
collaborators.push(script.meta.oujs.collaborator);
} else {
collaborators = script.meta.collaborator;
collaborators = script.meta.oujs.collaborator;
}
}

Expand Down

0 comments on commit b6fd452

Please sign in to comment.