mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 05:05:53 +00:00
Support terms handling on legacy scalar route
This commit is contained in:
parent
3b4aa7b0ba
commit
cf212d8f4e
@ -77,7 +77,7 @@ export default class Webserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { AutoWired, Inject } from "typescript-ioc/es6";
|
|||||||
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
import { ROLE_MSC_USER } from "../security/MSCSecurity";
|
||||||
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
||||||
|
|
||||||
interface SignTermsRequest {
|
export interface SignTermsRequest {
|
||||||
user_accepts: string[];
|
user_accepts: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import { ScalarAccountResponse, ScalarRegisterResponse } from "../../models/Scal
|
|||||||
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_MSC_USER } from "../security/MSCSecurity";
|
||||||
|
import TermsController, { ITermsNotSignedResponse } from "../controllers/TermsController";
|
||||||
|
import { SignTermsRequest } from "../msc/MSCTermsService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API for the minimum Scalar API we need to implement to be compatible with clients. Used for registration
|
* API for the minimum Scalar API we need to implement to be compatible with clients. Used for registration
|
||||||
@ -17,6 +19,9 @@ export class ScalarService {
|
|||||||
@Inject
|
@Inject
|
||||||
private accountController: AccountController;
|
private accountController: AccountController;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private termsController: TermsController;
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
private context: ServiceContext;
|
private context: ServiceContext;
|
||||||
|
|
||||||
@ -42,6 +47,21 @@ export class ScalarService {
|
|||||||
return {user_id: this.context.request.user.userId};
|
return {user_id: this.context.request.user.userId};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("terms")
|
||||||
|
@Security(ROLE_MSC_USER)
|
||||||
|
public async getTerms(): Promise<ITermsNotSignedResponse> {
|
||||||
|
return this.termsController.getMissingTermsForUser(this.context.request.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("terms")
|
||||||
|
@Security(ROLE_MSC_USER)
|
||||||
|
public async signTerms(request: SignTermsRequest): Promise<any> {
|
||||||
|
await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("ping")
|
@Path("ping")
|
||||||
public async ping(): Promise<any> {
|
public async ping(): Promise<any> {
|
||||||
|
@ -21,6 +21,11 @@ const TERMS_IGNORED_ROUTES = [
|
|||||||
{method: "POST", path: "/_matrix/integrations/v1/terms"},
|
{method: "POST", path: "/_matrix/integrations/v1/terms"},
|
||||||
{method: "POST", path: "/_matrix/integrations/v1/register"},
|
{method: "POST", path: "/_matrix/integrations/v1/register"},
|
||||||
{method: "POST", path: "/_matrix/integrations/v1/logout"},
|
{method: "POST", path: "/_matrix/integrations/v1/logout"},
|
||||||
|
|
||||||
|
// Legacy scalar routes
|
||||||
|
{method: "GET", path: "/api/v1/scalar/terms"},
|
||||||
|
{method: "POST", path: "/api/v1/scalar/terms"},
|
||||||
|
{method: "POST", path: "/api/v1/scalar/register"},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ADMIN_ROUTES = [
|
const ADMIN_ROUTES = [
|
||||||
|
Loading…
Reference in New Issue
Block a user