Set createdByUserID
to current user for locally created group item
Addresses #2322
This commit is contained in:
parent
4a914c26db
commit
72ac453a8c
3 changed files with 49 additions and 7 deletions
|
@ -1345,10 +1345,45 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
}
|
||||
}
|
||||
|
||||
if (this._changed.primaryData
|
||||
&& (this._changed.primaryData.createdByUserID || this._changed.primaryData.lastModifiedByUserID)) {
|
||||
let sql = "REPLACE INTO groupItems VALUES (?, ?, ?)";
|
||||
yield Zotero.DB.queryAsync(sql, [itemID, this._createdByUserID || null, this._lastModifiedByUserID || null]);
|
||||
// In group libraries:
|
||||
//
|
||||
// - If createdByUserID or lastModifiedByUserID are explicitly set, use those values
|
||||
// - Otherwise, set current user as createdByUserID if new or lastModifiedByUserID if not
|
||||
if (libraryType == 'group') {
|
||||
let createdByUserID;
|
||||
let lastModifiedByUserID;
|
||||
if (this._changed.primaryData) {
|
||||
if (this._changed.primaryData.createdByUserID) {
|
||||
createdByUserID = this._createdByUserID;
|
||||
}
|
||||
if (this._changed.primaryData.lastModifiedByUserID) {
|
||||
lastModifiedByUserID = this._lastModifiedByUserID;
|
||||
}
|
||||
}
|
||||
if (!options.skipGroupItemsUserUpdate) {
|
||||
if (!createdByUserID && isNew) {
|
||||
createdByUserID = Zotero.Users.getCurrentUserID();
|
||||
}
|
||||
// TEMP: For now, don't update lastModifiedByUserID -- we may want to start doing this
|
||||
// before we start showing a last-modified-by name in the UI so that it updates
|
||||
// immediately rather than waiting until a sync happens, but we should figure out if we
|
||||
// want all changes to count and make sure the dataserver follows the same behavior.
|
||||
//
|
||||
//if (!lastModifiedByUserID && !isNew) {
|
||||
// lastModifiedByUserID = Zotero.Users.getCurrentUserID();
|
||||
//}
|
||||
}
|
||||
if (createdByUserID || lastModifiedByUserID) {
|
||||
let sql = "REPLACE INTO groupItems VALUES (?, ?, ?)";
|
||||
yield Zotero.DB.queryAsync(
|
||||
sql,
|
||||
[
|
||||
itemID,
|
||||
createdByUserID || null,
|
||||
lastModifiedByUserID || null
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -360,6 +360,12 @@ var getGroup = Zotero.Promise.method(function () {
|
|||
|
||||
|
||||
var createGroup = Zotero.Promise.coroutine(function* (props = {}) {
|
||||
// Create a group item requires the current user to be set
|
||||
if (!Zotero.Users.getCurrentUserID()) {
|
||||
yield Zotero.Users.setCurrentUserID(1);
|
||||
yield Zotero.Users.setName(1, 'Name');
|
||||
}
|
||||
|
||||
var group = new Zotero.Group;
|
||||
group.id = props.id || Zotero.Utilities.rand(10000, 1000000);
|
||||
group.name = props.name || "Test " + Zotero.Utilities.randomString();
|
||||
|
|
|
@ -175,6 +175,7 @@ describe("Zotero.Sync.Data.Engine", function () {
|
|||
|
||||
yield Zotero.Users.setCurrentUserID(userID);
|
||||
yield Zotero.Users.setCurrentUsername("testuser");
|
||||
yield Zotero.Users.setCurrentName("Test User");
|
||||
})
|
||||
|
||||
after(function () {
|
||||
|
@ -4367,9 +4368,9 @@ describe("Zotero.Sync.Data.Engine", function () {
|
|||
var { id: groupID, libraryID } = await createGroup();
|
||||
({ engine, client, caller } = await setup({ libraryID }));
|
||||
|
||||
var item1 = await createDataObject('item', { libraryID });
|
||||
var item1 = await createDataObject('item', { libraryID }, { skipGroupItemsUserUpdate: true });
|
||||
var item1DateModified = item1.dateModified;
|
||||
var item2 = await createDataObject('item', { libraryID });
|
||||
var item2 = await createDataObject('item', { libraryID }, { skipGroupItemsUserUpdate: true });
|
||||
var responseJSON = [
|
||||
item1.toResponseJSON(),
|
||||
item2.toResponseJSON()
|
||||
|
@ -4413,7 +4414,7 @@ describe("Zotero.Sync.Data.Engine", function () {
|
|||
var { id: groupID, libraryID } = await createGroup();
|
||||
({ engine, client, caller } = await setup({ libraryID }));
|
||||
|
||||
var item = await createDataObject('item', { libraryID });
|
||||
var item = await createDataObject('item', { libraryID }, { skipGroupItemsUserUpdate: true });
|
||||
var responseJSON = [
|
||||
item.toResponseJSON()
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue