mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
Fixed bug in mutation
This commit is contained in:
@@ -14,25 +14,21 @@ module.exports = (user, perm) => {
|
||||
user.password.length > 0
|
||||
);
|
||||
|
||||
case types.CHANGE_USERNAME: {
|
||||
case types.CHANGE_USERNAME:
|
||||
return user.status.username.status === 'REJECTED';
|
||||
|
||||
case types.SET_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();
|
||||
const deadline = moment().subtract(14, 'days');
|
||||
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)
|
||||
)
|
||||
user.status.username.status === 'UNSET' ||
|
||||
get(user, 'status.username.history', []).every(({ created_at }) =>
|
||||
moment(created_at).isBefore(deadline)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
case types.SET_USERNAME:
|
||||
return user.status.username.status === 'UNSET';
|
||||
|
||||
case types.CREATE_COMMENT:
|
||||
case types.CREATE_ACTION:
|
||||
case types.DELETE_ACTION:
|
||||
|
||||
@@ -50,13 +50,10 @@ class ChangeUsername extends React.Component {
|
||||
|
||||
saveChanges = async () => {
|
||||
const { newUsername } = this.state.formData;
|
||||
const { id } = this.props;
|
||||
const { setUsername } = this.props;
|
||||
|
||||
try {
|
||||
await this.props.changeUsername({
|
||||
id,
|
||||
username: newUsername,
|
||||
});
|
||||
await setUsername(newUsername);
|
||||
this.props.notify(
|
||||
'success',
|
||||
t('talk-plugin-auth.change_username.changed_username_success_msg')
|
||||
@@ -173,7 +170,7 @@ class ChangeUsername extends React.Component {
|
||||
}
|
||||
|
||||
ChangeUsername.propTypes = {
|
||||
changeUsername: PropTypes.func.isRequired,
|
||||
setUsername: PropTypes.func.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
username: PropTypes.string,
|
||||
emailAddress: PropTypes.string,
|
||||
|
||||
@@ -3,10 +3,10 @@ import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'plugin-api/beta/client/hocs';
|
||||
import ChangeUsername from '../components/ChangeUsername';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
import { withChangeUsername } from 'plugin-api/beta/client/hocs';
|
||||
import { withSetUsername } from 'plugin-api/beta/client/hocs';
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch);
|
||||
|
||||
export default compose(connect(null, mapDispatchToProps), withChangeUsername)(
|
||||
export default compose(connect(null, mapDispatchToProps), withSetUsername)(
|
||||
ChangeUsername
|
||||
);
|
||||
|
||||
@@ -142,8 +142,9 @@ en:
|
||||
cancel: "Cancel"
|
||||
edit: "Edit"
|
||||
changed_password_msg: "Changed Password - Your password has been successfully changed"
|
||||
change_username:
|
||||
change_username:
|
||||
change_username_note: "Usernames can be changed every 14 days"
|
||||
changed_username_success_msg: "Username has been updated"
|
||||
save: "Save"
|
||||
edit_profile: "Edit Profile"
|
||||
cancel: "Cancel"
|
||||
@@ -255,7 +256,7 @@ es:
|
||||
cancel: "Cancelar"
|
||||
edit: "Editar"
|
||||
changed_password_msg: "Contraseña Actualizada - Tu contraseña ha sido exitosamente actualizada"
|
||||
change_username:
|
||||
change_username:
|
||||
change_username_note: "El usuario puede ser cambiado cada 14 días"
|
||||
save: "Guardar"
|
||||
edit_profile: "Editar Perfil"
|
||||
|
||||
+15
-5
@@ -253,9 +253,19 @@ class Users {
|
||||
},
|
||||
{
|
||||
'status.username.status': { $in: ['APPROVED', 'SET'] },
|
||||
'status.username.history.created_at': {
|
||||
$lte: oldestEditTime,
|
||||
},
|
||||
$or: [
|
||||
{
|
||||
'status.username.history.created_at': {
|
||||
$lte: oldestEditTime,
|
||||
},
|
||||
},
|
||||
{
|
||||
'status.username.history': [],
|
||||
},
|
||||
{
|
||||
'status.username.history': { $exists: false },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -286,8 +296,8 @@ class Users {
|
||||
|
||||
if (
|
||||
!['UNSET', 'APPROVED', 'SET'].includes(user.status.username.status) ||
|
||||
!user.status.username.history.every(({ created_at }) =>
|
||||
oldestEditTime.isAfter(created_at)
|
||||
!user.status.username.history.some(({ created_at }) =>
|
||||
moment(created_at).isAfter(oldestEditTime)
|
||||
)
|
||||
) {
|
||||
throw new ErrPermissionUpdateUsername();
|
||||
|
||||
Reference in New Issue
Block a user