snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Random } from '@rocket.chat/random';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
||||
import { Users } from '@rocket.chat/models';
|
||||
|
||||
import { hasPermissionAsync } from '../../../../../server/lib/authorization/hasPermission';
|
||||
import { twoFactorRequired } from '../../../../../server/lib/2fa/twoFactorRequired';
|
||||
declare module '@rocket.chat/ddp-client' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface ServerMethods {
|
||||
'personalAccessTokens:generateToken'(params: { tokenName: string; bypassTwoFactor: boolean }): Promise<string>;
|
||||
}
|
||||
}
|
||||
|
||||
export const generatePersonalAccessTokenOfUser = async ({
|
||||
bypassTwoFactor,
|
||||
tokenName,
|
||||
userId,
|
||||
}: {
|
||||
tokenName: string;
|
||||
userId: string;
|
||||
bypassTwoFactor: boolean;
|
||||
}): Promise<string> => {
|
||||
if (!(await hasPermissionAsync(userId, 'create-personal-access-tokens'))) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:generateToken',
|
||||
});
|
||||
}
|
||||
|
||||
const token = Random.secret();
|
||||
const tokenExist = await Users.findPersonalAccessTokenByTokenNameAndUserId({
|
||||
userId,
|
||||
tokenName,
|
||||
});
|
||||
if (tokenExist) {
|
||||
throw new Meteor.Error('error-token-already-exists', 'A token with this name already exists', {
|
||||
method: 'personalAccessTokens:generateToken',
|
||||
});
|
||||
}
|
||||
|
||||
await Users.addPersonalAccessTokenToUser({
|
||||
userId,
|
||||
loginTokenObject: {
|
||||
hashedToken: Accounts._hashLoginToken(token),
|
||||
type: 'personalAccessToken',
|
||||
createdAt: new Date(),
|
||||
lastTokenPart: token.slice(-6),
|
||||
name: tokenName,
|
||||
bypassTwoFactor,
|
||||
},
|
||||
});
|
||||
return token;
|
||||
};
|
||||
|
||||
Meteor.methods<ServerMethods>({
|
||||
'personalAccessTokens:generateToken': twoFactorRequired(async function ({
|
||||
tokenName,
|
||||
bypassTwoFactor,
|
||||
}: {
|
||||
tokenName: string;
|
||||
bypassTwoFactor: boolean;
|
||||
}) {
|
||||
const uid = Meteor.userId();
|
||||
if (!uid) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:generateToken',
|
||||
});
|
||||
}
|
||||
|
||||
return generatePersonalAccessTokenOfUser({ tokenName, userId: uid, bypassTwoFactor });
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
import './generateToken';
|
||||
import './regenerateToken';
|
||||
import './removeToken';
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
||||
import { Users } from '@rocket.chat/models';
|
||||
import { isPersonalAccessToken } from '@rocket.chat/core-typings';
|
||||
|
||||
import { hasPermissionAsync } from '../../../../../server/lib/authorization/hasPermission';
|
||||
import { twoFactorRequired } from '../../../../../server/lib/2fa/twoFactorRequired';
|
||||
import { removePersonalAccessTokenOfUser } from './removeToken';
|
||||
import { generatePersonalAccessTokenOfUser } from './generateToken';
|
||||
declare module '@rocket.chat/ddp-client' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface ServerMethods {
|
||||
'personalAccessTokens:regenerateToken'(params: { tokenName: string }): Promise<string>;
|
||||
}
|
||||
}
|
||||
|
||||
export const regeneratePersonalAccessTokenOfUser = async (tokenName: string, userId: string): Promise<string> => {
|
||||
if (!(await hasPermissionAsync(userId, 'create-personal-access-tokens'))) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:regenerateToken',
|
||||
});
|
||||
}
|
||||
|
||||
const tokenExist = await Users.findPersonalAccessTokenByTokenNameAndUserId({
|
||||
userId,
|
||||
tokenName,
|
||||
});
|
||||
if (!tokenExist) {
|
||||
throw new Meteor.Error('error-token-does-not-exists', 'Token does not exist', {
|
||||
method: 'personalAccessTokens:regenerateToken',
|
||||
});
|
||||
}
|
||||
|
||||
await removePersonalAccessTokenOfUser(tokenName, userId);
|
||||
|
||||
const tokenObject = tokenExist.services?.resume?.loginTokens?.find((token) => isPersonalAccessToken(token) && token.name === tokenName);
|
||||
|
||||
return generatePersonalAccessTokenOfUser({
|
||||
tokenName,
|
||||
userId,
|
||||
bypassTwoFactor: (tokenObject && isPersonalAccessToken(tokenObject) && tokenObject.bypassTwoFactor) || false,
|
||||
});
|
||||
};
|
||||
|
||||
Meteor.methods<ServerMethods>({
|
||||
'personalAccessTokens:regenerateToken': twoFactorRequired(async function ({ tokenName }: { tokenName: string }) {
|
||||
const uid = Meteor.userId();
|
||||
if (!uid) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:regenerateToken',
|
||||
});
|
||||
}
|
||||
|
||||
return regeneratePersonalAccessTokenOfUser(tokenName, uid);
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
||||
import { Users } from '@rocket.chat/models';
|
||||
|
||||
import { hasPermissionAsync } from '../../../../../server/lib/authorization/hasPermission';
|
||||
import { twoFactorRequired } from '../../../../../server/lib/2fa/twoFactorRequired';
|
||||
declare module '@rocket.chat/ddp-client' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface ServerMethods {
|
||||
'personalAccessTokens:removeToken'(params: { tokenName: string }): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
||||
export const removePersonalAccessTokenOfUser = async (tokenName: string, userId: string): Promise<void> => {
|
||||
if (!(await hasPermissionAsync(userId, 'create-personal-access-tokens'))) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:removeToken',
|
||||
});
|
||||
}
|
||||
const tokenExist = await Users.findPersonalAccessTokenByTokenNameAndUserId({
|
||||
userId,
|
||||
tokenName,
|
||||
});
|
||||
if (!tokenExist) {
|
||||
throw new Meteor.Error('error-token-does-not-exists', 'Token does not exist', {
|
||||
method: 'personalAccessTokens:removeToken',
|
||||
});
|
||||
}
|
||||
await Users.removePersonalAccessTokenOfUser({
|
||||
userId,
|
||||
loginTokenObject: {
|
||||
type: 'personalAccessToken',
|
||||
name: tokenName,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Meteor.methods<ServerMethods>({
|
||||
'personalAccessTokens:removeToken': twoFactorRequired(async function ({ tokenName }: { tokenName: string }) {
|
||||
const uid = Meteor.userId();
|
||||
if (!uid) {
|
||||
throw new Meteor.Error('not-authorized', 'Not Authorized', {
|
||||
method: 'personalAccessTokens:removeToken',
|
||||
});
|
||||
}
|
||||
|
||||
return removePersonalAccessTokenOfUser(tokenName, uid);
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user