Backend support
This commit is contained in:
@@ -63,4 +63,20 @@ Team.prototype.removeAdmin = async function(user: User) {
|
||||
}
|
||||
};
|
||||
|
||||
Team.prototype.suspendUser = async function(user: User, admin: User) {
|
||||
if (user.id === admin.id)
|
||||
throw new Error('Unable to suspend the current user');
|
||||
return user.update({
|
||||
suspendedById: admin.id,
|
||||
suspendedAt: new Date(),
|
||||
});
|
||||
};
|
||||
|
||||
Team.prototype.activateUser = async function(user: User, admin: User) {
|
||||
return user.update({
|
||||
suspendedById: null,
|
||||
suspendedAt: null,
|
||||
});
|
||||
};
|
||||
|
||||
export default Team;
|
||||
|
||||
@@ -28,8 +28,14 @@ const User = sequelize.define(
|
||||
slackId: { type: DataTypes.STRING, allowNull: true, unique: true },
|
||||
slackData: DataTypes.JSONB,
|
||||
jwtSecret: encryptedFields.vault('jwtSecret'),
|
||||
suspendedAt: DataTypes.DATE,
|
||||
},
|
||||
{
|
||||
getterMethods: {
|
||||
isSuspended() {
|
||||
return !!this.suspendedAt;
|
||||
},
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
fields: ['email'],
|
||||
@@ -43,6 +49,10 @@ User.associate = models => {
|
||||
User.hasMany(models.ApiKey, { as: 'apiKeys' });
|
||||
User.hasMany(models.Document, { as: 'documents' });
|
||||
User.hasMany(models.View, { as: 'views' });
|
||||
User.belongsTo(models.User, {
|
||||
as: 'suspendedBy',
|
||||
foreignKey: 'suspendedById',
|
||||
});
|
||||
};
|
||||
|
||||
// Instance methods
|
||||
|
||||
Reference in New Issue
Block a user