Skip to content

Commit

Permalink
馃帹 change last_login to last_seen (#8259)
Browse files Browse the repository at this point in the history
refs #8258

* 馃帹  change last_login to last_seen

- rename the column
- a change in Ghost-Admin is required as well

* test utils: revert export examples

* revert line breaks
  • Loading branch information
kirrg001 authored and ErisDS committed Apr 5, 2017
1 parent 9b3c394 commit 587ff6f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/server/data/schema/schema.js
Expand Up @@ -47,7 +47,7 @@ module.exports = {
meta_title: {type: 'string', maxlength: 2000, nullable: true},
meta_description: {type: 'string', maxlength: 2000, nullable: true},
tour: {type: 'text', maxlength: 65535, nullable: true},
last_login: {type: 'dateTime', nullable: true},
last_seen: {type: 'dateTime', nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
Expand Down
4 changes: 2 additions & 2 deletions core/server/models/base/listeners.js
Expand Up @@ -7,10 +7,10 @@ var config = require('../../config'),
moment = require('moment-timezone');

/**
* WHEN access token is created we will update last_login for user.
* WHEN access token is created we will update last_seen for user.
*/
events.on('token.added', function (tokenModel) {
models.User.edit({last_login: moment().toDate()}, {id: tokenModel.get('user_id')})
models.User.edit({last_seen: moment().toDate()}, {id: tokenModel.get('user_id')})
.catch(function (err) {
logging.error(new errors.GhostError({err: err, level: 'critical'}));
});
Expand Down
6 changes: 3 additions & 3 deletions core/server/models/user.js
Expand Up @@ -241,7 +241,7 @@ User = ghostBookshelf.Model.extend({
}, {
orderDefaultOptions: function orderDefaultOptions() {
return {
last_login: 'DESC',
last_seen: 'DESC',
name: 'ASC',
created_at: 'DESC'
};
Expand Down Expand Up @@ -364,7 +364,7 @@ User = ghostBookshelf.Model.extend({
/**
* ### Edit
*
* Note: In case of login the last_login attribute gets updated.
* Note: In case of login the last_seen attribute gets updated.
*
* @extends ghostBookshelf.Model.edit to handle returning the full object
* **See:** [ghostBookshelf.Model.edit](base.js.html#edit)
Expand Down Expand Up @@ -628,7 +628,7 @@ User = ghostBookshelf.Model.extend({

return self.isPasswordCorrect({plainPassword: object.password, hashedPassword: user.get('password')})
.then(function then() {
return Promise.resolve(user.set({status: 'active', last_login: new Date()}).save({validate: false}))
return Promise.resolve(user.set({status: 'active', last_seen: new Date()}).save({validate: false}))
.catch(function handleError(err) {
// If we get a validation or other error during this save, catch it and log it, but don't
// cause a login error because of it. The user validation is not important here.
Expand Down
4 changes: 2 additions & 2 deletions core/test/functional/routes/api/users_spec.js
Expand Up @@ -92,11 +92,11 @@ describe('User API', function () {
jsonResponse.users.should.have.length(4);

testUtils.API.checkResponse(jsonResponse.users[0], 'user');
testUtils.API.isISO8601(jsonResponse.users[0].last_login).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[0].last_seen).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[0].created_at).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[0].updated_at).should.be.true();

testUtils.API.isISO8601(jsonResponse.users[2].last_login).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[2].last_seen).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[2].created_at).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[2].updated_at).should.be.true();

Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/api/api_users_spec.js
Expand Up @@ -60,7 +60,7 @@ describe('Users API', function () {
}).then(function (response) {
response.users[0].created_at.should.be.an.instanceof(Date);
response.users[0].updated_at.should.be.an.instanceof(Date);
response.users[0].last_login.should.be.an.instanceof(Date);
response.users[0].last_seen.should.be.an.instanceof(Date);

done();
}).catch(done);
Expand Down
4 changes: 2 additions & 2 deletions core/test/integration/model/model_users_spec.js
Expand Up @@ -184,7 +184,7 @@ describe('User Model', function run() {
var userData = testUtils.DataGenerator.forModel.users[0];

UserModel.check({email: userData.email, password: userData.password}).then(function (activeUser) {
should.exist(activeUser.get('last_login'));
should.exist(activeUser.get('last_seen'));
done();
}).catch(done);
});
Expand All @@ -201,7 +201,7 @@ describe('User Model', function run() {

should.exist(user);

lastLogin = user.get('last_login');
lastLogin = user.get('last_seen');
createdAt = user.get('created_at');
updatedAt = user.get('updated_at');

Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/migration_spec.js
Expand Up @@ -19,7 +19,7 @@ var should = require('should'), // jshint ignore:line
// both of which are required for migrations to work properly.
describe('DB version integrity', function () {
// Only these variables should need updating
var currentSchemaHash = '8973f14e9a33601171dee3010d4cffd7',
var currentSchemaHash = '461181eefd9a9171099093b67c59b90a',
currentFixturesHash = 'ad12de59b939b13dc198611a6438ab51';

// If this test is failing, then it is likely a change has been made that requires a DB version bump,
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/models/base/listeners_spec.js
Expand Up @@ -34,7 +34,7 @@ describe('Models: listeners', function () {

userModelSpy.calledOnce.should.be.true();
userModelSpy.calledWith(
sinon.match.has('last_login'),
sinon.match.has('last_seen'),
sinon.match.has('id')
);

Expand Down

0 comments on commit 587ff6f

Please sign in to comment.