commit 4f155e343257a704bcdea853ea6eed8964ecc551
parent 79f0e4761f1251046949efb5086aeeb0ec57cb66
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 10 Jun 2015 01:14:02 -0400
Fix group.fromJSON() with no 'admins' or 'members' arrays
Diffstat:
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/group.js b/chrome/content/zotero/xpcom/data/group.js
@@ -192,6 +192,10 @@ Zotero.Group.prototype.save = Zotero.Promise.coroutine(function* () {
throw new Error("Group id not set");
}
+ if (!this.name) {
+ throw new Error("Group name not set");
+ }
+
if (!this._changed) {
Zotero.debug("Group " + this.id + " has not changed");
return false;
@@ -319,14 +323,14 @@ Zotero.Group.prototype.fromJSON = function (json, userID) {
if (userID) {
// If user is owner or admin, make library editable, and make files editable unless they're
// disabled altogether
- if (json.owner == userID || json.admins.indexOf(userID) != -1) {
+ if (json.owner == userID || (json.admins && json.admins.indexOf(userID) != -1)) {
editable = true;
if (json.fileEditing != 'none') {
filesEditable = true;
}
}
// If user is member, make library and files editable if they're editable by all members
- else if (json.members.indexOf(userID) != -1) {
+ else if (json.members && json.members.indexOf(userID) != -1) {
if (json.libraryEditing == 'members') {
editable = true;
if (json.fileEditing == 'members') {
diff --git a/test/tests/groupTest.js b/test/tests/groupTest.js
@@ -133,7 +133,7 @@ describe("Zotero.Group", function () {
owner: 1,
libraryEditing: 'members',
fileEditing: 'none',
- admins: [2],
+ // No admins
members: [3]
}, 3);
assert.isTrue(group.editable);