Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/definition/externals/meteor/meteor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type StringifyBuffers<T extends unknown[]> = {

declare global {
namespace Assets {
function getBinaryAsync(assetPath: string): Promise<EJSON | undefined>;
function getBinaryAsync(assetPath: string): Promise<Uint8Array | undefined>;

function getTextAsync(assetPath: string): Promise<string | undefined>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UserStatus, type IUser } from '@rocket.chat/core-typings';
import { Settings, Rooms, Users, Roles } from '@rocket.chat/models';
import { validateEmail } from '@rocket.chat/tools';
import colors from 'colors/safe';
Expand All @@ -16,19 +17,16 @@ import { addUserRolesAsync } from '../lib/roles/addUserRoles';
export async function insertAdminUserFromEnv() {
if (process.env.ADMIN_PASS) {
if ((await Roles.countUsersInRole('admin')) === 0) {
const adminUser = {
name: 'Administrator',
const adminUser: Partial<IUser> = {
name: process.env.ADMIN_NAME || 'Administrator',
username: 'admin',
status: 'offline',
statusDefault: 'online',
status: UserStatus.OFFLINE,
statusDefault: UserStatus.ONLINE,
utcOffset: 0,
active: true,
type: 'user',
};

if (process.env.ADMIN_NAME) {
adminUser.name = process.env.ADMIN_NAME;
}

console.log(colors.green(`Name: ${adminUser.name}`));

if (process.env.ADMIN_EMAIL) {
Expand Down Expand Up @@ -75,8 +73,6 @@ export async function insertAdminUserFromEnv() {

console.log(colors.green(`Username: ${adminUser.username}`));

adminUser.type = 'user';

const { insertedId: userId } = await Users.create(adminUser);

await Accounts.setPasswordAsync(userId, process.env.ADMIN_PASS);
Expand Down Expand Up @@ -137,29 +133,32 @@ Meteor.startup(async () => {
_id: 'rocket.cat',
name: 'Rocket.Cat',
username: 'rocket.cat',
status: 'online',
statusDefault: 'online',
status: UserStatus.ONLINE,
statusDefault: UserStatus.ONLINE,
utcOffset: 0,
active: true,
type: 'bot',
});

await addUserRolesAsync('rocket.cat', ['bot']);

const buffer = Buffer.from(await Assets.getBinaryAsync('avatars/rocketcat.png'));
const asset = await Assets.getBinaryAsync('avatars/rocketcat.png');
if (asset) {
const buffer = Buffer.from(asset);

const rs = RocketChatFile.bufferToStream(buffer, 'utf8');
const fileStore = FileUpload.getStore('Avatars');
await fileStore.deleteByName('rocket.cat');
const rs = RocketChatFile.bufferToStream(buffer);
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(
Expand Down Expand Up @@ -211,7 +210,7 @@ Meteor.startup(async () => {
if (process.env.TEST_MODE === 'true') {
console.log(colors.green('Inserting admin test user:'));

const adminUser = {
const adminUser: Omit<IUser, 'createdAt' | 'roles' | '_updatedAt'> = {
_id: 'rocketchat.internal.admin.test',
name: 'RocketChat Internal Admin Test',
username: 'rocketchat.internal.admin.test',
Expand All @@ -221,23 +220,23 @@ Meteor.startup(async () => {
verified: true,
},
],
status: 'offline',
statusDefault: 'online',
status: UserStatus.OFFLINE,
statusDefault: UserStatus.ONLINE,
utcOffset: 0,
active: true,
type: 'user',
};

console.log(colors.green(`Name: ${adminUser.name}`));
console.log(colors.green(`Email: ${adminUser.emails[0].address}`));
console.log(colors.green(`Email: ${adminUser.emails![0].address}`));
console.log(colors.green(`Username: ${adminUser.username}`));
console.log(colors.green(`Password: ${adminUser._id}`));

if (await Users.findOneByEmailAddress(adminUser.emails[0].address)) {
throw new Meteor.Error(`Email ${adminUser.emails[0].address} already exists`, "Rocket.Chat can't run in test mode");
if (await Users.findOneByEmailAddress(adminUser.emails![0].address)) {
throw new Meteor.Error(`Email ${adminUser.emails![0].address} already exists`, "Rocket.Chat can't run in test mode");
}

if (!(await checkUsernameAvailability(adminUser.username))) {
if (!(await checkUsernameAvailability(adminUser.username!))) {
throw new Meteor.Error(`Username ${adminUser.username} already exists`, "Rocket.Chat can't run in test mode");
}

Expand All @@ -252,7 +251,7 @@ Meteor.startup(async () => {
void notifyOnSettingChangedById('Show_Setup_Wizard');
}

await addUserToDefaultChannels(adminUser, true);
await addUserToDefaultChannels(adminUser as IUser, true);

// Create sample call history for API tests
return addCallHistoryTestData('rocketchat.internal.admin.test', 'rocket.cat');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getMongoInfo } from '../../app/utils/server/functions/getMongoInfo';
// import { sendMessagesToAdmins } from '../lib/sendMessagesToAdmins';
import { showErrorBox, showSuccessBox } from '../lib/logger/showBox';

const exitIfNotBypassed = (ignore, errorCode = 1) => {
const exitIfNotBypassed = (ignore: string | undefined, errorCode = 1) => {
if (typeof ignore === 'string' && ['yes', 'true'].includes(ignore.toLowerCase())) {
return;
}
Expand All @@ -28,10 +28,16 @@ Meteor.startup(async () => {
const { mongoVersion, mongoStorageEngine } = await getMongoInfo();

const desiredNodeVersion = semver.clean(fs.readFileSync(path.join(process.cwd(), '../../.node_version.txt')).toString());
const desiredNodeVersionMajor = String(semver.parse(desiredNodeVersion).major);
const parsedSemVer = semver.parse(desiredNodeVersion);
if (!parsedSemVer) {
console.error('Failed to parse desired Node.js version from .node_version.txt');
process.exit(1);
}

const desiredNodeVersionMajor = String(parsedSemVer.major);

return setTimeout(async () => {
let msg = [
let msg: string | string[] = [
`Rocket.Chat Version: ${Info.version}`,
` NodeJS Version: ${process.versions.node} - ${process.arch}`,
` MongoDB Version: ${mongoVersion}`,
Expand All @@ -41,11 +47,11 @@ Meteor.startup(async () => {
` Site URL: ${settings.get('Site_Url')}`,
];

if (Info.commit && Info.commit.hash) {
if (Info.commit?.hash) {
msg.push(` Commit Hash: ${Info.commit.hash.substr(0, 10)}`);
}

if (Info.commit && Info.commit.branch) {
if (Info.commit?.branch) {
msg.push(` Commit Branch: ${Info.commit.branch}`);
}

Expand All @@ -63,7 +69,9 @@ Meteor.startup(async () => {
exitIfNotBypassed(process.env.BYPASS_NODEJS_VALIDATION);
}

if (semver.satisfies(semver.coerce(mongoVersion), '<7.0.0')) {
const mongoSemver = semver.coerce(mongoVersion);

if (!mongoSemver || semver.satisfies(mongoSemver, '<7.0.0')) {
msg += ['', '', 'YOUR CURRENT MONGODB VERSION IS NOT SUPPORTED BY ROCKET.CHAT,', 'PLEASE UPGRADE TO VERSION 7.0 OR LATER'].join('\n');
showErrorBox('SERVER ERROR', msg);

Expand Down
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export interface IRoomsModel extends IBaseModel<IRoom> {
saveRetentionOverrideGlobalById(rid: string, retentionOverrideGlobal: boolean): Promise<UpdateResult>;
saveEncryptedById(rid: string, encrypted: boolean): Promise<UpdateResult>;
updateGroupDMsRemovingUsernamesByUsername(username: string, userId: string): Promise<UpdateResult | Document>;
createWithIdTypeAndName(id: string, type: IRoom['t'], name: string, extraData?: Record<string, string>): Promise<IRoom>;
createWithIdTypeAndName(id: string, type: IRoom['t'], name: string, extraData?: Record<string, unknown>): Promise<IRoom>;
createWithFullRoomData(room: Omit<IRoom, '_id' | '_updatedAt'>): Promise<IRoom>;
removeById(rid: string): Promise<DeleteResult>;
removeByIds(rids: string[]): Promise<DeleteResult>;
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
_id: IRoom['_id'],
type: IRoom['t'],
name: IRoom['name'],
extraData?: Record<string, string>,
extraData?: Record<string, unknown>,
): Promise<IRoom> {
const room: IRoom = {
_id,
Expand Down
Loading