diff --git a/migrations/20200709224148-users-rename-modifiedAt-to-ts.js b/migrations/20200709224148-users-rename-modifiedAt-to-ts.js new file mode 100644 index 000000000..30df49e68 --- /dev/null +++ b/migrations/20200709224148-users-rename-modifiedAt-to-ts.js @@ -0,0 +1,16 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE users ADD COLUMN ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP', function (error) { + if (error) console.error(error); + + db.runSql('ALTER TABLE users DROP COLUMN modifiedAt', callback); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE users DROP COLUMN ts', function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 1b016f0ae..249e7d43f 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS users( password VARCHAR(1024) NOT NULL, salt VARCHAR(512) NOT NULL, createdAt VARCHAR(512) NOT NULL, - modifiedAt VARCHAR(512) NOT NULL, + ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, displayName VARCHAR(512) DEFAULT "", fallbackEmail VARCHAR(512) DEFAULT "", twoFactorAuthenticationSecret VARCHAR(128) DEFAULT "", diff --git a/src/test/apps-test.js b/src/test/apps-test.js index d684da6ca..25a6e0237 100644 --- a/src/test/apps-test.js +++ b/src/test/apps-test.js @@ -29,7 +29,6 @@ describe('Apps', function () { fallbackEmail: 'admin@me.com', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', groupIds: [], @@ -45,7 +44,6 @@ describe('Apps', function () { fallbackEmail: 'safe@me.com', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', groupIds: [], @@ -61,7 +59,6 @@ describe('Apps', function () { fallbackEmail: 'safe1@me.com', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', groupIds: [ 'somegroup' ], diff --git a/src/test/apptask-test.js b/src/test/apptask-test.js index 54a242c05..97887f866 100644 --- a/src/test/apptask-test.js +++ b/src/test/apptask-test.js @@ -73,7 +73,6 @@ var ADMIN = { fallbackEmail: 'admin@me.com', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: '', displayName: '', role: 'owner', diff --git a/src/test/database-test.js b/src/test/database-test.js index fbc168613..ba44201f9 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -34,7 +34,6 @@ var USER_0 = { fallbackEmail: 'safer@me.com', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', twoFactorAuthenticationEnabled: false, @@ -53,7 +52,6 @@ var USER_1 = { fallbackEmail: 'safer2@me.com', salt: 'tata', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: '', displayName: 'Herbert 1', twoFactorAuthenticationEnabled: false, @@ -72,7 +70,6 @@ var USER_2 = { fallbackEmail: 'safer3@me.com', salt: 'tata', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: '', displayName: 'Herbert 2', twoFactorAuthenticationEnabled: false, diff --git a/src/test/groups-test.js b/src/test/groups-test.js index 101159651..d80818c42 100644 --- a/src/test/groups-test.js +++ b/src/test/groups-test.js @@ -36,7 +36,6 @@ var USER_0 = { role: 'user', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', source: '', @@ -52,7 +51,6 @@ var USER_1 = { // this user has not signed up yet role: 'user', salt: 'morton', createdAt: 'sometime back', - modifiedAt: 'now', resetToken: hat(256), displayName: '', source: '', diff --git a/src/userdb.js b/src/userdb.js index 949a499cc..ecaee238f 100644 --- a/src/userdb.js +++ b/src/userdb.js @@ -28,7 +28,7 @@ var assert = require('assert'), debug = require('debug')('box:userdb'), mysql = require('mysql'); -var USERS_FIELDS = [ 'id', 'username', 'email', 'fallbackEmail', 'password', 'salt', 'createdAt', 'modifiedAt', 'resetToken', 'displayName', +var USERS_FIELDS = [ 'id', 'username', 'email', 'fallbackEmail', 'password', 'salt', 'createdAt', 'resetToken', 'displayName', 'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime' ].join(','); var APP_PASSWORD_FIELDS = [ 'id', 'name', 'userId', 'identifier', 'hashedPassword', 'creationTime' ].join(','); @@ -166,15 +166,14 @@ function add(userId, user, callback) { assert.strictEqual(typeof user.fallbackEmail, 'string'); assert.strictEqual(typeof user.salt, 'string'); assert.strictEqual(typeof user.createdAt, 'string'); - assert.strictEqual(typeof user.modifiedAt, 'string'); assert.strictEqual(typeof user.resetToken, 'string'); assert.strictEqual(typeof user.displayName, 'string'); assert.strictEqual(typeof user.source, 'string'); assert.strictEqual(typeof user.role, 'string'); assert.strictEqual(typeof callback, 'function'); - const query = 'INSERT INTO users (id, username, password, email, fallbackEmail, salt, createdAt, modifiedAt, resetToken, displayName, source, role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - const args = [ userId, user.username, user.password, user.email, user.fallbackEmail, user.salt, user.createdAt, user.modifiedAt, user.resetToken, user.displayName, user.source, user.role ]; + const query = 'INSERT INTO users (id, username, password, email, fallbackEmail, salt, createdAt, resetToken, displayName, source, role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const args = [ userId, user.username, user.password, user.email, user.fallbackEmail, user.salt, user.createdAt, user.resetToken, user.displayName, user.source, user.role ]; database.query(query, args, function (error) { if (error && error.code === 'ER_DUP_ENTRY' && error.sqlMessage.indexOf('users_email') !== -1) return callback(new BoxError(BoxError.ALREADY_EXISTS, 'email already exists')); diff --git a/src/users.js b/src/users.js index 62f0a899f..7378962c7 100644 --- a/src/users.js +++ b/src/users.js @@ -183,7 +183,6 @@ function create(username, password, email, displayName, options, auditSource, ca password: Buffer.from(derivedKey, 'binary').toString('hex'), salt: salt.toString('hex'), createdAt: now, - modifiedAt: now, resetToken: '', displayName: displayName, source: source, @@ -524,7 +523,6 @@ function setPassword(user, newPassword, callback) { if (error) return callback(new BoxError(BoxError.CRYPTO_ERROR, error)); let data = { - modifiedAt: (new Date()).toISOString(), password: Buffer.from(derivedKey, 'binary').toString('hex'), resetToken: '' };