Support terms handling on legacy scalar route

This commit is contained in:
Travis Ralston 2019-07-10 20:59:39 -06:00
parent 3b4aa7b0ba
commit cf212d8f4e
4 changed files with 27 additions and 2 deletions

View File

@ -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();
}); });
} }

View File

@ -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[];
} }

View File

@ -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> {

View File

@ -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 = [