mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 05:05:53 +00:00
Rename MSC things to be Matrix things
This commit is contained in:
parent
8f537ee078
commit
c5108da67b
@ -7,7 +7,7 @@ import { Server } from "typescript-rest";
|
|||||||
import * as _ from "lodash";
|
import * as _ from "lodash";
|
||||||
import config from "../config";
|
import config from "../config";
|
||||||
import { ApiError } from "./ApiError";
|
import { ApiError } from "./ApiError";
|
||||||
import MSCSecurity from "./security/MSCSecurity";
|
import MatrixSecurity from "./security/MatrixSecurity";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web server for Dimension. Handles the API routes for the admin, scalar, dimension, and matrix APIs.
|
* Web server for Dimension. Handles the API routes for the admin, scalar, dimension, and matrix APIs.
|
||||||
@ -26,10 +26,10 @@ export default class Webserver {
|
|||||||
private loadRoutes() {
|
private loadRoutes() {
|
||||||
// TODO: Rename services to controllers, and controllers to services. They're backwards.
|
// TODO: Rename services to controllers, and controllers to services. They're backwards.
|
||||||
|
|
||||||
const apis = ["scalar", "dimension", "admin", "matrix", "msc"].map(a => path.join(__dirname, a, "*.js"));
|
const apis = ["scalar", "dimension", "admin", "matrix"].map(a => path.join(__dirname, a, "*.js"));
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
Server.useIoC();
|
Server.useIoC();
|
||||||
Server.registerAuthenticator(new MSCSecurity());
|
Server.registerAuthenticator(new MatrixSecurity());
|
||||||
apis.forEach(a => Server.loadServices(router, [a]));
|
apis.forEach(a => Server.loadServices(router, [a]));
|
||||||
const routes = _.uniq(router.stack.map(r => r.route.path));
|
const routes = _.uniq(router.stack.map(r => r.route.path));
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
|
@ -4,7 +4,7 @@ import { AppserviceStore } from "../../db/AppserviceStore";
|
|||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { MatrixAppserviceClient } from "../../matrix/MatrixAppserviceClient";
|
import { MatrixAppserviceClient } from "../../matrix/MatrixAppserviceClient";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface AppserviceResponse {
|
interface AppserviceResponse {
|
||||||
id: string;
|
id: string;
|
||||||
@ -28,14 +28,14 @@ export class AdminAppserviceService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getAppservices(): Promise<AppserviceResponse[]> {
|
public async getAppservices(): Promise<AppserviceResponse[]> {
|
||||||
return (await AppService.findAll()).map(a => this.mapAppservice(a));
|
return (await AppService.findAll()).map(a => this.mapAppservice(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":appserviceId")
|
@Path(":appserviceId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getAppservice(@PathParam("appserviceId") asId: string): Promise<AppserviceResponse> {
|
public async getAppservice(@PathParam("appserviceId") asId: string): Promise<AppserviceResponse> {
|
||||||
try {
|
try {
|
||||||
const appservice = await AppserviceStore.getAppservice(asId);
|
const appservice = await AppserviceStore.getAppservice(asId);
|
||||||
@ -48,7 +48,7 @@ export class AdminAppserviceService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new")
|
@Path("new")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async createAppservice(request: AppserviceCreateRequest): Promise<AppserviceResponse> {
|
public async createAppservice(request: AppserviceCreateRequest): Promise<AppserviceResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ export class AdminAppserviceService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":appserviceId/test")
|
@Path(":appserviceId/test")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async test(@PathParam("appserviceId") asId: string): Promise<any> {
|
public async test(@PathParam("appserviceId") asId: string): Promise<any> {
|
||||||
const appservice = await AppserviceStore.getAppservice(asId);
|
const appservice = await AppserviceStore.getAppservice(asId);
|
||||||
const client = new MatrixAppserviceClient(appservice);
|
const client = new MatrixAppserviceClient(appservice);
|
||||||
|
@ -3,7 +3,7 @@ import { ApiError } from "../ApiError";
|
|||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { BotStore } from "../../db/BotStore";
|
import { BotStore } from "../../db/BotStore";
|
||||||
import { Cache, CACHE_INTEGRATIONS } from "../../MemoryCache";
|
import { Cache, CACHE_INTEGRATIONS } from "../../MemoryCache";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface BotResponse extends BotRequest {
|
interface BotResponse extends BotRequest {
|
||||||
id: number;
|
id: number;
|
||||||
@ -36,14 +36,14 @@ export class AdminCustomSimpleBotService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBots(): Promise<BotResponse[]> {
|
public async getBots(): Promise<BotResponse[]> {
|
||||||
return BotStore.getCustomBots();
|
return BotStore.getCustomBots();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":botId")
|
@Path(":botId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBot(@PathParam("botId") botId: number): Promise<BotResponse> {
|
public async getBot(@PathParam("botId") botId: number): Promise<BotResponse> {
|
||||||
const bot = await BotStore.getCustomBot(botId);
|
const bot = await BotStore.getCustomBot(botId);
|
||||||
if (!bot) throw new ApiError(404, "Bot not found");
|
if (!bot) throw new ApiError(404, "Bot not found");
|
||||||
@ -52,7 +52,7 @@ export class AdminCustomSimpleBotService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new")
|
@Path("new")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async createBot(request: BotRequest): Promise<BotResponse> {
|
public async createBot(request: BotRequest): Promise<BotResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bot = await BotStore.createCustom(request);
|
const bot = await BotStore.createCustom(request);
|
||||||
@ -63,7 +63,7 @@ export class AdminCustomSimpleBotService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":botId")
|
@Path(":botId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updateBot(@PathParam("botId") botId: number, request: BotRequest): Promise<BotResponse> {
|
public async updateBot(@PathParam("botId") botId: number, request: BotRequest): Promise<BotResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bot = await BotStore.updateCustom(botId, request);
|
const bot = await BotStore.updateCustom(botId, request);
|
||||||
@ -74,7 +74,7 @@ export class AdminCustomSimpleBotService {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path(":botId")
|
@Path(":botId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async deleteBot(@PathParam("botId") botId: number): Promise<any> {
|
public async deleteBot(@PathParam("botId") botId: number): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
await BotStore.deleteCustom(botId);
|
await BotStore.deleteCustom(botId);
|
||||||
@ -85,7 +85,7 @@ export class AdminCustomSimpleBotService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("profile/:userId")
|
@Path("profile/:userId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getProfile(@PathParam("userId") userId: string): Promise<BotProfile> {
|
public async getProfile(@PathParam("userId") userId: string): Promise<BotProfile> {
|
||||||
const profile = await BotStore.getProfile(userId);
|
const profile = await BotStore.getProfile(userId);
|
||||||
return {name: profile.displayName, avatarUrl: profile.avatarMxc};
|
return {name: profile.displayName, avatarUrl: profile.avatarMxc};
|
||||||
|
@ -4,7 +4,7 @@ import { LogService } from "matrix-js-snippets";
|
|||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import GitterBridgeRecord from "../../db/models/GitterBridgeRecord";
|
import GitterBridgeRecord from "../../db/models/GitterBridgeRecord";
|
||||||
import Upstream from "../../db/models/Upstream";
|
import Upstream from "../../db/models/Upstream";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -32,7 +32,7 @@ export class AdminGitterService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridges(): Promise<BridgeResponse[]> {
|
public async getBridges(): Promise<BridgeResponse[]> {
|
||||||
const bridges = await GitterBridgeRecord.findAll();
|
const bridges = await GitterBridgeRecord.findAll();
|
||||||
return Promise.all(bridges.map(async b => {
|
return Promise.all(bridges.map(async b => {
|
||||||
@ -47,7 +47,7 @@ export class AdminGitterService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
||||||
const telegramBridge = await GitterBridgeRecord.findByPk(bridgeId);
|
const telegramBridge = await GitterBridgeRecord.findByPk(bridgeId);
|
||||||
if (!telegramBridge) throw new ApiError(404, "Gitter Bridge not found");
|
if (!telegramBridge) throw new ApiError(404, "Gitter Bridge not found");
|
||||||
@ -62,7 +62,7 @@ export class AdminGitterService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bridge = await GitterBridgeRecord.findByPk(bridgeId);
|
const bridge = await GitterBridgeRecord.findByPk(bridgeId);
|
||||||
@ -80,7 +80,7 @@ export class AdminGitterService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const upstream = await Upstream.findByPk(request.upstreamId);
|
const upstream = await Upstream.findByPk(request.upstreamId);
|
||||||
@ -99,7 +99,7 @@ export class AdminGitterService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/selfhosted")
|
@Path("new/selfhosted")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bridge = await GitterBridgeRecord.create({
|
const bridge = await GitterBridgeRecord.create({
|
||||||
|
@ -6,7 +6,7 @@ import { Cache, CACHE_INTEGRATIONS } from "../../MemoryCache";
|
|||||||
import { Integration } from "../../integrations/Integration";
|
import { Integration } from "../../integrations/Integration";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { BridgeStore } from "../../db/BridgeStore";
|
import { BridgeStore } from "../../db/BridgeStore";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface SetEnabledRequest {
|
interface SetEnabledRequest {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@ -28,7 +28,7 @@ export class AdminIntegrationsService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":category/:type/options")
|
@Path(":category/:type/options")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setOptions(@PathParam("category") category: string, @PathParam("type") type: string, body: SetOptionsRequest): Promise<any> {
|
public async setOptions(@PathParam("category") category: string, @PathParam("type") type: string, body: SetOptionsRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ export class AdminIntegrationsService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":category/:type/enabled")
|
@Path(":category/:type/enabled")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setEnabled(@PathParam("category") category: string, @PathParam("type") type: string, body: SetEnabledRequest): Promise<any> {
|
public async setEnabled(@PathParam("category") category: string, @PathParam("type") type: string, body: SetEnabledRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ export class AdminIntegrationsService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":category/all")
|
@Path(":category/all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getAllIntegrations(@PathParam("category") category: string): Promise<Integration[]> {
|
public async getAllIntegrations(@PathParam("category") category: string): Promise<Integration[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import IrcBridgeRecord from "../../db/models/IrcBridgeRecord";
|
|||||||
import { AvailableNetworks, IrcBridge } from "../../bridges/IrcBridge";
|
import { AvailableNetworks, IrcBridge } from "../../bridges/IrcBridge";
|
||||||
import Upstream from "../../db/models/Upstream";
|
import Upstream from "../../db/models/Upstream";
|
||||||
import IrcBridgeNetwork from "../../db/models/IrcBridgeNetwork";
|
import IrcBridgeNetwork from "../../db/models/IrcBridgeNetwork";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -40,7 +40,7 @@ export class AdminIrcService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridges(): Promise<BridgeResponse[]> {
|
public async getBridges(): Promise<BridgeResponse[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ export class AdminIrcService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ export class AdminIrcService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":bridgeId/network/:networkId/enabled")
|
@Path(":bridgeId/network/:networkId/enabled")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setNetworkEnabled(@PathParam("bridgeId") bridgeId: number, @PathParam("networkId") networkId: string, request: SetEnabledRequest): Promise<any> {
|
public async setNetworkEnabled(@PathParam("bridgeId") bridgeId: number, @PathParam("networkId") networkId: string, request: SetEnabledRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ export class AdminIrcService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ export class AdminIrcService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/selfhosted")
|
@Path("new/selfhosted")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { NebStore } from "../../db/NebStore";
|
|||||||
import { NebConfig } from "../../models/neb";
|
import { NebConfig } from "../../models/neb";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -31,7 +31,7 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getNebConfigs(): Promise<NebConfig[]> {
|
public async getNebConfigs(): Promise<NebConfig[]> {
|
||||||
const cachedConfigs = Cache.for(CACHE_NEB).get("configurations");
|
const cachedConfigs = Cache.for(CACHE_NEB).get("configurations");
|
||||||
if (cachedConfigs) return cachedConfigs;
|
if (cachedConfigs) return cachedConfigs;
|
||||||
@ -43,7 +43,7 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":id/config")
|
@Path(":id/config")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getNebConfig(@PathParam("id") nebId: number): Promise<NebConfig> {
|
public async getNebConfig(@PathParam("id") nebId: number): Promise<NebConfig> {
|
||||||
const configs = await this.getNebConfigs();
|
const configs = await this.getNebConfigs();
|
||||||
const firstConfig = configs.filter(c => c.id === nebId)[0];
|
const firstConfig = configs.filter(c => c.id === nebId)[0];
|
||||||
@ -53,7 +53,7 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":id/integration/:type/enabled")
|
@Path(":id/integration/:type/enabled")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setIntegrationEnabled(@PathParam("id") nebId: number, @PathParam("type") integrationType: string, request: SetEnabledRequest): Promise<any> {
|
public async setIntegrationEnabled(@PathParam("id") nebId: number, @PathParam("type") integrationType: string, request: SetEnabledRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":id/integration/:type/config")
|
@Path(":id/integration/:type/config")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setIntegrationConfig(@PathParam("id") nebId: number, @PathParam("type") integrationType: string, newConfig: any): Promise<any> {
|
public async setIntegrationConfig(@PathParam("id") nebId: number, @PathParam("type") integrationType: string, newConfig: any): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -81,14 +81,14 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":id/integration/:type/config")
|
@Path(":id/integration/:type/config")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getIntegrationConfig(@PathParam("id") nebId: number, @PathParam("type") integrationType: string): Promise<any> {
|
public async getIntegrationConfig(@PathParam("id") nebId: number, @PathParam("type") integrationType: string): Promise<any> {
|
||||||
return NebStore.getIntegrationConfig(nebId, integrationType);
|
return NebStore.getIntegrationConfig(nebId, integrationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(request: CreateWithUpstream): Promise<NebConfig> {
|
public async newConfigForUpstream(request: CreateWithUpstream): Promise<NebConfig> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ export class AdminNebService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/appservice")
|
@Path("new/appservice")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForAppservice(request: CreateWithAppservice): Promise<NebConfig> {
|
public async newConfigForAppservice(request: CreateWithAppservice): Promise<NebConfig> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { CURRENT_VERSION } from "../../version";
|
|||||||
import { getFederationConnInfo } from "../../matrix/helpers";
|
import { getFederationConnInfo } from "../../matrix/helpers";
|
||||||
import UserScalarToken from "../../db/models/UserScalarToken";
|
import UserScalarToken from "../../db/models/UserScalarToken";
|
||||||
import { Cache, CACHE_SCALAR_ACCOUNTS } from "../../MemoryCache";
|
import { Cache, CACHE_SCALAR_ACCOUNTS } from "../../MemoryCache";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface DimensionVersionResponse {
|
interface DimensionVersionResponse {
|
||||||
version: string;
|
version: string;
|
||||||
@ -34,21 +34,21 @@ export class AdminService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("check")
|
@Path("check")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async checkIfAdmin(): Promise<{}> {
|
public async checkIfAdmin(): Promise<{}> {
|
||||||
return {}; // A 200 OK essentially means "you're an admin".
|
return {}; // A 200 OK essentially means "you're an admin".
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("version")
|
@Path("version")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getVersion(): Promise<DimensionVersionResponse> {
|
public async getVersion(): Promise<DimensionVersionResponse> {
|
||||||
return {version: CURRENT_VERSION};
|
return {version: CURRENT_VERSION};
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("config")
|
@Path("config")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getConfig(): Promise<DimensionConfigResponse> {
|
public async getConfig(): Promise<DimensionConfigResponse> {
|
||||||
const client = new MatrixLiteClient(config.homeserver.accessToken);
|
const client = new MatrixLiteClient(config.homeserver.accessToken);
|
||||||
const fedInfo = await getFederationConnInfo(config.homeserver.name);
|
const fedInfo = await getFederationConnInfo(config.homeserver.name);
|
||||||
@ -70,7 +70,7 @@ export class AdminService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("test/federation")
|
@Path("test/federation")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async testFederationRouting(@QueryParam("server_name") serverName: string): Promise<any> {
|
public async testFederationRouting(@QueryParam("server_name") serverName: string): Promise<any> {
|
||||||
return {
|
return {
|
||||||
inputServerName: serverName,
|
inputServerName: serverName,
|
||||||
@ -80,7 +80,7 @@ export class AdminService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("sessions/logout/all")
|
@Path("sessions/logout/all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async logoutAll(): Promise<any> {
|
public async logoutAll(): Promise<any> {
|
||||||
// Clear the cache first to hopefully invalidate a bunch of them
|
// Clear the cache first to hopefully invalidate a bunch of them
|
||||||
Cache.for(CACHE_SCALAR_ACCOUNTS).clear();
|
Cache.for(CACHE_SCALAR_ACCOUNTS).clear();
|
||||||
|
@ -4,7 +4,7 @@ import { LogService } from "matrix-js-snippets";
|
|||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import Upstream from "../../db/models/Upstream";
|
import Upstream from "../../db/models/Upstream";
|
||||||
import SlackBridgeRecord from "../../db/models/SlackBridgeRecord";
|
import SlackBridgeRecord from "../../db/models/SlackBridgeRecord";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -32,7 +32,7 @@ export class AdminSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridges(): Promise<BridgeResponse[]> {
|
public async getBridges(): Promise<BridgeResponse[]> {
|
||||||
const bridges = await SlackBridgeRecord.findAll();
|
const bridges = await SlackBridgeRecord.findAll();
|
||||||
return Promise.all(bridges.map(async b => {
|
return Promise.all(bridges.map(async b => {
|
||||||
@ -47,7 +47,7 @@ export class AdminSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
||||||
const telegramBridge = await SlackBridgeRecord.findByPk(bridgeId);
|
const telegramBridge = await SlackBridgeRecord.findByPk(bridgeId);
|
||||||
if (!telegramBridge) throw new ApiError(404, "Slack Bridge not found");
|
if (!telegramBridge) throw new ApiError(404, "Slack Bridge not found");
|
||||||
@ -62,7 +62,7 @@ export class AdminSlackService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bridge = await SlackBridgeRecord.findByPk(bridgeId);
|
const bridge = await SlackBridgeRecord.findByPk(bridgeId);
|
||||||
@ -80,7 +80,7 @@ export class AdminSlackService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
public async newConfigForUpstream(request: CreateWithUpstream): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const upstream = await Upstream.findByPk(request.upstreamId);
|
const upstream = await Upstream.findByPk(request.upstreamId);
|
||||||
@ -99,7 +99,7 @@ export class AdminSlackService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/selfhosted")
|
@Path("new/selfhosted")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const bridge = await SlackBridgeRecord.create({
|
const bridge = await SlackBridgeRecord.create({
|
||||||
|
@ -9,7 +9,7 @@ import config from "../../config";
|
|||||||
import Sticker from "../../db/models/Sticker";
|
import Sticker from "../../db/models/Sticker";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import * as sharp from "sharp";
|
import * as sharp from "sharp";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface SetEnabledRequest {
|
interface SetEnabledRequest {
|
||||||
isEnabled: boolean;
|
isEnabled: boolean;
|
||||||
@ -30,14 +30,14 @@ export class AdminStickerService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("packs")
|
@Path("packs")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getStickerPacks(): Promise<MemoryStickerPack[]> {
|
public async getStickerPacks(): Promise<MemoryStickerPack[]> {
|
||||||
return await DimensionStickerService.getStickerPacks(false);
|
return await DimensionStickerService.getStickerPacks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("packs/:id/enabled")
|
@Path("packs/:id/enabled")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async setPackEnabled(@PathParam("id") packId: number, request: SetEnabledRequest): Promise<any> {
|
public async setPackEnabled(@PathParam("id") packId: number, request: SetEnabledRequest): Promise<any> {
|
||||||
const pack = await StickerPack.findByPk(packId);
|
const pack = await StickerPack.findByPk(packId);
|
||||||
if (!pack) throw new ApiError(404, "Sticker pack not found");
|
if (!pack) throw new ApiError(404, "Sticker pack not found");
|
||||||
@ -51,7 +51,7 @@ export class AdminStickerService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("packs/import/telegram")
|
@Path("packs/import/telegram")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async importFromTelegram(request: ImportTelegramRequest): Promise<MemoryStickerPack> {
|
public async importFromTelegram(request: ImportTelegramRequest): Promise<MemoryStickerPack> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { Cache, CACHE_INTEGRATIONS, CACHE_TELEGRAM_BRIDGE } from "../../MemoryCa
|
|||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import TelegramBridgeRecord from "../../db/models/TelegramBridgeRecord";
|
import TelegramBridgeRecord from "../../db/models/TelegramBridgeRecord";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -37,7 +37,7 @@ export class AdminTelegramService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridges(): Promise<BridgeResponse[]> {
|
public async getBridges(): Promise<BridgeResponse[]> {
|
||||||
const bridges = await TelegramBridgeRecord.findAll();
|
const bridges = await TelegramBridgeRecord.findAll();
|
||||||
return Promise.all(bridges.map(async b => {
|
return Promise.all(bridges.map(async b => {
|
||||||
@ -55,7 +55,7 @@ export class AdminTelegramService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
||||||
const telegramBridge = await TelegramBridgeRecord.findByPk(bridgeId);
|
const telegramBridge = await TelegramBridgeRecord.findByPk(bridgeId);
|
||||||
if (!telegramBridge) throw new ApiError(404, "Telegram Bridge not found");
|
if (!telegramBridge) throw new ApiError(404, "Telegram Bridge not found");
|
||||||
@ -73,7 +73,7 @@ export class AdminTelegramService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -95,14 +95,14 @@ export class AdminTelegramService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(@QueryParam("scalar_token") _scalarToken: string, _request: CreateWithUpstream): Promise<BridgeResponse> {
|
public async newConfigForUpstream(@QueryParam("scalar_token") _scalarToken: string, _request: CreateWithUpstream): Promise<BridgeResponse> {
|
||||||
throw new ApiError(400, "Cannot create a telegram bridge from an upstream");
|
throw new ApiError(400, "Cannot create a telegram bridge from an upstream");
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/selfhosted")
|
@Path("new/selfhosted")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { GET, Path, PathParam, POST, PUT, Security } from "typescript-rest";
|
import { GET, Path, PathParam, POST, PUT, Security } from "typescript-rest";
|
||||||
import TermsController, { ITerms } from "../controllers/TermsController";
|
import TermsController, { ITerms } from "../controllers/TermsController";
|
||||||
import { AutoWired, Inject } from "typescript-ioc/es6";
|
import { AutoWired, Inject } from "typescript-ioc/es6";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreatePolicyObject {
|
interface CreatePolicyObject {
|
||||||
name: string;
|
name: string;
|
||||||
@ -21,35 +21,35 @@ export class AdminTermsService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getPolicies(): Promise<ITerms[]> {
|
public async getPolicies(): Promise<ITerms[]> {
|
||||||
return this.termsController.getPoliciesForAdmin();
|
return this.termsController.getPoliciesForAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":shortcode/:version")
|
@Path(":shortcode/:version")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise<ITerms> {
|
public async getPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise<ITerms> {
|
||||||
return this.termsController.getPolicyForAdmin(shortcode, version);
|
return this.termsController.getPolicyForAdmin(shortcode, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":shortcode/draft")
|
@Path(":shortcode/draft")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise<ITerms> {
|
public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise<ITerms> {
|
||||||
return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
|
return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":shortcode/publish/:version")
|
@Path(":shortcode/publish/:version")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async publishDraftPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise<ITerms> {
|
public async publishDraftPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise<ITerms> {
|
||||||
return this.termsController.publishPolicy(shortcode, version);
|
return this.termsController.publishPolicy(shortcode, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path(":shortcode/:version")
|
@Path(":shortcode/:version")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updatePolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string, request: CreatePolicyObject): Promise<ITerms> {
|
public async updatePolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string, request: CreatePolicyObject): Promise<ITerms> {
|
||||||
return this.termsController.updatePolicy(request.name, shortcode, version, request.text, request.url);
|
return this.termsController.updatePolicy(request.name, shortcode, version, request.text, request.url);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { Context, GET, Path, POST, Security, ServiceContext } from "typescript-r
|
|||||||
import { Cache, CACHE_SCALAR_ACCOUNTS, CACHE_UPSTREAM } from "../../MemoryCache";
|
import { Cache, CACHE_SCALAR_ACCOUNTS, CACHE_UPSTREAM } from "../../MemoryCache";
|
||||||
import Upstream from "../../db/models/Upstream";
|
import Upstream from "../../db/models/Upstream";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface UpstreamRepsonse {
|
interface UpstreamRepsonse {
|
||||||
id: number;
|
id: number;
|
||||||
@ -31,7 +31,7 @@ export class AdminUpstreamService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getUpstreams(): Promise<UpstreamRepsonse[]> {
|
public async getUpstreams(): Promise<UpstreamRepsonse[]> {
|
||||||
const cachedUpstreams = Cache.for(CACHE_UPSTREAM).get("upstreams");
|
const cachedUpstreams = Cache.for(CACHE_UPSTREAM).get("upstreams");
|
||||||
if (cachedUpstreams) return cachedUpstreams;
|
if (cachedUpstreams) return cachedUpstreams;
|
||||||
@ -44,7 +44,7 @@ export class AdminUpstreamService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new")
|
@Path("new")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async createUpstream(request: NewUpstreamRequest): Promise<UpstreamRepsonse> {
|
public async createUpstream(request: NewUpstreamRequest): Promise<UpstreamRepsonse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { Cache, CACHE_INTEGRATIONS, CACHE_WEBHOOKS_BRIDGE } from "../../MemoryCa
|
|||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import WebhookBridgeRecord from "../../db/models/WebhookBridgeRecord";
|
import WebhookBridgeRecord from "../../db/models/WebhookBridgeRecord";
|
||||||
import { ROLE_MSC_ADMIN, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_ADMIN, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface CreateWithUpstream {
|
interface CreateWithUpstream {
|
||||||
upstreamId: number;
|
upstreamId: number;
|
||||||
@ -33,7 +33,7 @@ export class AdminWebhooksService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("all")
|
@Path("all")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridges(): Promise<BridgeResponse[]> {
|
public async getBridges(): Promise<BridgeResponse[]> {
|
||||||
const bridges = await WebhookBridgeRecord.findAll();
|
const bridges = await WebhookBridgeRecord.findAll();
|
||||||
return Promise.all(bridges.map(async b => {
|
return Promise.all(bridges.map(async b => {
|
||||||
@ -49,7 +49,7 @@ export class AdminWebhooksService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
public async getBridge(@PathParam("bridgeId") bridgeId: number): Promise<BridgeResponse> {
|
||||||
const webhookBridge = await WebhookBridgeRecord.findByPk(bridgeId);
|
const webhookBridge = await WebhookBridgeRecord.findByPk(bridgeId);
|
||||||
if (!webhookBridge) throw new ApiError(404, "Webhook Bridge not found");
|
if (!webhookBridge) throw new ApiError(404, "Webhook Bridge not found");
|
||||||
@ -65,7 +65,7 @@ export class AdminWebhooksService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":bridgeId")
|
@Path(":bridgeId")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async updateBridge(@PathParam("bridgeId") bridgeId: number, request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -85,14 +85,14 @@ export class AdminWebhooksService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/upstream")
|
@Path("new/upstream")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newConfigForUpstream(@QueryParam("scalar_token") _scalarToken: string, _request: CreateWithUpstream): Promise<BridgeResponse> {
|
public async newConfigForUpstream(@QueryParam("scalar_token") _scalarToken: string, _request: CreateWithUpstream): Promise<BridgeResponse> {
|
||||||
throw new ApiError(400, "Cannot create a webhook bridge from an upstream");
|
throw new ApiError(400, "Cannot create a webhook bridge from an upstream");
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("new/selfhosted")
|
@Path("new/selfhosted")
|
||||||
@Security([ROLE_MSC_USER, ROLE_MSC_ADMIN])
|
@Security([ROLE_USER, ROLE_ADMIN])
|
||||||
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
public async newSelfhosted(request: CreateSelfhosted): Promise<BridgeResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import { ScalarClient } from "../../scalar/ScalarClient";
|
|||||||
import * as randomString from "random-string";
|
import * as randomString from "random-string";
|
||||||
import { AutoWired } from "typescript-ioc/es6";
|
import { AutoWired } from "typescript-ioc/es6";
|
||||||
import { Cache, CACHE_SCALAR_ACCOUNTS } from "../../MemoryCache";
|
import { Cache, CACHE_SCALAR_ACCOUNTS } from "../../MemoryCache";
|
||||||
import { IMSCUser } from "../security/MSCSecurity";
|
import { ILoggedInUser } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
export interface IAccountRegisteredResponse {
|
export interface IAccountRegisteredResponse {
|
||||||
token: string;
|
token: string;
|
||||||
@ -108,10 +108,10 @@ export default class AccountController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a user out
|
* Logs a user out
|
||||||
* @param {IMSCUser} user The user to log out
|
* @param {ILoggedInUser} user The user to log out
|
||||||
* @returns {Promise<*>} Resolves when complete.
|
* @returns {Promise<*>} Resolves when complete.
|
||||||
*/
|
*/
|
||||||
public async logout(user: IMSCUser): Promise<any> {
|
public async logout(user: ILoggedInUser): Promise<any> {
|
||||||
const tokens = await UserScalarToken.findAll({where: {scalarToken: user.token}, include: [Upstream]});
|
const tokens = await UserScalarToken.findAll({where: {scalarToken: user.token}, include: [Upstream]});
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token.upstream) {
|
if (token.upstream) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { AutoWired } from "typescript-ioc/es6";
|
import { AutoWired } from "typescript-ioc/es6";
|
||||||
import { IMSCUser } from "../security/MSCSecurity";
|
import { ILoggedInUser } from "../security/MatrixSecurity";
|
||||||
import TermsRecord from "../../db/models/TermsRecord";
|
import TermsRecord from "../../db/models/TermsRecord";
|
||||||
import TermsTextRecord from "../../db/models/TermsTextRecord";
|
import TermsTextRecord from "../../db/models/TermsTextRecord";
|
||||||
import TermsSignedRecord from "../../db/models/TermsSignedRecord";
|
import TermsSignedRecord from "../../db/models/TermsSignedRecord";
|
||||||
@ -86,11 +86,11 @@ export default class TermsController {
|
|||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async doesUserNeedToSignTerms(user: IMSCUser): Promise<boolean> {
|
public async doesUserNeedToSignTerms(user: ILoggedInUser): Promise<boolean> {
|
||||||
return Object.keys((await this.getMissingTermsForUser(user)).policies).length > 0;
|
return Object.keys((await this.getMissingTermsForUser(user)).policies).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getMissingTermsForUser(user: IMSCUser): Promise<ITermsNotSignedResponse> {
|
public async getMissingTermsForUser(user: ILoggedInUser): Promise<ITermsNotSignedResponse> {
|
||||||
const latest = await this.getPublishedTerms();
|
const latest = await this.getPublishedTerms();
|
||||||
const signed = await TermsSignedRecord.findAll({where: {userId: user.userId}});
|
const signed = await TermsSignedRecord.findAll({where: {userId: user.userId}});
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ export default class TermsController {
|
|||||||
return policies;
|
return policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async signTermsMatching(user: IMSCUser, urls: string[]): Promise<any> {
|
public async signTermsMatching(user: ILoggedInUser, urls: string[]): Promise<any> {
|
||||||
const terms = await TermsTextRecord.findAll({where: {url: {[Op.in]: urls}}});
|
const terms = await TermsTextRecord.findAll({where: {url: {[Op.in]: urls}}});
|
||||||
const signed = await TermsSignedRecord.findAll({where: {userId: user.userId}});
|
const signed = await TermsSignedRecord.findAll({where: {userId: user.userId}});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { Context, DELETE, GET, Path, PathParam, POST, Security, ServiceContext }
|
|||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { BridgedRoom, GitterBridge } from "../../bridges/GitterBridge";
|
import { BridgedRoom, GitterBridge } from "../../bridges/GitterBridge";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface BridgeRoomRequest {
|
interface BridgeRoomRequest {
|
||||||
gitterRoomName: string;
|
gitterRoomName: string;
|
||||||
@ -19,7 +19,7 @@ export class DimensionGitterService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("room/:roomId/link")
|
@Path("room/:roomId/link")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getLink(@PathParam("roomId") roomId: string): Promise<BridgedRoom> {
|
public async getLink(@PathParam("roomId") roomId: string): Promise<BridgedRoom> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
try {
|
try {
|
||||||
@ -33,7 +33,7 @@ export class DimensionGitterService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("room/:roomId/link")
|
@Path("room/:roomId/link")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async bridgeRoom(@PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<BridgedRoom> {
|
public async bridgeRoom(@PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<BridgedRoom> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
try {
|
try {
|
||||||
@ -48,7 +48,7 @@ export class DimensionGitterService {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("room/:roomId/link")
|
@Path("room/:roomId/link")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async unbridgeRoom(@PathParam("roomId") roomId: string): Promise<any> {
|
public async unbridgeRoom(@PathParam("roomId") roomId: string): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
try {
|
try {
|
||||||
|
@ -10,7 +10,7 @@ import { ComplexBot } from "../../integrations/ComplexBot";
|
|||||||
import { Bridge } from "../../integrations/Bridge";
|
import { Bridge } from "../../integrations/Bridge";
|
||||||
import { BridgeStore } from "../../db/BridgeStore";
|
import { BridgeStore } from "../../db/BridgeStore";
|
||||||
import { BotStore } from "../../db/BotStore";
|
import { BotStore } from "../../db/BotStore";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
export interface IntegrationsResponse {
|
export interface IntegrationsResponse {
|
||||||
widgets: Widget[],
|
widgets: Widget[],
|
||||||
@ -88,7 +88,7 @@ export class DimensionIntegrationsService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("room/:roomId")
|
@Path("room/:roomId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getIntegrationsInRoom(@PathParam("roomId") roomId: string): Promise<IntegrationsResponse> {
|
public async getIntegrationsInRoom(@PathParam("roomId") roomId: string): Promise<IntegrationsResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
return {
|
return {
|
||||||
@ -101,7 +101,7 @@ export class DimensionIntegrationsService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("room/:roomId/integrations/:category/:type")
|
@Path("room/:roomId/integrations/:category/:type")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getIntegrationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string): Promise<any> {
|
public async getIntegrationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string): Promise<any> {
|
||||||
const roomConfig = await this.getIntegrationsInRoom(roomId); // does auth for us
|
const roomConfig = await this.getIntegrationsInRoom(roomId); // does auth for us
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ export class DimensionIntegrationsService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("room/:roomId/integrations/:category/:type/config")
|
@Path("room/:roomId/integrations/:category/:type/config")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async setIntegrationConfigurationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string, newConfig: any): Promise<any> {
|
public async setIntegrationConfigurationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string, newConfig: any): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ export class DimensionIntegrationsService {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("room/:roomId/integrations/:category/:type")
|
@Path("room/:roomId/integrations/:category/:type")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async removeIntegrationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string): Promise<any> {
|
public async removeIntegrationInRoom(@PathParam("roomId") roomId: string, @PathParam("category") category: string, @PathParam("type") integrationType: string): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { LogService } from "matrix-js-snippets";
|
|||||||
import { IrcBridge } from "../../bridges/IrcBridge";
|
import { IrcBridge } from "../../bridges/IrcBridge";
|
||||||
import IrcBridgeRecord from "../../db/models/IrcBridgeRecord";
|
import IrcBridgeRecord from "../../db/models/IrcBridgeRecord";
|
||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface RequestLinkRequest {
|
interface RequestLinkRequest {
|
||||||
op: string;
|
op: string;
|
||||||
@ -20,7 +20,7 @@ export class DimensionIrcService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path(":networkId/channel/:channel/ops")
|
@Path(":networkId/channel/:channel/ops")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getOps(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string): Promise<string[]> {
|
public async getOps(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string): Promise<string[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const parsed = IrcBridge.parseNetworkId(networkId);
|
const parsed = IrcBridge.parseNetworkId(networkId);
|
||||||
@ -36,7 +36,7 @@ export class DimensionIrcService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":networkId/channel/:channel/link/:roomId")
|
@Path(":networkId/channel/:channel/link/:roomId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async requestLink(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string, request: RequestLinkRequest): Promise<any> {
|
public async requestLink(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string, request: RequestLinkRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const parsed = IrcBridge.parseNetworkId(networkId);
|
const parsed = IrcBridge.parseNetworkId(networkId);
|
||||||
@ -52,7 +52,7 @@ export class DimensionIrcService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(":networkId/channel/:channel/unlink/:roomId")
|
@Path(":networkId/channel/:channel/unlink/:roomId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async unlink(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string): Promise<any> {
|
public async unlink(@PathParam("networkId") networkId: string, @PathParam("channel") channelNoHash: string, @PathParam("roomId") roomId: string): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const parsed = IrcBridge.parseNetworkId(networkId);
|
const parsed = IrcBridge.parseNetworkId(networkId);
|
||||||
|
@ -3,7 +3,7 @@ import { ApiError } from "../ApiError";
|
|||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import { BridgedChannel, SlackBridge } from "../../bridges/SlackBridge";
|
import { BridgedChannel, SlackBridge } from "../../bridges/SlackBridge";
|
||||||
import { SlackChannel, SlackTeam } from "../../bridges/models/slack";
|
import { SlackChannel, SlackTeam } from "../../bridges/models/slack";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface BridgeRoomRequest {
|
interface BridgeRoomRequest {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
@ -21,7 +21,7 @@ export class DimensionSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("room/:roomId/link")
|
@Path("room/:roomId/link")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getLink(@PathParam("roomId") roomId: string): Promise<BridgedChannel> {
|
public async getLink(@PathParam("roomId") roomId: string): Promise<BridgedChannel> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export class DimensionSlackService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("room/:roomId/link")
|
@Path("room/:roomId/link")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async bridgeRoom(@PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<BridgedChannel> {
|
public async bridgeRoom(@PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<BridgedChannel> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ export class DimensionSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("teams")
|
@Path("teams")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getTeams(): Promise<SlackTeam[]> {
|
public async getTeams(): Promise<SlackTeam[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ export class DimensionSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("teams/:teamId/channels")
|
@Path("teams/:teamId/channels")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getChannels(@PathParam("teamId") teamId: string): Promise<SlackChannel[]> {
|
public async getChannels(@PathParam("teamId") teamId: string): Promise<SlackChannel[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ export class DimensionSlackService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("auth")
|
@Path("auth")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getAuthUrl(): Promise<{ authUrl: string }> {
|
public async getAuthUrl(): Promise<{ authUrl: string }> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { ApiError } from "../ApiError";
|
|||||||
import { StickerpackMetadataDownloader } from "../../utils/StickerpackMetadataDownloader";
|
import { StickerpackMetadataDownloader } from "../../utils/StickerpackMetadataDownloader";
|
||||||
import { MatrixStickerBot } from "../../matrix/MatrixStickerBot";
|
import { MatrixStickerBot } from "../../matrix/MatrixStickerBot";
|
||||||
import config from "../../config";
|
import config from "../../config";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
export interface MemoryStickerPack {
|
export interface MemoryStickerPack {
|
||||||
id: number;
|
id: number;
|
||||||
@ -88,7 +88,7 @@ export class DimensionStickerService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("config")
|
@Path("config")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getConfig(): Promise<StickerConfig> {
|
public async getConfig(): Promise<StickerConfig> {
|
||||||
return {
|
return {
|
||||||
enabled: config.stickers.enabled,
|
enabled: config.stickers.enabled,
|
||||||
@ -99,7 +99,7 @@ export class DimensionStickerService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("packs")
|
@Path("packs")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getStickerPacks(): Promise<MemoryStickerPack[]> {
|
public async getStickerPacks(): Promise<MemoryStickerPack[]> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const cachedPacks = Cache.for(CACHE_STICKERS).get("packs_" + userId);
|
const cachedPacks = Cache.for(CACHE_STICKERS).get("packs_" + userId);
|
||||||
@ -126,7 +126,7 @@ export class DimensionStickerService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("packs/:packId/selected")
|
@Path("packs/:packId/selected")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async setPackSelected(@PathParam("packId") packId: number, request: SetSelectedRequest): Promise<any> {
|
public async setPackSelected(@PathParam("packId") packId: number, request: SetSelectedRequest): Promise<any> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const pack = await StickerPack.findByPk(packId);
|
const pack = await StickerPack.findByPk(packId);
|
||||||
@ -150,7 +150,7 @@ export class DimensionStickerService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("packs/import")
|
@Path("packs/import")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async importPack(request: ImportPackRequest): Promise<MemoryUserStickerPack> {
|
public async importPack(request: ImportPackRequest): Promise<MemoryUserStickerPack> {
|
||||||
if (!config.stickers.enabled) {
|
if (!config.stickers.enabled) {
|
||||||
throw new ApiError(400, "Custom stickerpacks are disabled on this homeserver");
|
throw new ApiError(400, "Custom stickerpacks are disabled on this homeserver");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Context, DELETE, GET, Path, PathParam, POST, QueryParam, Security, ServiceContext } from "typescript-rest";
|
import { Context, DELETE, GET, Path, PathParam, POST, QueryParam, Security, ServiceContext } from "typescript-rest";
|
||||||
import { TelegramBridge } from "../../bridges/TelegramBridge";
|
import { TelegramBridge } from "../../bridges/TelegramBridge";
|
||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
interface PortalInfoResponse {
|
interface PortalInfoResponse {
|
||||||
bridged: boolean;
|
bridged: boolean;
|
||||||
@ -26,7 +26,7 @@ export class DimensionTelegramService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("chat/:chatId")
|
@Path("chat/:chatId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getPortalInfo(@PathParam("chatId") chatId: number, @QueryParam("roomId") roomId: string): Promise<PortalInfoResponse> {
|
public async getPortalInfo(@PathParam("chatId") chatId: number, @QueryParam("roomId") roomId: string): Promise<PortalInfoResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ export class DimensionTelegramService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("chat/:chatId/room/:roomId")
|
@Path("chat/:chatId/room/:roomId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async bridgeRoom(@PathParam("chatId") chatId: number, @PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<PortalInfoResponse> {
|
public async bridgeRoom(@PathParam("chatId") chatId: number, @PathParam("roomId") roomId: string, request: BridgeRoomRequest): Promise<PortalInfoResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ export class DimensionTelegramService {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("room/:roomId")
|
@Path("room/:roomId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async unbridgeRoom(@PathParam("roomId") roomId: string): Promise<PortalInfoResponse> {
|
public async unbridgeRoom(@PathParam("roomId") roomId: string): Promise<PortalInfoResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import Webhook from "../../db/models/Webhook";
|
|||||||
import { ApiError } from "../ApiError";
|
import { ApiError } from "../ApiError";
|
||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import * as request from "request";
|
import * as request from "request";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API for interacting with the Webhooks bridge, and for setting up proxies to other
|
* API for interacting with the Webhooks bridge, and for setting up proxies to other
|
||||||
@ -55,7 +55,7 @@ export class DimensionWebhooksService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("room/:roomId/webhooks/new")
|
@Path("room/:roomId/webhooks/new")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async newWebhook(@PathParam("roomId") roomId: string, options: WebhookOptions): Promise<WebhookConfiguration> {
|
public async newWebhook(@PathParam("roomId") roomId: string, options: WebhookOptions): Promise<WebhookConfiguration> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const webhooks = new WebhooksBridge(userId);
|
const webhooks = new WebhooksBridge(userId);
|
||||||
@ -64,7 +64,7 @@ export class DimensionWebhooksService {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("room/:roomId/webhooks/:hookId")
|
@Path("room/:roomId/webhooks/:hookId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async updateWebhook(@PathParam("roomId") roomId: string, @PathParam("hookId") hookId: string, options: WebhookOptions): Promise<WebhookConfiguration> {
|
public async updateWebhook(@PathParam("roomId") roomId: string, @PathParam("hookId") hookId: string, options: WebhookOptions): Promise<WebhookConfiguration> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const webhooks = new WebhooksBridge(userId);
|
const webhooks = new WebhooksBridge(userId);
|
||||||
@ -73,7 +73,7 @@ export class DimensionWebhooksService {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("room/:roomId/webhooks/:hookId")
|
@Path("room/:roomId/webhooks/:hookId")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async deleteWebhook(@PathParam("roomId") roomId: string, @PathParam("hookId") hookId: string): Promise<SuccessResponse> {
|
public async deleteWebhook(@PathParam("roomId") roomId: string, @PathParam("hookId") hookId: string): Promise<SuccessResponse> {
|
||||||
const userId = this.context.request.user.userId;
|
const userId = this.context.request.user.userId;
|
||||||
const webhooks = new WebhooksBridge(userId);
|
const webhooks = new WebhooksBridge(userId);
|
||||||
|
@ -2,7 +2,7 @@ import { Context, GET, Path, POST, Security, ServiceContext } from "typescript-r
|
|||||||
import { OpenId } from "../../models/OpenId";
|
import { OpenId } from "../../models/OpenId";
|
||||||
import AccountController, { IAccountInfoResponse, IAccountRegisteredResponse } from "../controllers/AccountController";
|
import AccountController, { IAccountInfoResponse, IAccountRegisteredResponse } from "../controllers/AccountController";
|
||||||
import { AutoWired, Inject } from "typescript-ioc/es6";
|
import { AutoWired, Inject } from "typescript-ioc/es6";
|
||||||
import { IMSCUser, ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ILoggedInUser, ROLE_USER } from "../security/MatrixSecurity";
|
||||||
import { ScalarClient } from "../../scalar/ScalarClient";
|
import { ScalarClient } from "../../scalar/ScalarClient";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,7 +10,7 @@ import { ScalarClient } from "../../scalar/ScalarClient";
|
|||||||
*/
|
*/
|
||||||
@Path("/_matrix/integrations/v1/account")
|
@Path("/_matrix/integrations/v1/account")
|
||||||
@AutoWired
|
@AutoWired
|
||||||
export class MSCAccountService {
|
export class MatrixAccountService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private accountController: AccountController;
|
private accountController: AccountController;
|
||||||
@ -26,15 +26,15 @@ export class MSCAccountService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async info(): Promise<IAccountInfoResponse> {
|
public async info(): Promise<IAccountInfoResponse> {
|
||||||
const user: IMSCUser = this.context.request.user;
|
const user: ILoggedInUser = this.context.request.user;
|
||||||
return {user_id: user.userId};
|
return {user_id: user.userId};
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("logout")
|
@Path("logout")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async logout(): Promise<any> {
|
public async logout(): Promise<any> {
|
||||||
await this.accountController.logout(this.context.request.user);
|
await this.accountController.logout(this.context.request.user);
|
||||||
return {};
|
return {};
|
@ -1,6 +1,6 @@
|
|||||||
import { Context, GET, Path, POST, Security, ServiceContext } from "typescript-rest";
|
import { Context, GET, Path, POST, Security, ServiceContext } from "typescript-rest";
|
||||||
import { AutoWired, Inject } from "typescript-ioc/es6";
|
import { AutoWired, Inject } from "typescript-ioc/es6";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
||||||
|
|
||||||
export interface SignTermsRequest {
|
export interface SignTermsRequest {
|
||||||
@ -12,7 +12,7 @@ export interface SignTermsRequest {
|
|||||||
*/
|
*/
|
||||||
@Path("/_matrix/integrations/v1/terms")
|
@Path("/_matrix/integrations/v1/terms")
|
||||||
@AutoWired
|
@AutoWired
|
||||||
export class MSCTermsService {
|
export class MatrixTermsService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private termsController: TermsController;
|
private termsController: TermsController;
|
||||||
@ -22,14 +22,14 @@ export class MSCTermsService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async needsSignatures(): Promise<ITermsNotSignedResponse> {
|
public async needsSignatures(): Promise<ITermsNotSignedResponse> {
|
||||||
return this.termsController.getMissingTermsForUser(this.context.request.user);
|
return this.termsController.getMissingTermsForUser(this.context.request.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async signTerms(request: SignTermsRequest): Promise<any> {
|
public async signTerms(request: SignTermsRequest): Promise<any> {
|
||||||
await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
|
await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
|
||||||
return {};
|
return {};
|
@ -4,9 +4,9 @@ import { OpenId } from "../../models/OpenId";
|
|||||||
import { ScalarAccountResponse, ScalarRegisterResponse } from "../../models/ScalarResponses";
|
import { ScalarAccountResponse, ScalarRegisterResponse } from "../../models/ScalarResponses";
|
||||||
import { AutoWired, Inject } from "typescript-ioc/es6";
|
import { AutoWired, Inject } from "typescript-ioc/es6";
|
||||||
import AccountController from "../controllers/AccountController";
|
import AccountController from "../controllers/AccountController";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
||||||
import { SignTermsRequest } from "../msc/MSCTermsService";
|
import { SignTermsRequest } from "../matrix/MatrixTermsService";
|
||||||
import { ScalarClient } from "../../scalar/ScalarClient";
|
import { ScalarClient } from "../../scalar/ScalarClient";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +39,7 @@ export class ScalarService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("account")
|
@Path("account")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getAccount(@QueryParam("v") apiVersion: string): Promise<ScalarAccountResponse> {
|
public async getAccount(@QueryParam("v") apiVersion: string): Promise<ScalarAccountResponse> {
|
||||||
if (apiVersion !== "1.1") {
|
if (apiVersion !== "1.1") {
|
||||||
throw new ApiError(401, "Invalid API version.");
|
throw new ApiError(401, "Invalid API version.");
|
||||||
@ -50,14 +50,14 @@ export class ScalarService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("terms")
|
@Path("terms")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async getTerms(): Promise<ITermsNotSignedResponse> {
|
public async getTerms(): Promise<ITermsNotSignedResponse> {
|
||||||
return this.termsController.getMissingTermsForUser(this.context.request.user);
|
return this.termsController.getMissingTermsForUser(this.context.request.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("terms")
|
@Path("terms")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async signTerms(request: SignTermsRequest): Promise<any> {
|
public async signTerms(request: SignTermsRequest): Promise<any> {
|
||||||
await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
|
await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
|
||||||
return {};
|
return {};
|
||||||
|
@ -3,7 +3,7 @@ import { LogService } from "matrix-js-snippets";
|
|||||||
import { Cache, CACHE_WIDGET_TITLES } from "../../MemoryCache";
|
import { Cache, CACHE_WIDGET_TITLES } from "../../MemoryCache";
|
||||||
import { MatrixLiteClient } from "../../matrix/MatrixLiteClient";
|
import { MatrixLiteClient } from "../../matrix/MatrixLiteClient";
|
||||||
import config from "../../config";
|
import config from "../../config";
|
||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_USER } from "../security/MatrixSecurity";
|
||||||
import moment = require("moment");
|
import moment = require("moment");
|
||||||
|
|
||||||
interface UrlPreviewResponse {
|
interface UrlPreviewResponse {
|
||||||
@ -26,7 +26,7 @@ export class ScalarWidgetService {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("title_lookup")
|
@Path("title_lookup")
|
||||||
@Security(ROLE_MSC_USER)
|
@Security(ROLE_USER)
|
||||||
public async titleLookup(@QueryParam("curl") url: string): Promise<UrlPreviewResponse> {
|
public async titleLookup(@QueryParam("curl") url: string): Promise<UrlPreviewResponse> {
|
||||||
const cachedResult = Cache.for(CACHE_WIDGET_TITLES).get(url);
|
const cachedResult = Cache.for(CACHE_WIDGET_TITLES).get(url);
|
||||||
if (cachedResult) {
|
if (cachedResult) {
|
||||||
|
@ -8,13 +8,13 @@ import config from "../../config";
|
|||||||
import { ScalarStore } from "../../db/ScalarStore";
|
import { ScalarStore } from "../../db/ScalarStore";
|
||||||
import { ScalarClient } from "../../scalar/ScalarClient";
|
import { ScalarClient } from "../../scalar/ScalarClient";
|
||||||
|
|
||||||
export interface IMSCUser {
|
export interface ILoggedInUser {
|
||||||
userId: string;
|
userId: string;
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ROLE_MSC_USER = "ROLE_MSC_USER";
|
export const ROLE_USER = "ROLE_USER";
|
||||||
export const ROLE_MSC_ADMIN = "ROLE_MSC_ADMIN";
|
export const ROLE_ADMIN = "ROLE_ADMIN";
|
||||||
|
|
||||||
const TERMS_IGNORED_ROUTES = [
|
const TERMS_IGNORED_ROUTES = [
|
||||||
{method: "*", path: "/api/v1/dimension/admin/"},
|
{method: "*", path: "/api/v1/dimension/admin/"},
|
||||||
@ -33,16 +33,16 @@ const ADMIN_ROUTES = [
|
|||||||
{method: "*", path: "/api/v1/dimension/admin/"},
|
{method: "*", path: "/api/v1/dimension/admin/"},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default class MSCSecurity implements ServiceAuthenticator {
|
export default class MatrixSecurity implements ServiceAuthenticator {
|
||||||
|
|
||||||
private accountController = new AccountController();
|
private accountController = new AccountController();
|
||||||
private termsController = new TermsController();
|
private termsController = new TermsController();
|
||||||
|
|
||||||
public getRoles(req: Request): string[] {
|
public getRoles(req: Request): string[] {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
const roles = [ROLE_MSC_USER];
|
const roles = [ROLE_USER];
|
||||||
if (config.admins.includes(req.user.userId)) {
|
if (config.admins.includes(req.user.userId)) {
|
||||||
roles.push(ROLE_MSC_ADMIN);
|
roles.push(ROLE_ADMIN);
|
||||||
}
|
}
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
@ -63,12 +63,12 @@ export default class MSCSecurity implements ServiceAuthenticator {
|
|||||||
} else if (req.query && req.query.access_token) {
|
} else if (req.query && req.query.access_token) {
|
||||||
token = req.query.access_token;
|
token = req.query.access_token;
|
||||||
} else if (req.query && req.query.scalar_token) {
|
} else if (req.query && req.query.scalar_token) {
|
||||||
LogService.warn("MSCSecurity", "Request used old scalar_token auth - this will be removed in a future version");
|
LogService.warn("MatrixSecurity", "Request used old scalar_token auth - this will be removed in a future version");
|
||||||
token = req.query.scalar_token;
|
token = req.query.scalar_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
req.user = <IMSCUser>{
|
req.user = <ILoggedInUser>{
|
||||||
userId: await this.accountController.getTokenOwner(token),
|
userId: await this.accountController.getTokenOwner(token),
|
||||||
token: token,
|
token: token,
|
||||||
};
|
};
|
||||||
@ -93,7 +93,7 @@ export default class MSCSecurity implements ServiceAuthenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.matchesAnyRoute(req, ADMIN_ROUTES, false) && !this.getRoles(req).includes(ROLE_MSC_ADMIN)) {
|
if (this.matchesAnyRoute(req, ADMIN_ROUTES, false) && !this.getRoles(req).includes(ROLE_ADMIN)) {
|
||||||
return res.status(403).json({errcode: "M_UNAUTHORIZED", error: "User is not an admin"});
|
return res.status(403).json({errcode: "M_UNAUTHORIZED", error: "User is not an admin"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ export default class MSCSecurity implements ServiceAuthenticator {
|
|||||||
if (e instanceof ApiError) {
|
if (e instanceof ApiError) {
|
||||||
res.status(e.statusCode).json(e.jsonResponse);
|
res.status(e.statusCode).json(e.jsonResponse);
|
||||||
} else {
|
} else {
|
||||||
LogService.error("MSCSecurity", e);
|
LogService.error("MatrixSecurity", e);
|
||||||
res.status(500).json({errcode: "M_UNKNOWN", error: "Unknown server error"});
|
res.status(500).json({errcode: "M_UNKNOWN", error: "Unknown server error"});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ import { SessionStorage } from "../SessionStorage";
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
|
|
||||||
export class AuthedApi {
|
export class AuthedApi {
|
||||||
constructor(protected http: HttpClient, private mscAuth = false) {
|
constructor(protected http: HttpClient, private matrixAuth = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected authedGet<T>(url: string, qs?: any): Observable<T> {
|
protected authedGet<T>(url: string, qs?: any): Observable<T> {
|
||||||
@ -32,7 +32,7 @@ export class AuthedApi {
|
|||||||
if (!opts) opts = {};
|
if (!opts) opts = {};
|
||||||
if (!qs) qs = {};
|
if (!qs) qs = {};
|
||||||
if (!headers) headers = {};
|
if (!headers) headers = {};
|
||||||
if (this.mscAuth) {
|
if (this.matrixAuth) {
|
||||||
headers["Authorization"] = `Bearer ${SessionStorage.scalarToken}`;
|
headers["Authorization"] = `Bearer ${SessionStorage.scalarToken}`;
|
||||||
} else {
|
} else {
|
||||||
qs["scalar_token"] = SessionStorage.scalarToken;
|
qs["scalar_token"] = SessionStorage.scalarToken;
|
||||||
|
Loading…
Reference in New Issue
Block a user