Remove legacy gitter bridge support

This commit is contained in:
Travis Ralston 2020-12-28 21:10:23 -07:00
parent 88b155d81f
commit f7ed739423
25 changed files with 6 additions and 881 deletions

View File

@ -52,7 +52,6 @@ export const CACHE_IRC_BRIDGE = "irc-bridge";
export const CACHE_STICKERS = "stickers";
export const CACHE_TELEGRAM_BRIDGE = "telegram-bridge";
export const CACHE_WEBHOOKS_BRIDGE = "webhooks-bridge";
export const CACHE_GITTER_BRIDGE = "gitter-bridge";
export const CACHE_SIMPLE_BOTS = "simple-bots";
export const CACHE_SLACK_BRIDGE = "slack-bridge";
export const CACHE_TERMS = "terms";
export const CACHE_TERMS = "terms";

View File

@ -1,115 +0,0 @@
import { Context, GET, Path, PathParam, POST, Security, ServiceContext } from "typescript-rest";
import { Cache, CACHE_GITTER_BRIDGE, CACHE_INTEGRATIONS } from "../../MemoryCache";
import { LogService } from "matrix-js-snippets";
import { ApiError } from "../ApiError";
import GitterBridgeRecord from "../../db/models/GitterBridgeRecord";
import Upstream from "../../db/models/Upstream";
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
interface CreateWithUpstream {
upstreamId: number;
}
interface CreateSelfhosted {
provisionUrl: string;
}
interface BridgeResponse {
id: number;
upstreamId?: number;
provisionUrl?: string;
isEnabled: boolean;
}
/**
* Administrative API for configuring Gitter bridge instances.
*/
@Path("/api/v1/dimension/admin/gitter")
export class AdminGitterService {
@Context
private context: ServiceContext;
@GET
@Path("all")
@Security([ROLE_USER, ROLE_ADMIN])
public async getBridges(): Promise<BridgeResponse[]> {
const bridges = await GitterBridgeRecord.findAll();
return Promise.all(bridges.map(async b => {
return {
id: b.id,
upstreamId: b.upstreamId,
provisionUrl: b.provisionUrl,
isEnabled: b.isEnabled,
};
}));
}
@GET
@Path(":bridgeId")
@Security([ROLE_USER, ROLE_ADMIN])
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
const telegramBridge = await GitterBridgeRecord.findByPk(bridgeId);
if (!telegramBridge) throw new ApiError(404, "Gitter Bridge not found");
return {
id: telegramBridge.id,
upstreamId: telegramBridge.upstreamId,
provisionUrl: telegramBridge.provisionUrl,
isEnabled: telegramBridge.isEnabled,
};
}
@POST
@Path(":bridgeId")
@Security([ROLE_USER, ROLE_ADMIN])
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
const userId = this.context.request.user.userId;
const bridge = await GitterBridgeRecord.findByPk(bridgeId);
if (!bridge) throw new ApiError(404, "Bridge not found");
bridge.provisionUrl = request.provisionUrl;
await bridge.save();
LogService.info("AdminGitterService", userId + " updated Gitter Bridge " + bridge.id);
Cache.for(CACHE_GITTER_BRIDGE).clear();
Cache.for(CACHE_INTEGRATIONS).clear();
return this.getBridge(bridge.id);
}
@POST
@Path("new/upstream")
@Security([ROLE_USER, ROLE_ADMIN])
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
const userId = this.context.request.user.userId;
const upstream = await Upstream.findByPk(request.upstreamId);
if (!upstream) throw new ApiError(400, "Upstream not found");
const bridge = await GitterBridgeRecord.create({
upstreamId: request.upstreamId,
isEnabled: true,
});
LogService.info("AdminGitterService", userId + " created a new Gitter Bridge from upstream " + request.upstreamId);
Cache.for(CACHE_GITTER_BRIDGE).clear();
Cache.for(CACHE_INTEGRATIONS).clear();
return this.getBridge(bridge.id);
}
@POST
@Path("new/selfhosted")
@Security([ROLE_USER, ROLE_ADMIN])
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
const userId = this.context.request.user.userId;
const bridge = await GitterBridgeRecord.create({
provisionUrl: request.provisionUrl,
isEnabled: true,
});
LogService.info("AdminGitterService", userId + " created a new Gitter Bridge with provisioning URL " + request.provisionUrl);
Cache.for(CACHE_GITTER_BRIDGE).clear();
Cache.for(CACHE_INTEGRATIONS).clear();
return this.getBridge(bridge.id);
}
}

View File

@ -1,64 +0,0 @@
import { Context, DELETE, GET, Path, PathParam, POST, Security, ServiceContext } from "typescript-rest";
import { ApiError } from "../ApiError";
import { BridgedRoom, GitterBridge } from "../../bridges/GitterBridge";
import { LogService } from "matrix-js-snippets";
import { ROLE_USER } from "../security/MatrixSecurity";
interface BridgeRoomRequest {
gitterRoomName: string;
}
/**
* API for interacting with the Gitter bridge
*/
@Path("/api/v1/dimension/gitter")
export class DimensionGitterService {
@Context
private context: ServiceContext;
@GET
@Path("room/:roomId/link")
@Security(ROLE_USER)
public async getLink(@PathParam("roomId") roomId: string): Promise<BridgedRoom> {
const userId = this.context.request.user.userId;
try {
const gitter = new GitterBridge(userId);
return gitter.getLink(roomId);
} catch (e) {
LogService.error("DimensionGitterService", e);
throw new ApiError(400, "Error getting bridge info");
}
}
@POST
@Path("room/:roomId/link")
@Security(ROLE_USER)
public async bridgeRoom(@PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<BridgedRoom> {
const userId = this.context.request.user.userId;
try {
const gitter = new GitterBridge(userId);
await gitter.requestLink(roomId, request.gitterRoomName);
return gitter.getLink(roomId);
} catch (e) {
LogService.error("DimensionGitterService", e);
throw new ApiError(400, "Error bridging room");
}
}
@DELETE
@Path("room/:roomId/link")
@Security(ROLE_USER)
public async unbridgeRoom(@PathParam("roomId") roomId: string): Promise<any> {
const userId = this.context.request.user.userId;
try {
const gitter = new GitterBridge(userId);
const link = await gitter.getLink(roomId);
await gitter.removeLink(roomId, link.gitterRoomName);
return {}; // 200 OK
} catch (e) {
LogService.error("DimensionGitterService", e);
throw new ApiError(400, "Error unbridging room");
}
}
}

View File

@ -1,205 +0,0 @@
import IrcBridgeRecord from "../db/models/IrcBridgeRecord";
import Upstream from "../db/models/Upstream";
import UserScalarToken from "../db/models/UserScalarToken";
import { LogService } from "matrix-js-snippets";
import * as request from "request";
import { ModularGitterResponse } from "../models/ModularResponses";
import GitterBridgeRecord from "../db/models/GitterBridgeRecord";
import { BridgedRoomResponse, GetBotUserIdResponse } from "./models/gitter";
export interface GitterBridgeInfo {
botUserId: string;
}
export interface BridgedRoom {
roomId: string;
gitterRoomName: string;
}
export class GitterBridge {
constructor(private requestingUserId: string) {
}
private async getDefaultBridge(): Promise<GitterBridgeRecord> {
const bridges = await GitterBridgeRecord.findAll({where: {isEnabled: true}});
if (!bridges || bridges.length !== 1) {
throw new Error("No bridges or too many bridges found");
}
return bridges[0];
}
public async isBridgingEnabled(): Promise<boolean> {
const bridges = await GitterBridgeRecord.findAll({where: {isEnabled: true}});
return !!bridges && bridges.length > 0;
}
public async getBridgeInfo(): Promise<GitterBridgeInfo> {
const bridge = await this.getDefaultBridge();
if (bridge.upstreamId) {
const info = await this.doUpstreamRequest<ModularGitterResponse<GetBotUserIdResponse>>(bridge, "POST", "/bridges/gitter/_matrix/provision/getbotid/", null, {});
if (!info || !info.replies || !info.replies[0] || !info.replies[0].response) {
throw new Error("Invalid response from Modular for Gitter bot user ID");
}
return {botUserId: info.replies[0].response.bot_user_id};
} else {
const info = await this.doProvisionRequest<GetBotUserIdResponse>(bridge, "POST", "/_matrix/provision/getbotid");
return {botUserId: info.bot_user_id};
}
}
public async getLink(roomId: string): Promise<BridgedRoom> {
const bridge = await this.getDefaultBridge();
const requestBody = {
matrix_room_id: roomId,
user_id: this.requestingUserId,
};
try {
if (bridge.upstreamId) {
delete requestBody["user_id"];
const link = await this.doUpstreamRequest<ModularGitterResponse<BridgedRoomResponse>>(bridge, "POST", "/bridges/gitter/_matrix/provision/getlink", null, requestBody);
if (!link || !link.replies || !link.replies[0] || !link.replies[0].response) {
// noinspection ExceptionCaughtLocallyJS
throw new Error("Invalid response from Modular for Gitter list links in " + roomId);
}
return {
roomId: link.replies[0].response.matrix_room_id,
gitterRoomName: link.replies[0].response.remote_room_name,
};
} else {
const link = await this.doProvisionRequest<BridgedRoomResponse>(bridge, "POST", "/_matrix/provision/getlink", null, requestBody);
return {
roomId: link.matrix_room_id,
gitterRoomName: link.remote_room_name,
};
}
} catch (e) {
if (e.status === 404) return null;
LogService.error("GitterBridge", e);
throw e;
}
}
public async requestLink(roomId: string, remoteName: string): Promise<any> {
const bridge = await this.getDefaultBridge();
const requestBody = {
matrix_room_id: roomId,
remote_room_name: remoteName,
user_id: this.requestingUserId,
};
if (bridge.upstreamId) {
delete requestBody["user_id"];
await this.doUpstreamRequest(bridge, "POST", "/bridges/gitter/_matrix/provision/link", null, requestBody);
} else {
await this.doProvisionRequest(bridge, "POST", "/_matrix/provision/link", null, requestBody);
}
}
public async removeLink(roomId: string, remoteName: string): Promise<any> {
const bridge = await this.getDefaultBridge();
const requestBody = {
matrix_room_id: roomId,
remote_room_name: remoteName,
user_id: this.requestingUserId,
};
if (bridge.upstreamId) {
delete requestBody["user_id"];
await this.doUpstreamRequest(bridge, "POST", "/bridges/gitter/_matrix/provision/unlink", null, requestBody);
} else {
await this.doProvisionRequest(bridge, "POST", "/_matrix/provision/unlink", null, requestBody);
}
}
private async doUpstreamRequest<T>(bridge: IrcBridgeRecord, method: string, endpoint: string, qs?: any, body?: any): Promise<T> {
const upstream = await Upstream.findByPk(bridge.upstreamId);
const token = await UserScalarToken.findOne({
where: {
upstreamId: upstream.id,
isDimensionToken: false,
userId: this.requestingUserId,
},
});
if (!qs) qs = {};
qs["scalar_token"] = token.scalarToken;
const apiUrl = upstream.apiUrl.endsWith("/") ? upstream.apiUrl.substring(0, upstream.apiUrl.length - 1) : upstream.apiUrl;
const url = apiUrl + (endpoint.startsWith("/") ? endpoint : "/" + endpoint);
LogService.info("GitterBridge", "Doing upstream Gitter Bridge request: " + url);
return new Promise<T>((resolve, reject) => {
request({
method: method,
url: url,
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("GitterBridge", "Error calling " + url);
LogService.error("GitterBridge", err);
reject(err);
} else if (!res) {
LogService.error("GitterBridge", "There is no response for " + url);
reject(new Error("No response provided - is the service online?"));
} else if (res.statusCode !== 200) {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
LogService.error("GitterBridge", "Got status code " + res.statusCode + " when calling " + url);
LogService.error("GitterBridge", res.body);
reject({body: res.body, status: res.statusCode});
} else {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("GitterBridge", e);
reject(e);
}
});
});
}
private async doProvisionRequest<T>(bridge: IrcBridgeRecord, method: string, endpoint: string, qs?: any, body?: any): Promise<T> {
const provisionUrl = bridge.provisionUrl;
const apiUrl = provisionUrl.endsWith("/") ? provisionUrl.substring(0, provisionUrl.length - 1) : provisionUrl;
const url = apiUrl + (endpoint.startsWith("/") ? endpoint : "/" + endpoint);
LogService.info("GitterBridge", "Doing provision Gitter Bridge request: " + url);
return new Promise<T>((resolve, reject) => {
request({
method: method,
url: url,
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("GitterBridge", "Error calling" + url);
LogService.error("GitterBridge", err);
reject(err);
} else if (!res) {
LogService.error("GitterBridge", "There is no response for " + url);
reject(new Error("No response provided - is the service online?"));
} else if (res.statusCode !== 200) {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
LogService.error("GitterBridge", "Got status code " + res.statusCode + " when calling " + url);
LogService.error("GitterBridge", res.body);
reject({body: res.body, status: res.statusCode});
} else {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("GitterBridge", e);
reject(e);
}
});
});
}
}

View File

@ -1,6 +1,5 @@
import {
Bridge,
GitterBridgeConfiguration,
SlackBridgeConfiguration,
TelegramBridgeConfiguration,
WebhookBridgeConfiguration
@ -10,7 +9,6 @@ import { IrcBridge } from "../bridges/IrcBridge";
import { LogService } from "matrix-js-snippets";
import { TelegramBridge } from "../bridges/TelegramBridge";
import { WebhooksBridge } from "../bridges/WebhooksBridge";
import { GitterBridge } from "../bridges/GitterBridge";
import { SlackBridge } from "../bridges/SlackBridge";
export class BridgeStore {
@ -61,7 +59,7 @@ export class BridgeStore {
const record = await BridgeRecord.findOne({where: {type: integrationType}});
if (!record) throw new Error("Bridge not found");
const hasDedicatedApi = ["irc", "telegram", "webhooks", "gitter", "slack"];
const hasDedicatedApi = ["irc", "telegram", "webhooks", "slack"];
if (hasDedicatedApi.indexOf(integrationType) !== -1) {
throw new Error("This bridge should be modified with the dedicated API");
} else throw new Error("Unsupported bridge");
@ -77,9 +75,6 @@ export class BridgeStore {
} else if (record.type === "webhooks") {
const webhooks = new WebhooksBridge(requestingUserId);
return webhooks.isBridgingEnabled();
} else if (record.type === "gitter") {
const gitter = new GitterBridge(requestingUserId);
return gitter.isBridgingEnabled();
} else if (record.type === "slack") {
const slack = new SlackBridge(requestingUserId);
return slack.isBridgingEnabled();
@ -96,9 +91,6 @@ export class BridgeStore {
} else if (record.type === "webhooks") {
const webhooks = new WebhooksBridge(requestingUserId);
return webhooks.isBridgingEnabled();
} else if (record.type === "gitter") {
const gitter = new GitterBridge(requestingUserId);
return gitter.isBridgingEnabled();
} else if (record.type === "slack") {
const slack = new SlackBridge(requestingUserId);
return slack.isBridgingEnabled();
@ -130,15 +122,6 @@ export class BridgeStore {
webhooks: hooks,
botUserId: info.botUserId,
};
} else if (record.type === "gitter") {
if (!inRoomId) return {}; // The bridge's admin config is handled by other APIs
const gitter = new GitterBridge(requestingUserId);
const info = await gitter.getBridgeInfo();
const link = await gitter.getLink(inRoomId);
return <GitterBridgeConfiguration>{
link: link,
botUserId: info.botUserId,
};
} else if (record.type === "slack") {
if (!inRoomId) return {}; // The bridge's admin config is handled by other APIs
const slack = new SlackBridge(requestingUserId);
@ -154,4 +137,4 @@ export class BridgeStore {
private constructor() {
}
}
}

View File

@ -23,7 +23,6 @@ import Sticker from "./models/Sticker";
import UserStickerPack from "./models/UserStickerPack";
import TelegramBridgeRecord from "./models/TelegramBridgeRecord";
import WebhookBridgeRecord from "./models/WebhookBridgeRecord";
import GitterBridgeRecord from "./models/GitterBridgeRecord";
import CustomSimpleBotRecord from "./models/CustomSimpleBotRecord";
import SlackBridgeRecord from "./models/SlackBridgeRecord";
import TermsRecord from "./models/TermsRecord";
@ -70,7 +69,6 @@ class _DimensionStore {
UserStickerPack,
TelegramBridgeRecord,
WebhookBridgeRecord,
GitterBridgeRecord,
CustomSimpleBotRecord,
SlackBridgeRecord,
TermsRecord,

View File

@ -1,26 +0,0 @@
import { AllowNull, AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import Upstream from "./Upstream";
@Table({
tableName: "dimension_gitter_bridges",
underscored: false,
timestamps: false,
})
export default class GitterBridgeRecord extends Model<GitterBridgeRecord> {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@AllowNull
@Column
@ForeignKey(() => Upstream)
upstreamId?: number;
@AllowNull
@Column
provisionUrl?: string;
@Column
isEnabled: boolean;
}

View File

@ -3,10 +3,9 @@ import BridgeRecord from "../db/models/BridgeRecord";
import { AvailableNetworks, LinkedChannels } from "../bridges/IrcBridge";
import { PortalInfo, PuppetInfo } from "../bridges/TelegramBridge";
import { WebhookConfiguration } from "../bridges/models/webhooks";
import { BridgedRoom } from "../bridges/GitterBridge";
import { BridgedChannel } from "../bridges/SlackBridge";
const PRIVATE_ACCESS_SUPPORTED_BRIDGES = ["webhooks", "gitter"];
const PRIVATE_ACCESS_SUPPORTED_BRIDGES = ["webhooks"];
export class Bridge extends Integration {
constructor(bridge: BridgeRecord, public config: any) {
@ -42,12 +41,7 @@ export interface WebhookBridgeConfiguration {
botUserId: string;
}
export interface GitterBridgeConfiguration {
link: BridgedRoom;
botUserId: string;
}
export interface SlackBridgeConfiguration {
link: BridgedChannel;
botUserId: string;
}
}

View File

@ -10,16 +10,9 @@ export interface ModularIrcResponse<T> {
}[];
}
export interface ModularGitterResponse<T> {
replies: {
rid: string;
response: T;
}[];
}
export interface ModularSlackResponse<T> {
replies: {
rid: string;
response: T;
}[];
}
}

View File

@ -1,47 +0,0 @@
<div *ngIf="isLoading">
<my-spinner></my-spinner>
</div>
<div *ngIf="!isLoading">
<my-ibox boxTitle="Gitter Bridge Configurations">
<div class="my-ibox-content">
<p>
<a href="https://github.com/matrix-org/matrix-appservice-gitter" target="_blank">{{'matrix-appservice-gitter' | translate}}</a>
{{'is a Gitter bridge that supports bridging Gitter rooms to Matrix. Users on Matrix are represented as a single bot user in Gitter, however Gitter users are represented as real-looking Matrix users in the room.' | translate}}
</p>
<table class="table table-striped table-condensed table-bordered">
<thead>
<tr>
<th>{{'Name' | translate}}</th>
<th class="text-center" style="width: 120px;">{{'Actions' | translate}}</th>
</tr>
</thead>
<tbody>
<tr *ngIf="!configurations || configurations.length === 0">
<td colspan="2"><i>{{'No bridge configurations.' | translate}}</i></td>
</tr>
<tr *ngFor="let bridge of configurations trackById">
<td>
{{ bridge.upstreamId ? "matrix.org's bridge" : "Self-hosted bridge" }}
<span class="text-muted" style="display: inline-block;"
*ngIf="!bridge.upstreamId">({{ bridge.provisionUrl }})</span>
</td>
<td class="text-center">
<span class="editButton" (click)="editBridge(bridge)" *ngIf="!bridge.upstreamId">
<i class="fa fa-pencil-alt"></i>
</span>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-success btn-sm" (click)="addModularHostedBridge()"
[disabled]="(configurations && configurations.length > 0) || isUpdating">
<i class="fa fa-plus"></i>{{'Add matrix.org\'s bridge' | translate}}
</button>
<button type="button" class="btn btn-success btn-sm" (click)="addSelfHostedBridge()"
[disabled]="(configurations && configurations.length > 0) || isUpdating">
<i class="fa fa-plus"></i>{{'Add self-hosted bridge' | translate}}
</button>
</div>
</my-ibox>
</div>

View File

@ -1,3 +0,0 @@
.editButton {
cursor: pointer;
}

View File

@ -1,105 +0,0 @@
import { Component, OnInit } from "@angular/core";
import { ToasterService } from "angular2-toaster";
import { Modal, overlayConfigFactory } from "ngx-modialog";
import {
AdminGitterBridgeManageSelfhostedComponent,
ManageSelfhostedGitterBridgeDialogContext
} from "./manage-selfhosted/manage-selfhosted.component";
import { AdminGitterApiService } from "../../../shared/services/admin/admin-gitter-api.service";
import { FE_GitterBridge } from "../../../shared/models/gitter";
import { FE_Upstream } from "../../../shared/models/admin-responses";
import { AdminUpstreamApiService } from "../../../shared/services/admin/admin-upstream-api.service";
import { TranslateService } from "@ngx-translate/core";
@Component({
templateUrl: "./gitter.component.html",
styleUrls: ["./gitter.component.scss"],
})
export class AdminGitterBridgeComponent implements OnInit {
public isLoading = true;
public isUpdating = false;
public configurations: FE_GitterBridge[] = [];
private upstreams: FE_Upstream[];
constructor(private gitterApi: AdminGitterApiService,
private upstreamApi: AdminUpstreamApiService,
private toaster: ToasterService,
private modal: Modal,
public translate: TranslateService) {
this.translate = translate;
}
public ngOnInit() {
this.reload().then(() => this.isLoading = false);
}
private async reload(): Promise<any> {
try {
this.upstreams = await this.upstreamApi.getUpstreams();
this.configurations = await this.gitterApi.getBridges();
} catch (err) {
console.error(err);
this.translate.get('Error loading bridges').subscribe((res: string) => {this.toaster.pop("error", res); } );
}
}
public addModularHostedBridge() {
this.isUpdating = true;
const createBridge = (upstream: FE_Upstream) => {
return this.gitterApi.newFromUpstream(upstream).then(bridge => {
this.configurations.push(bridge);
this.translate.get('matrix.org\'s Gitter bridge added').subscribe((res: string) => {this.toaster.pop("success", res); });
this.isUpdating = false;
}).catch(err => {
console.error(err);
this.isUpdating = false;
this.translate.get('Error adding matrix.org\'s Gitter Bridge').subscribe((res: string) => {this.toaster.pop("error", res); } );
});
};
const vectorUpstreams = this.upstreams.filter(u => u.type === "vector");
if (vectorUpstreams.length === 0) {
console.log("Creating default scalar upstream");
const scalarUrl = "https://scalar.vector.im/api";
this.upstreamApi.newUpstream("modular", "vector", scalarUrl, scalarUrl).then(upstream => {
this.upstreams.push(upstream);
createBridge(upstream);
}).catch(err => {
console.error(err);
this.translate.get('Error creating matrix.org\'s Gitter Bridge').subscribe((res: string) => {this.toaster.pop("error", res); } );
});
} else createBridge(vectorUpstreams[0]);
}
public addSelfHostedBridge() {
this.modal.open(AdminGitterBridgeManageSelfhostedComponent, overlayConfigFactory({
isBlocking: true,
size: 'lg',
provisionUrl: '',
}, ManageSelfhostedGitterBridgeDialogContext)).result.then(() => {
this.reload().catch(err => {
console.error(err);
this.translate.get('Failed to get an update Gitter bridge list').subscribe((res: string) => {this.toaster.pop("error", res); } );
});
});
}
public editBridge(bridge: FE_GitterBridge) {
this.modal.open(AdminGitterBridgeManageSelfhostedComponent, overlayConfigFactory({
isBlocking: true,
size: 'lg',
provisionUrl: bridge.provisionUrl,
bridgeId: bridge.id,
}, ManageSelfhostedGitterBridgeDialogContext)).result.then(() => {
this.reload().catch(err => {
console.error(err);
this.translate.get('Failed to get an update Gitter bridge list').subscribe((res: string) => {this.toaster.pop("error", res); } );
});
});
}
}

View File

@ -1,28 +0,0 @@
<div class="dialog">
<div class="dialog-header">
<h4> {{'self-hosted Gitter bridge' | translate}} ({{ isAdding ? "Add a new" : "Edit" }})</h4>
</div>
<div class="dialog-content">
<p>
{{'Self-hosted Gitter bridges already have provisioning enabled. Be careful not to expose the API to the public internet.' | translate}}
</p>
<label class="label-block">
{{'Provisioning URL' | translate}}
<span class="text-muted ">
{{'The provisioning URL for the bridge. This is usually the same as the URL your homeserver uses to communicate with the bridge.' | translate}}
</span>
<input type="text" class="form-control"
placeholder="http://localhost:9000"
[(ngModel)]="provisionUrl" [disabled]="isSaving"/>
</label>
</div>
<div class="dialog-footer">
<button type="button" (click)="add()" title="close" class="btn btn-primary btn-sm">
<i class="far fa-save"></i> {{'Save' | translate}}
</button>
<button type="button" (click)="dialog.close()" title="close" class="btn btn-secondary btn-sm">
<i class="far fa-times-circle"></i> {{'Cancel' | translate}}
</button>
</div>
</div>

View File

@ -1,56 +0,0 @@
import { Component } from "@angular/core";
import { ToasterService } from "angular2-toaster";
import { DialogRef, ModalComponent } from "ngx-modialog";
import { BSModalContext } from "ngx-modialog/plugins/bootstrap";
import { AdminGitterApiService } from "../../../../shared/services/admin/admin-gitter-api.service";
import { TranslateService } from "@ngx-translate/core";
export class ManageSelfhostedGitterBridgeDialogContext extends BSModalContext {
public provisionUrl: string;
public bridgeId: number;
}
@Component({
templateUrl: "./manage-selfhosted.component.html",
styleUrls: ["./manage-selfhosted.component.scss"],
})
export class AdminGitterBridgeManageSelfhostedComponent implements ModalComponent<ManageSelfhostedGitterBridgeDialogContext> {
public isSaving = false;
public provisionUrl: string;
public bridgeId: number;
public isAdding = false;
constructor(public dialog: DialogRef<ManageSelfhostedGitterBridgeDialogContext>,
private gitterApi: AdminGitterApiService,
private toaster: ToasterService,
public translate: TranslateService) {
this.translate = translate;
this.provisionUrl = dialog.context.provisionUrl;
this.bridgeId = dialog.context.bridgeId;
this.isAdding = !this.bridgeId;
}
public add() {
this.isSaving = true;
if (this.isAdding) {
this.gitterApi.newSelfhosted(this.provisionUrl).then(() => {
this.translate.get('Gitter bridge added').subscribe((res: string) => {this.toaster.pop("success", res); });
this.dialog.close();
}).catch(err => {
console.error(err);
this.isSaving = false;
this.translate.get('Failed to create Gitter bridge').subscribe((res: string) => { this.toaster.pop("error", res); });
});
} else {
this.gitterApi.updateSelfhosted(this.bridgeId, this.provisionUrl).then(() => {
this.translate.get('Gitter bridge updated').subscribe((res: string) => {this.toaster.pop("success", res); });
this.dialog.close();
}).catch(err => {
console.error(err);
this.isSaving = false;
this.translate.get('Failed to update Gitter bridge').subscribe((res: string) => {this.toaster.pop("error", res); });
});
}
}
}

View File

@ -90,11 +90,6 @@ import { AdminWebhooksBridgeComponent } from "./admin/bridges/webhooks/webhooks.
import { AdminWebhooksApiService } from "./shared/services/admin/admin-webhooks-api.service";
import { WebhooksApiService } from "./shared/services/integrations/webhooks-api.service";
import { WebhooksBridgeConfigComponent } from "./configs/bridge/webhooks/webhooks.bridge.component";
import { AdminGitterBridgeComponent } from "./admin/bridges/gitter/gitter.component";
import { AdminGitterBridgeManageSelfhostedComponent } from "./admin/bridges/gitter/manage-selfhosted/manage-selfhosted.component";
import { AdminGitterApiService } from "./shared/services/admin/admin-gitter-api.service";
import { GitterBridgeConfigComponent } from "./configs/bridge/gitter/gitter.bridge.component";
import { GitterApiService } from "./shared/services/integrations/gitter-api.service";
import { GenericFullscreenWidgetWrapperComponent } from "./widget-wrappers/generic-fullscreen/generic-fullscreen.component";
import { GrafanaWidgetConfigComponent } from "./configs/widget/grafana/grafana.widget.component";
import { TradingViewWidgetConfigComponent } from "./configs/widget/tradingview/tradingview.widget.component";
@ -215,9 +210,6 @@ export function HttpLoaderFactory(http: HttpClient) {
AdminWebhooksBridgeManageSelfhostedComponent,
AdminWebhooksBridgeComponent,
WebhooksBridgeConfigComponent,
AdminGitterBridgeComponent,
AdminGitterBridgeManageSelfhostedComponent,
GitterBridgeConfigComponent,
GenericFullscreenWidgetWrapperComponent,
GrafanaWidgetConfigComponent,
TradingViewWidgetConfigComponent,
@ -262,8 +254,6 @@ export function HttpLoaderFactory(http: HttpClient) {
TelegramApiService,
AdminWebhooksApiService,
WebhooksApiService,
AdminGitterApiService,
GitterApiService,
AdminCustomSimpleBotsApiService,
SlackApiService,
AdminSlackApiService,
@ -290,7 +280,6 @@ export function HttpLoaderFactory(http: HttpClient) {
TelegramAskUnbridgeComponent,
TelegramCannotUnbridgeComponent,
AdminWebhooksBridgeManageSelfhostedComponent,
AdminGitterBridgeManageSelfhostedComponent,
AdminAddCustomBotComponent,
AdminSlackBridgeManageSelfhostedComponent,
AdminLogoutConfirmationDialogComponent,

View File

@ -33,8 +33,6 @@ import { AdminTelegramBridgeComponent } from "./admin/bridges/telegram/telegram.
import { TelegramBridgeConfigComponent } from "./configs/bridge/telegram/telegram.bridge.component";
import { AdminWebhooksBridgeComponent } from "./admin/bridges/webhooks/webhooks.component";
import { WebhooksBridgeConfigComponent } from "./configs/bridge/webhooks/webhooks.bridge.component";
import { AdminGitterBridgeComponent } from "./admin/bridges/gitter/gitter.component";
import { GitterBridgeConfigComponent } from "./configs/bridge/gitter/gitter.bridge.component";
import { GenericFullscreenWidgetWrapperComponent } from "./widget-wrappers/generic-fullscreen/generic-fullscreen.component";
import { GrafanaWidgetConfigComponent } from "./configs/widget/grafana/grafana.widget.component";
import { TradingViewWidgetConfigComponent } from "./configs/widget/tradingview/tradingview.widget.component";
@ -131,11 +129,6 @@ const routes: Routes = [
component: AdminWebhooksBridgeComponent,
data: {breadcrumb: "Webhook Bridge", name: "Webhook Bridge"},
},
{
path: "gitter",
component: AdminGitterBridgeComponent,
data: {breadcrumb: "Gitter Bridge", name: "Gitter Bridge"},
},
{
path: "slack",
component: AdminSlackBridgeComponent,
@ -273,11 +266,6 @@ const routes: Routes = [
component: WebhooksBridgeConfigComponent,
data: {breadcrumb: "Webhook Bridge Configuration", name: "Webhook Bridge Configuration"},
},
{
path: "gitter",
component: GitterBridgeConfigComponent,
data: {breadcrumb: "Gitter Bridge Configuration", name: "Gitter Bridge Configuration"},
},
{
path: "slack",
component: SlackBridgeConfigComponent,

View File

@ -1,27 +0,0 @@
<my-bridge-config [bridgeComponent]="this">
<ng-template #bridgeParamsTemplate>
<my-ibox [isCollapsible]="false">
<h5 class="my-ibox-title">
{{'Bridge to Gitter' | translate}}
</h5>
<div class="my-ibox-content">
<div *ngIf="isBridged">
{{'This room is bridged to on Gitter' | translate}} "{{ bridge.config.link.gitterRoomName }}" {{'on Gitter' | translate}}.
<button type="button" class="btn btn-sm btn-danger" [disabled]="isBusy" (click)="unbridgeRoom()">
{{'Unbridge' | translate}}
</button>
</div>
<div *ngIf="!isBridged">
<label class="label-block">
{{'Gitter Room' | translate}}
<input title="room name" type="text" class="form-control form-control-sm col-md-3"
[(ngModel)]="gitterRoomName" [disabled]="isBusy" placeholder="my-org/room"/>
</label>
<button type="button" class="btn btn-sm btn-primary" [disabled]="isBusy" (click)="bridgeRoom()">
Bridge
</button>
</div>
</div>
</my-ibox>
</ng-template>
</my-bridge-config>

View File

@ -1,4 +0,0 @@
.actions-col {
width: 120px;
text-align: center;
}

View File

@ -1,68 +0,0 @@
import { Component } from "@angular/core";
import { BridgeComponent } from "../bridge.component";
import { FE_GitterLink } from "../../../shared/models/gitter";
import { GitterApiService } from "../../../shared/services/integrations/gitter-api.service";
import { ScalarClientApiService } from "../../../shared/services/scalar/scalar-client-api.service";
import { TranslateService } from "@ngx-translate/core";
interface GitterConfig {
botUserId: string;
link: FE_GitterLink;
}
@Component({
templateUrl: "gitter.bridge.component.html",
styleUrls: ["gitter.bridge.component.scss"],
})
export class GitterBridgeConfigComponent extends BridgeComponent<GitterConfig> {
public gitterRoomName: string;
public isBusy: boolean;
constructor(private gitter: GitterApiService, private scalar: ScalarClientApiService, public translate: TranslateService) {
super("gitter", translate);
this.translate = translate;
}
public get isBridged(): boolean {
return this.bridge.config.link && !!this.bridge.config.link.gitterRoomName;
}
public async bridgeRoom(): Promise<any> {
this.isBusy = true;
try {
await this.scalar.inviteUser(this.roomId, this.bridge.config.botUserId);
} catch (e) {
if (!e.response || !e.response.error || !e.response.error._error ||
e.response.error._error.message.indexOf("already in the room") === -1) {
this.isBusy = false;
this.translate.get('Error inviting bridge').subscribe((res: string) => {this.toaster.pop("error", res); });
return;
}
}
this.gitter.bridgeRoom(this.roomId, this.gitterRoomName).then(link => {
this.bridge.config.link = link;
this.isBusy = false;
this.translate.get('Bridge requested').subscribe((res: string) => {this.toaster.pop("success", res); });
}).catch(error => {
this.isBusy = false;
console.error(error);
this.translate.get('Error requesting bridge').subscribe((res: string) => {this.toaster.pop("error", res); });
});
}
public unbridgeRoom(): void {
this.isBusy = true;
this.gitter.unbridgeRoom(this.roomId).then(() => {
this.bridge.config.link = null;
this.isBusy = false;
this.translate.get('Bridge removed').subscribe((res: string) => {this.toaster.pop("success", res); });
}).catch(error => {
this.isBusy = false;
console.error(error);
this.translate.get('Error removing bridge').subscribe((res: string) => {this.toaster.pop("error", res); });
});
}
}

View File

@ -1,11 +0,0 @@
export interface FE_GitterBridge {
id: number;
upstreamId?: number;
provisionUrl?: string;
isEnabled: boolean;
}
export interface FE_GitterLink {
roomId: string;
gitterRoomName: string;
}

View File

@ -30,7 +30,6 @@ export class IntegrationsRegistry {
"irc": {},
"telegram": {},
"webhooks": {},
"gitter": {},
"slack": {},
},
"widget": {

View File

@ -1,36 +0,0 @@
import { Injectable } from "@angular/core";
import { AuthedApi } from "../authed-api";
import { FE_Upstream } from "../../models/admin-responses";
import { FE_GitterBridge } from "../../models/gitter";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AdminGitterApiService extends AuthedApi {
constructor(http: HttpClient) {
super(http);
}
public getBridges(): Promise<FE_GitterBridge[]> {
return this.authedGet<FE_GitterBridge[]>("/api/v1/dimension/admin/gitter/all").toPromise();
}
public getBridge(bridgeId: number): Promise<FE_GitterBridge> {
return this.authedGet<FE_GitterBridge>("/api/v1/dimension/admin/gitter/" + bridgeId).toPromise();
}
public newFromUpstream(upstream: FE_Upstream): Promise<FE_GitterBridge> {
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/new/upstream", {upstreamId: upstream.id}).toPromise();
}
public newSelfhosted(provisionUrl: string): Promise<FE_GitterBridge> {
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/new/selfhosted", {
provisionUrl: provisionUrl,
}).toPromise();
}
public updateSelfhosted(bridgeId: number, provisionUrl: string): Promise<FE_GitterBridge> {
return this.authedPost<FE_GitterBridge>("/api/v1/dimension/admin/gitter/" + bridgeId, {
provisionUrl: provisionUrl,
}).toPromise();
}
}

View File

@ -1,23 +0,0 @@
import { Injectable } from "@angular/core";
import { AuthedApi } from "../authed-api";
import { FE_GitterLink } from "../../models/gitter";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class GitterApiService extends AuthedApi {
constructor(http: HttpClient) {
super(http);
}
public bridgeRoom(roomId: string, gitterRoomName: string): Promise<FE_GitterLink> {
return this.authedPost<FE_GitterLink>("/api/v1/dimension/gitter/room/" + roomId + "/link", {gitterRoomName}).toPromise();
}
public unbridgeRoom(roomId: string): Promise<any> {
return this.authedDelete("/api/v1/dimension/gitter/room/" + roomId + "/link").toPromise();
}
public getLink(roomId: string): Promise<FE_GitterLink> {
return this.authedGet<FE_GitterLink>("/api/v1/dimension/gitter/room/" + roomId + "/link").toPromise();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB