mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Allow a user to change their own username
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { isString } = require('lodash');
|
||||
const { get, isString } = require('lodash');
|
||||
const moment = require('moment');
|
||||
const { check } = require('../utils');
|
||||
const types = require('../constants');
|
||||
|
||||
@@ -12,8 +13,22 @@ module.exports = (user, perm) => {
|
||||
isString(user.password) &&
|
||||
user.password.length > 0
|
||||
);
|
||||
case types.CHANGE_USERNAME:
|
||||
return user.status.username.status === 'REJECTED';
|
||||
|
||||
case types.CHANGE_USERNAME: {
|
||||
// Only users who have their usernames rejected or those users who
|
||||
// not changed their usernames within 14 days can change their usernames.
|
||||
const now = moment();
|
||||
return (
|
||||
user.status.username.status === 'REJECTED' ||
|
||||
get(user, 'status.username.history', [])
|
||||
.filter(({ status }) => status === 'CHANGED')
|
||||
.every(({ created_at }) =>
|
||||
moment(created_at)
|
||||
.add(14, 'days')
|
||||
.isAfter(now)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
case types.SET_USERNAME:
|
||||
return user.status.username.status === 'UNSET';
|
||||
|
||||
Reference in New Issue
Block a user