Skip to content

Commit

Permalink
Remove GoNEB migrator (#867)
Browse files Browse the repository at this point in the history
* Remove GoNEB migrator.

* changelog

* Remove frontend pieces

* Remove unused statuscodes

* Linting

* Remove warning about ts-comment
  • Loading branch information
Half-Shot authored Dec 28, 2023
1 parent 67dfa44 commit 76a4209
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 327 deletions.
1 change: 1 addition & 0 deletions changelog.d/867.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The GoNEB migrator is being removed in this release. Users wishing to migrate from GoNEB deployments should use <=5.0.0 and then upgrade.
6 changes: 2 additions & 4 deletions src/Connections/GitlabRepo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// We need to instantiate some functions which are not directly called, which confuses typescript.
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { UserTokenStore } from "../UserTokenStore";
import { Appservice, Intent, StateEvent } from "matrix-bot-sdk";
import { BotCommands, botCommand, compileBotCommands } from "../BotCommands";
Expand Down Expand Up @@ -752,7 +750,7 @@ ${data.description}`;
let relation;
const discussionWithThread = result.discussions.find(discussionId => this.discussionThreads.has(discussionId));
if (discussionWithThread) {
const threadEventId = await this.discussionThreads.get(discussionWithThread)!.catch(_ => { /* already logged */ });
const threadEventId = await this.discussionThreads.get(discussionWithThread)?.catch(() => { /* already logged */ });
if (threadEventId) {
relation = {
"m.relates_to": {
Expand Down Expand Up @@ -948,7 +946,7 @@ ${data.description}`;
private async persistDiscussionThreads(): Promise<void> {
const serialized: SerializedGitlabDiscussionThreads = [];
for (const [discussionId, eventIdPromise] of this.discussionThreads.entriesAscending()) {
const eventId = await eventIdPromise.catch(_ => { /* logged elsewhere */ });
const eventId = await eventIdPromise.catch(() => { /* logged elsewhere */ });
if (eventId) {
serialized.push({ discussionId, eventId });
}
Expand Down
43 changes: 0 additions & 43 deletions src/Widgets/BridgeWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import { ConnectionManager } from "../ConnectionManager";
import BotUsersManager, {BotUser} from "../Managers/BotUsersManager";
import { assertUserPermissionsInRoom, GetConnectionsResponseItem } from "../provisioning/api";
import { Appservice, PowerLevelsEvent } from "matrix-bot-sdk";
import { GoNebMigrator } from "./GoNebMigrator";
import { StatusCodes } from "http-status-codes";
import { GithubInstance } from '../github/GithubInstance';
import { AllowedTokenTypes, TokenType, UserTokenStore } from '../UserTokenStore';

const log = new Logger("BridgeWidgetApi");

export class BridgeWidgetApi extends ProvisioningApi {
private readonly goNebMigrator?: GoNebMigrator;

constructor(
private adminRooms: Map<string, AdminRoom>,
private readonly config: BridgeConfig,
Expand Down Expand Up @@ -60,45 +56,6 @@ export class BridgeWidgetApi extends ProvisioningApi {
this.addRoute('get', '/v1/service/:service/auth', wrapHandler(this.getAuth));
this.addRoute('get', '/v1/service/:service/auth/:state', wrapHandler(this.getAuthPoll));
this.addRoute('post', '/v1/service/:service/auth/logout', wrapHandler(this.postAuthLogout));
this.baseRoute.use((err: unknown, _req: Express.Request, _res: Express.Response, _next: NextFunction) => {
// Needed until https://github.com/matrix-org/matrix-appservice-bridge/pull/465 lands.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this as any).onError(err, _req, _res, _next);
});

if (this.config.goNebMigrator) {
this.goNebMigrator = new GoNebMigrator(
this.config.goNebMigrator.apiUrl,
this.config.goNebMigrator.serviceIds,
this.config.goNebMigrator.goNebBotPrefix,
);
}

this.addRoute("get", "/v1/:roomId/goNebConnections", wrapHandler(this.getGoNebConnections));
}

private async getGoNebConnections(req: ProvisioningRequest, res: Response) {
if (!this.goNebMigrator) {
res.status(StatusCodes.NO_CONTENT).send();
return;
}

const roomId = req.params.roomId;

if (!req.userId) {
throw Error('Cannot get connections without a valid userId');
}

const botUser = await this.getBotUserInRoom(roomId);
await assertUserPermissionsInRoom(req.userId, roomId, "read", botUser.intent);

const userIds = this.goNebMigrator.getGoNebUsersFromRoomMembers(
await botUser.intent.underlyingClient.getJoinedRoomMembers(roomId)
);

const connections = await this.goNebMigrator.getConnectionsForRoom(roomId, new Set(userIds));

res.send(connections);
}

private async getBotUserInRoom(roomId: string, serviceType?: string): Promise<BotUser> {
Expand Down
190 changes: 0 additions & 190 deletions src/Widgets/GoNebMigrator.ts

This file was deleted.

14 changes: 3 additions & 11 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,6 @@ export interface BridgeConfigMetrics {
port?: number;
}

export interface BridgeConfigGoNebMigrator {
apiUrl: string;
serviceIds?: string[];
goNebBotPrefix?: string;
}

export interface BridgeConfigSentry {
dsn: string;
environment?: string;
Expand All @@ -477,7 +471,6 @@ export interface BridgeConfigRoot {
widgets?: BridgeWidgetConfigYAML;
metrics?: BridgeConfigMetrics;
listeners?: BridgeConfigListener[];
goNebMigrator?: BridgeConfigGoNebMigrator;
sentry?: BridgeConfigSentry;
}

Expand Down Expand Up @@ -531,9 +524,6 @@ export class BridgeConfig {
'resources' may be any of ${ResourceTypeArray.join(', ')}`)
public readonly listeners: BridgeConfigListener[];

@configKey("go-neb migrator configuration", true)
public readonly goNebMigrator?: BridgeConfigGoNebMigrator;

@configKey("Configure Sentry error reporting", true)
public readonly sentry?: BridgeConfigSentry;

Expand Down Expand Up @@ -603,7 +593,9 @@ export class BridgeConfig {
this.queue.port = env?.CFG_QUEUE_POST ? parseInt(env?.CFG_QUEUE_POST, 10) : undefined;
}

this.goNebMigrator = configData.goNebMigrator;
if ('goNebMigrator' in configData) {
log.warn(`The GoNEB migrator has been removed from this release. You should remove the 'goNebMigrator' from your config.`);
}

// Listeners is a bit special
this.listeners = configData.listeners || [];
Expand Down
4 changes: 0 additions & 4 deletions web/BridgeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ export class BridgeAPI {
return this.request('GET', `/widgetapi/v1/${encodeURIComponent(roomId)}/connections`);
}

async getGoNebConnectionsForRoom(roomId: string): Promise<any|undefined> {
return this.request('GET', `/widgetapi/v1/${encodeURIComponent(roomId)}/goNebConnections`);
}

async getConnectionsForService<T extends GetConnectionsResponseItem >(roomId: string, service: string): Promise<GetConnectionsForServiceResponse<T>> {
return this.request('GET', `/widgetapi/v1/${encodeURIComponent(roomId)}/connections/${encodeURIComponent(service)}`);
}
Expand Down
18 changes: 1 addition & 17 deletions web/components/roomConfig/FeedsConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionComponent, createRef } from "preact";
import { useCallback, useEffect, useState } from "preact/hooks"
import { useCallback, useState } from "preact/hooks"
import { BridgeConfig } from "../../BridgeAPI";
import { FeedConnectionState, FeedResponseItem } from "../../../src/Connections/FeedConnection";
import { ConnectionConfigurationProps, IRoomConfigText, RoomConfig } from "./RoomConfig";
Expand Down Expand Up @@ -93,20 +93,6 @@ const roomConfigText: IRoomConfigText = {
const RoomConfigListItemFunc = (c: FeedResponseItem) => c.config.label || c.config.url;

export const FeedsConfig: BridgeConfig = ({ api, roomId, showHeader }) => {
const [ goNebConnections, setGoNebConnections ] = useState(undefined);

useEffect(() => {
api.getGoNebConnectionsForRoom(roomId).then((res: any) => {
if (!res) return;
setGoNebConnections(res.feeds.map((config: any) => ({
config,
})));
}).catch(ex => {
console.warn("Failed to fetch go neb connections", ex);
});
}, [api, roomId]);

const compareConnections = useCallback((goNebConnection: FeedResponseItem, nativeConnection: FeedResponseItem) => goNebConnection.config.url === nativeConnection.config.url, []);

return <RoomConfig<ServiceConfig, FeedResponseItem, FeedConnectionState>
headerImg={FeedsIcon}
Expand All @@ -118,7 +104,5 @@ export const FeedsConfig: BridgeConfig = ({ api, roomId, showHeader }) => {
text={roomConfigText}
listItemName={RoomConfigListItemFunc}
connectionConfigComponent={ConnectionConfiguration}
migrationCandidates={goNebConnections}
migrationComparator={compareConnections}
/>;
};
Loading

0 comments on commit 76a4209

Please sign in to comment.