Skip to content
Snippets Groups Projects
Unverified Commit 30183fd2 authored by Guilherme Gazzo's avatar Guilherme Gazzo Committed by GitHub
Browse files

chore: handle rocket.cat creation and deletion (#31170)

parent db255190
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,13 @@ import { relinquishRoomOwnerships } from './relinquishRoomOwnerships';
import { updateGroupDMsName } from './updateGroupDMsName';
export async function deleteUser(userId: string, confirmRelinquish = false, deletedBy?: IUser['_id']): Promise<void> {
if (userId === 'rocket.cat') {
throw new Meteor.Error('error-action-not-allowed', 'Deleting the rocket.cat user is not allowed', {
method: 'deleteUser',
action: 'Delete_user',
});
}
const user = await Users.findOneById(userId, {
projection: { username: 1, avatarOrigin: 1, roles: 1, federated: 1 },
});
......
......@@ -54,34 +54,41 @@ Meteor.startup(async () => {
Settings.updateValueById('Initial_Channel_Created', true);
}
if (!(await Users.findOneById('rocket.cat'))) {
await Users.create({
_id: 'rocket.cat',
name: 'Rocket.Cat',
username: 'rocket.cat',
status: 'online',
statusDefault: 'online',
utcOffset: 0,
active: true,
type: 'bot',
});
try {
if (!(await Users.findOneById('rocket.cat', { projection: { _id: 1 } }))) {
await Users.create({
_id: 'rocket.cat',
name: 'Rocket.Cat',
username: 'rocket.cat',
status: 'online',
statusDefault: 'online',
utcOffset: 0,
active: true,
type: 'bot',
});
await addUserRolesAsync('rocket.cat', ['bot']);
await addUserRolesAsync('rocket.cat', ['bot']);
const buffer = Buffer.from(await Assets.getBinaryAsync('avatars/rocketcat.png'));
const buffer = Buffer.from(await Assets.getBinaryAsync('avatars/rocketcat.png'));
const rs = RocketChatFile.bufferToStream(buffer, 'utf8');
const fileStore = FileUpload.getStore('Avatars');
await fileStore.deleteByName('rocket.cat');
const rs = RocketChatFile.bufferToStream(buffer, 'utf8');
const fileStore = FileUpload.getStore('Avatars');
await fileStore.deleteByName('rocket.cat');
const file = {
userId: 'rocket.cat',
type: 'image/png',
size: buffer.length,
};
const file = {
userId: 'rocket.cat',
type: 'image/png',
size: buffer.length,
};
const upload = await fileStore.insert(file, rs);
await Users.setAvatarData('rocket.cat', 'local', upload.etag);
const upload = await fileStore.insert(file, rs);
await Users.setAvatarData('rocket.cat', 'local', upload.etag);
}
} catch (error) {
console.log(
'Error creating default `rocket.cat` user, if you created a user with this username please remove it and restart the server',
);
throw error;
}
if (process.env.ADMIN_PASS) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment