Add 'archived' property to Zotero.Library objects
Set when a user loses access to a library but chooses to keep it as a read-only library.
This commit is contained in:
parent
88184b341b
commit
9ac458e05c
5 changed files with 53 additions and 4 deletions
|
@ -48,6 +48,7 @@ Zotero.Library = function(params = {}) {
|
||||||
'libraryVersion',
|
'libraryVersion',
|
||||||
'storageVersion',
|
'storageVersion',
|
||||||
'lastSync',
|
'lastSync',
|
||||||
|
'archived'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ Zotero.Library = function(params = {}) {
|
||||||
// DB columns
|
// DB columns
|
||||||
Zotero.defineProperty(Zotero.Library, '_dbColumns', {
|
Zotero.defineProperty(Zotero.Library, '_dbColumns', {
|
||||||
value: Object.freeze([
|
value: Object.freeze([
|
||||||
'type', 'editable', 'filesEditable', 'version', 'storageVersion', 'lastSync'
|
'type', 'editable', 'filesEditable', 'version', 'storageVersion', 'lastSync', 'archived'
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -195,7 +196,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'hasTrash', {
|
||||||
|
|
||||||
// Create other accessors
|
// Create other accessors
|
||||||
(function() {
|
(function() {
|
||||||
let accessors = ['editable', 'filesEditable', 'storageVersion'];
|
let accessors = ['editable', 'filesEditable', 'storageVersion', 'archived'];
|
||||||
for (let i=0; i<accessors.length; i++) {
|
for (let i=0; i<accessors.length; i++) {
|
||||||
let prop = Zotero.Library._colToProp(accessors[i]);
|
let prop = Zotero.Library._colToProp(accessors[i]);
|
||||||
Zotero.defineProperty(Zotero.Library.prototype, accessors[i], {
|
Zotero.defineProperty(Zotero.Library.prototype, accessors[i], {
|
||||||
|
@ -300,6 +301,16 @@ Zotero.Library.prototype._set = function(prop, val) {
|
||||||
val = new Date(Math.floor(val.getTime()/1000) * 1000);
|
val = new Date(Math.floor(val.getTime()/1000) * 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '_libraryArchived':
|
||||||
|
if (['user', 'publications', 'feeds'].indexOf(this._libraryType) != -1) {
|
||||||
|
throw new Error('Cannot change ' + prop + ' for ' + this._libraryType + ' library');
|
||||||
|
}
|
||||||
|
if (val && this._libraryEditable) {
|
||||||
|
throw new Error('Cannot set editable library as archived');
|
||||||
|
}
|
||||||
|
val = !!val;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this[prop] == val) return; // Unchanged
|
if (this[prop] == val) return; // Unchanged
|
||||||
|
@ -326,6 +337,7 @@ Zotero.Library.prototype._loadDataFromRow = function(row) {
|
||||||
this._libraryVersion = row._libraryVersion;
|
this._libraryVersion = row._libraryVersion;
|
||||||
this._libraryStorageVersion = row._libraryStorageVersion;
|
this._libraryStorageVersion = row._libraryStorageVersion;
|
||||||
this._libraryLastSync = row._libraryLastSync !== 0 ? new Date(row._libraryLastSync * 1000) : false;
|
this._libraryLastSync = row._libraryLastSync !== 0 ? new Date(row._libraryLastSync * 1000) : false;
|
||||||
|
this._libraryArchived = !!row._libraryArchived;
|
||||||
|
|
||||||
this._hasCollections = !!row.hasCollections;
|
this._hasCollections = !!row.hasCollections;
|
||||||
this._hasSearches = !!row.hasSearches;
|
this._hasSearches = !!row.hasSearches;
|
||||||
|
|
|
@ -2367,6 +2367,10 @@ Zotero.Schema = new function(){
|
||||||
yield Zotero.DB.queryAsync("INSERT INTO feeds SELECT libraryID, name, url, lastUpdate, lastCheck, lastCheckError, 30, cleanupAfter, refreshInterval FROM feedsOld");
|
yield Zotero.DB.queryAsync("INSERT INTO feeds SELECT libraryID, name, url, lastUpdate, lastCheck, lastCheckError, 30, cleanupAfter, refreshInterval FROM feedsOld");
|
||||||
yield Zotero.DB.queryAsync("DROP TABLE feedsOld");
|
yield Zotero.DB.queryAsync("DROP TABLE feedsOld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (i == 91) {
|
||||||
|
yield Zotero.DB.queryAsync("ALTER TABLE libraries ADD COLUMN archived INT NOT NULL DEFAULT 0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield _updateDBVersion('userdata', toVersion);
|
yield _updateDBVersion('userdata', toVersion);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- 90
|
-- 91
|
||||||
|
|
||||||
-- Copyright (c) 2009 Center for History and New Media
|
-- Copyright (c) 2009 Center for History and New Media
|
||||||
-- George Mason University, Fairfax, Virginia, USA
|
-- George Mason University, Fairfax, Virginia, USA
|
||||||
|
@ -255,7 +255,8 @@ CREATE TABLE libraries (
|
||||||
filesEditable INT NOT NULL,
|
filesEditable INT NOT NULL,
|
||||||
version INT NOT NULL DEFAULT 0,
|
version INT NOT NULL DEFAULT 0,
|
||||||
storageVersion INT NOT NULL DEFAULT 0,
|
storageVersion INT NOT NULL DEFAULT 0,
|
||||||
lastSync INT NOT NULL DEFAULT 0
|
lastSync INT NOT NULL DEFAULT 0,
|
||||||
|
archived INT NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
|
|
|
@ -311,6 +311,7 @@ var createGroup = Zotero.Promise.coroutine(function* (props = {}) {
|
||||||
if (props.libraryVersion) {
|
if (props.libraryVersion) {
|
||||||
group.libraryVersion = props.libraryVersion;
|
group.libraryVersion = props.libraryVersion;
|
||||||
}
|
}
|
||||||
|
group.archived = props.archived === undefined ? false : props.archived;
|
||||||
yield group.saveTx();
|
yield group.saveTx();
|
||||||
return group;
|
return group;
|
||||||
});
|
});
|
||||||
|
|
|
@ -127,6 +127,37 @@ describe("Zotero.Library", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#archived", function() {
|
||||||
|
it("should return archived status", function() {
|
||||||
|
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
|
||||||
|
assert.isFalse(library.archived, 'user library is not archived');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should allow setting archived status", function* () {
|
||||||
|
let library = yield createGroup({ editable: false, archived: true });
|
||||||
|
assert.isTrue(library.archived);
|
||||||
|
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT archived FROM libraries WHERE libraryID=?", library.libraryID)), 1)
|
||||||
|
|
||||||
|
library.archived = false;
|
||||||
|
yield library.saveTx();
|
||||||
|
assert.isFalse(library.archived);
|
||||||
|
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT archived FROM libraries WHERE libraryID=?", library.libraryID)), 0)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not be settable for user and publications libraries", function* () {
|
||||||
|
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
|
||||||
|
assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for user library$/, "does not allow setting user library as archived");
|
||||||
|
|
||||||
|
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
|
||||||
|
assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for publications library$/, "does not allow setting publications library as archived");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should only be settable on read-only library", function* () {
|
||||||
|
let library = yield createGroup();
|
||||||
|
assert.throws(() => library.archived = true, /^Cannot set editable library as archived$/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#save()", function() {
|
describe("#save()", function() {
|
||||||
it("should require mandatory parameters to be set", function* () {
|
it("should require mandatory parameters to be set", function* () {
|
||||||
let library = new Zotero.Library({ editable: true, filesEditable: true });
|
let library = new Zotero.Library({ editable: true, filesEditable: true });
|
||||||
|
|
Loading…
Reference in a new issue