-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module-api): external users module
- Loading branch information
marc.sirisak
committed
Jul 4, 2024
1 parent
827f3fd
commit 0c14fab
Showing
16 changed files
with
5,876 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ modules: | |
|
||
# Pulling from filesystem. | ||
- "file:./modules/tchap-translations" | ||
- "file:./modules/tchap-external-users" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"sourceMaps": true, | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react", | ||
"@babel/preset-typescript" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-transform-runtime" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
plugins: [ | ||
"matrix-org", | ||
], | ||
extends: [ | ||
"plugin:matrix-org/babel", | ||
], | ||
env: { | ||
browser: true, | ||
node: true, | ||
}, | ||
rules: { | ||
// No specific rules | ||
}, | ||
overrides: [{ | ||
files: [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
extends: [ | ||
"plugin:matrix-org/typescript", | ||
], | ||
rules: { | ||
// TypeScript has its own version of this | ||
"@babel/no-invalid-this": "off", | ||
|
||
// We're okay being explicit at the moment | ||
"@typescript-eslint/no-empty-interface": "off", | ||
|
||
// Turn off things we're not concerned about here | ||
"quotes": "off", | ||
"object-curly-spacing": "off", | ||
"array-bracket-spacing": "off", | ||
"quote-props": "off", // "be sensible" | ||
"@typescript-eslint/no-explicit-any": "off", // handled at review time | ||
|
||
// We want to go a bit long for clarity | ||
"max-len": ["error", {"code": 160}], | ||
|
||
// Casing is something we'll resolve at review time | ||
"camelcase": "off", | ||
"@typescript-eslint/naming-convention": "off", | ||
}, | ||
}], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Custom | ||
.idea/ | ||
lib/ | ||
.npmrc | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Tchap-external-users | ||
A simple module that implement the specificities for a tchap external users. | ||
|
||
- Display a unique dialog when trying to add/search a new room |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Joi from 'joi'; | ||
|
||
export const TCHAP_EXTERNAL_USERS_MODULE_CONFIG_NAMESPACE = | ||
'fr.gouv.beta.tchap.module.external_users'; | ||
export const TCHAP_EXTERNAL_USERS_MODULE_CONFIG_KEY = 'config'; | ||
|
||
/** | ||
* Configurations for the guest module. | ||
*/ | ||
export interface TchapExternalUsersModuleConfig { | ||
/** | ||
* The URL of the homeserver where the guest users should be registered. This | ||
* must have the `synapse-guest-module` installed. | ||
* @example `https://synapse.local` | ||
* | ||
* @remark If the URL is set to `USE_REGISTER_ENDPOINT`, this activates a legacy | ||
* mode that will call the original register endpoint. This is only | ||
* supposed to be used with a legacy synapse module implementation. | ||
*/ | ||
user_homeserver_url: string; | ||
} | ||
|
||
const tchapExternalUserModuleConfigSchema = Joi.object<TchapExternalUsersModuleConfig, true>({ | ||
user_homeserver_url: Joi.string() | ||
.uri() | ||
.required(), | ||
}).unknown(); | ||
|
||
/** | ||
* Validates that the config has a valid structure for a {@link TchapExternalUsersModuleConfig}. | ||
*/ | ||
export function assertValidExternalUsersModuleConfig( | ||
config: unknown, | ||
): asserts config is TchapExternalUsersModuleConfig { | ||
|
||
const result = tchapExternalUserModuleConfigSchema.validate(config); | ||
|
||
if (result.error) { | ||
throw new Error( | ||
`Errors in the module configuration in "${TCHAP_EXTERNAL_USERS_MODULE_CONFIG_NAMESPACE}".${TCHAP_EXTERNAL_USERS_MODULE_CONFIG_KEY}: ${result.error.message}`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "tchap-external-users-module", | ||
"version": "0.0.1", | ||
"description": "Tchap module for external users", | ||
"main": "lib/TchapExternalUsersModule.js", | ||
"types": "lib/TchapExternalUsersModule.d.ts", | ||
"author": "DINUM", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"build": "yarn clean && yarn build:compile && yarn build:types", | ||
"build:types": "tsc -p ./tsconfig.build.json --emitDeclarationOnly", | ||
"build:compile": "babel -d lib --verbose --extensions \".ts,.tsx\" src", | ||
"start": "tsc -p ./tsconfig.build.json -w", | ||
"test": "jest", | ||
"lint": "eslint src test && tsc --noEmit", | ||
"lint:fix": "eslint --fix src test", | ||
"prepare": "yarn build" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.17.6", | ||
"@babel/core": "^7.17.8", | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@babel/eslint-plugin": "^7.17.7", | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/plugin-transform-runtime": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-react": "^7.16.7", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@testing-library/jest-dom": "^6.4.6", | ||
"@testing-library/react": "^12.1.5", | ||
"@types/jest": "^29.5.12", | ||
"@types/react": "^17", | ||
"@typescript-eslint/eslint-plugin": "^5.18.0", | ||
"@typescript-eslint/parser": "^5.18.0", | ||
"eslint": "^8.12.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-matrix-org": "^0.4.0", | ||
"jest": "^27.5.1", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.1.4", | ||
"typescript": "^4.6.3" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.17.9", | ||
"@matrix-org/react-sdk-module-api": "^1.0.0", | ||
"joi": "^17.13.3" | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
modules/tchap-external-users/src/TchapExternalUsersModule.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2022 New Vector Ltd. t/a Element | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule"; | ||
import { ModuleApi } from "@matrix-org/react-sdk-module-api/lib/ModuleApi"; | ||
import { CantAddDialog } from "./components/CantAddDialog"; | ||
import { AddRoomListener, ExternalUsersLifecycle } from "@matrix-org/react-sdk-module-api/src/tchap/lifecycles/ExternalUsers"; | ||
import { DialogProps } from "@matrix-org/react-sdk-module-api/lib/components/DialogContent"; | ||
|
||
import React from "react"; | ||
|
||
export default class TchapExternalUsersModule extends RuntimeModule { | ||
private domain: String; | ||
|
||
public constructor(moduleApi: ModuleApi) { | ||
super(moduleApi); | ||
|
||
// const rawConfig = this.moduleApi.getConfigValue( | ||
// TCHAP_EXTERNAL_USERS_MODULE_CONFIG_NAMESPACE, | ||
// TCHAP_EXTERNAL_USERS_MODULE_CONFIG_KEY, | ||
// ); | ||
|
||
// assertValidGuestModuleConfig(rawConfig); | ||
// this.config = rawConfig; | ||
|
||
this.on(ExternalUsersLifecycle.AddRoom, this.onAddRoom); | ||
} | ||
|
||
protected onAddRoom: AddRoomListener = () => { | ||
this.moduleApi.openDialog<null, DialogProps, CantAddDialog>( | ||
{ | ||
title: "test title", | ||
actionLabel: "test action", | ||
canSubmit: false, | ||
}, | ||
(props, ref) => <CantAddDialog ref={ref} {...props} /> | ||
); | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/tchap-external-users/src/components/CantAddDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from "react"; | ||
import { DialogProps, DialogState } from "@matrix-org/react-sdk-module-api/lib/components/DialogContent"; | ||
import { DialogContent } from "@matrix-org/react-sdk-module-api/lib/components/DialogContent"; | ||
|
||
export class CantAddDialog extends DialogContent<DialogProps, DialogState,{}> { | ||
public async trySubmit(): Promise<null> { | ||
return Promise.resolve(null); | ||
} | ||
|
||
public render() { | ||
return <div> | ||
<p> Coucou externe tu n'as pas le droit </p> | ||
</div>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"sourceMap": true, | ||
"noEmit": false, | ||
"module": "commonjs", | ||
"emitDecoratorMetadata": true, | ||
"declaration": true, | ||
"outDir": "./lib", | ||
"jsx": "react" | ||
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
"./src/**/*.tsx" | ||
] | ||
} |
Oops, something went wrong.