Fix feedback on PR

Change locale as parameter on adminInterface
This commit is contained in:
CEC 2022-04-20 16:30:16 +02:00
parent f1a93fea88
commit 5466bd1d68
7 changed files with 43 additions and 30 deletions

View File

@ -169,6 +169,7 @@ export class AuthenticateController extends BaseHttpController {
//Get user data from Admin Back Office //Get user data from Admin Back Office
//This is very important to create User Local in LocalStorage in WorkAdventure //This is very important to create User Local in LocalStorage in WorkAdventure
const resUserData = await adminService.fetchMemberDataByUuid( const resUserData = await adminService.fetchMemberDataByUuid(
req.header("accept-language"),
authTokenData.identifier, authTokenData.identifier,
playUri as string, playUri as string,
IPAddress, IPAddress,
@ -224,7 +225,7 @@ export class AuthenticateController extends BaseHttpController {
//Get user data from Admin Back Office //Get user data from Admin Back Office
//This is very important to create User Local in LocalStorage in WorkAdventure //This is very important to create User Local in LocalStorage in WorkAdventure
const data = await adminService.fetchMemberDataByUuid(email, playUri as string, IPAddress, []); const data = await adminService.fetchMemberDataByUuid(req.header("accept-language"), email, playUri as string, IPAddress, []);
return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale }); return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
} catch (e) { } catch (e) {
@ -321,15 +322,13 @@ export class AuthenticateController extends BaseHttpController {
(async () => { (async () => {
const param = await req.json(); const param = await req.json();
adminService.locale = req.header("accept-language");
//todo: what to do if the organizationMemberToken is already used? //todo: what to do if the organizationMemberToken is already used?
const organizationMemberToken: string | null = param.organizationMemberToken; const organizationMemberToken: string | null = param.organizationMemberToken;
const playUri: string | null = param.playUri; const playUri: string | null = param.playUri;
try { try {
if (typeof organizationMemberToken != "string") throw new Error("No organization token"); if (typeof organizationMemberToken != "string") throw new Error("No organization token");
const data = await adminService.fetchMemberDataByToken(organizationMemberToken, playUri); const data = await adminService.fetchMemberDataByToken(req.header("accept-language"), organizationMemberToken, playUri);
const userUuid = data.userUuid; const userUuid = data.userUuid;
const email = data.email; const email = data.email;
const roomUrl = data.roomUrl; const roomUrl = data.roomUrl;
@ -508,7 +507,7 @@ export class AuthenticateController extends BaseHttpController {
userRoomToken: undefined, userRoomToken: undefined,
}; };
try { try {
data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []); data = await adminService.fetchMemberDataByUuid("en", email, playUri, IPAddress, []);
} catch (err) { } catch (err) {
console.error("openIDCallback => fetchMemberDataByUuid", err); console.error("openIDCallback => fetchMemberDataByUuid", err);
} }

View File

@ -246,8 +246,6 @@ export class IoSocketController {
const websocketExtensions = req.getHeader("sec-websocket-extensions"); const websocketExtensions = req.getHeader("sec-websocket-extensions");
const IPAddress = req.getHeader("x-forwarded-for"); const IPAddress = req.getHeader("x-forwarded-for");
adminService.locale = req.getHeader("accept-language");
const roomId = query.roomId; const roomId = query.roomId;
try { try {
if (typeof roomId !== "string") { if (typeof roomId !== "string") {
@ -316,6 +314,7 @@ export class IoSocketController {
try { try {
try { try {
userData = await adminService.fetchMemberDataByUuid( userData = await adminService.fetchMemberDataByUuid(
req.getHeader("accept-language"),
userIdentifier, userIdentifier,
roomId, roomId,
IPAddress, IPAddress,

View File

@ -104,12 +104,10 @@ export class MapController extends BaseHttpController {
return; return;
} }
adminService.locale = req.header("accept-language");
(async () => { (async () => {
try { try {
const mapDetails = isMapDetailsData.parse( const mapDetails = isMapDetailsData.parse(
await adminService.fetchMapDetails(query.playUri as string, query.authToken as string) await adminService.fetchMapDetails(req.header("accept-language"), query.playUri as string, query.authToken as string)
); );
if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true; if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true;

View File

@ -29,9 +29,7 @@ export const isFetchMemberDataByUuidResponse = z.object({
export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>; export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>;
class AdminApi implements AdminInterface { class AdminApi implements AdminInterface {
locale: string = "en"; async fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect> {
async fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect> {
let userId: string | undefined = undefined; let userId: string | undefined = undefined;
if (authToken != undefined) { if (authToken != undefined) {
let authTokenData: AuthTokenData; let authTokenData: AuthTokenData;
@ -66,7 +64,7 @@ class AdminApi implements AdminInterface {
}; };
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/map", { const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/map", {
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
params, params,
}); });
@ -89,6 +87,7 @@ class AdminApi implements AdminInterface {
} }
async fetchMemberDataByUuid( async fetchMemberDataByUuid(
locale: string,
userIdentifier: string, userIdentifier: string,
playUri: string, playUri: string,
ipAddress: string, ipAddress: string,
@ -101,7 +100,7 @@ class AdminApi implements AdminInterface {
ipAddress, ipAddress,
characterLayers, characterLayers,
}, },
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
paramsSerializer: (p) => { paramsSerializer: (p) => {
return qs.stringify(p, { arrayFormat: "brackets" }); return qs.stringify(p, { arrayFormat: "brackets" });
}, },
@ -120,11 +119,11 @@ class AdminApi implements AdminInterface {
); );
} }
async fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> { async fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case. //todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, { const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
params: { playUri }, params: { playUri },
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
}); });
const adminApiData = isAdminApiData.safeParse(res.data); const adminApiData = isAdminApiData.safeParse(res.data);
@ -139,6 +138,7 @@ class AdminApi implements AdminInterface {
} }
reportPlayer( reportPlayer(
locale: string,
reportedUserUuid: string, reportedUserUuid: string,
reportedUserComment: string, reportedUserComment: string,
reporterUserUuid: string, reporterUserUuid: string,
@ -153,12 +153,12 @@ class AdminApi implements AdminInterface {
reportWorldSlug, reportWorldSlug,
}, },
{ {
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
} }
); );
} }
async verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> { async verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case. //todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
return Axios.get( return Axios.get(
ADMIN_API_URL + ADMIN_API_URL +
@ -169,15 +169,15 @@ class AdminApi implements AdminInterface {
encodeURIComponent(userUuid) + encodeURIComponent(userUuid) +
"&roomUrl=" + "&roomUrl=" +
encodeURIComponent(roomUrl), encodeURIComponent(roomUrl),
{ headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale } } { headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale } }
).then((data) => { ).then((data) => {
return data.data; return data.data;
}); });
} }
async getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]> { async getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise<string[]> {
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), { return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
}).then((data) => { }).then((data) => {
return data.data; return data.data;
}); });

View File

@ -4,7 +4,6 @@ import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
export interface AdminInterface { export interface AdminInterface {
locale: string;
/** /**
* @var playUri: is url of the room * @var playUri: is url of the room
@ -14,6 +13,7 @@ export interface AdminInterface {
* @return MapDetailsData|RoomRedirect * @return MapDetailsData|RoomRedirect
*/ */
fetchMemberDataByUuid( fetchMemberDataByUuid(
locale: string,
userIdentifier: string, userIdentifier: string,
playUri: string, playUri: string,
ipAddress: string, ipAddress: string,
@ -25,22 +25,25 @@ export interface AdminInterface {
* @var userId: can to be undefined or email or uuid * @var userId: can to be undefined or email or uuid
* @return MapDetailsData|RoomRedirect * @return MapDetailsData|RoomRedirect
*/ */
fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect>; fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect>;
/** /**
* @param locale
* @param organizationMemberToken * @param organizationMemberToken
* @param playUri * @param playUri
* @return AdminApiData * @return AdminApiData
*/ */
fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>; fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>;
/** /**
* @param locale
* @param reportedUserUuid * @param reportedUserUuid
* @param reportedUserComment * @param reportedUserComment
* @param reporterUserUuid * @param reporterUserUuid
* @param reportWorldSlug * @param reportWorldSlug
*/ */
reportPlayer( reportPlayer(
locale: string,
reportedUserUuid: string, reportedUserUuid: string,
reportedUserComment: string, reportedUserComment: string,
reporterUserUuid: string, reporterUserUuid: string,
@ -48,18 +51,20 @@ export interface AdminInterface {
): Promise<unknown>; ): Promise<unknown>;
/** /**
* @param locale
* @param userUuid * @param userUuid
* @param ipAddress * @param ipAddress
* @param roomUrl * @param roomUrl
* @return AdminBannedData * @return AdminBannedData
*/ */
verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData>; verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData>;
/** /**
* @param locale
* @param roomUrl * @param roomUrl
* @return string[] * @return string[]
*/ */
getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]>; getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise<string[]>;
/** /**
* @param accessToken * @param accessToken

View File

@ -10,9 +10,10 @@ import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
* A local class mocking a real admin if no admin is configured. * A local class mocking a real admin if no admin is configured.
*/ */
class LocalAdmin implements AdminInterface { class LocalAdmin implements AdminInterface {
locale: string = "en";
fetchMemberDataByUuid( fetchMemberDataByUuid(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
userIdentifier: string, userIdentifier: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
playUri: string, playUri: string,
@ -33,6 +34,8 @@ class LocalAdmin implements AdminInterface {
} }
fetchMapDetails( fetchMapDetails(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
playUri: string, playUri: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
authToken?: string authToken?: string
@ -61,6 +64,8 @@ class LocalAdmin implements AdminInterface {
} }
async fetchMemberDataByToken( async fetchMemberDataByToken(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
organizationMemberToken: string, organizationMemberToken: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -70,6 +75,8 @@ class LocalAdmin implements AdminInterface {
} }
reportPlayer( reportPlayer(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
reportedUserUuid: string, reportedUserUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -83,6 +90,8 @@ class LocalAdmin implements AdminInterface {
} }
async verifyBanUser( async verifyBanUser(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
userUuid: string, userUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -94,6 +103,8 @@ class LocalAdmin implements AdminInterface {
} }
async getUrlRoomsFromSameWorld( async getUrlRoomsFromSameWorld(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
roomUrl: string roomUrl: string
): Promise<string[]> { ): Promise<string[]> {

View File

@ -360,6 +360,7 @@ export class SocketManager implements ZoneEventListener {
async handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) { async handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
try { try {
await adminService.reportPlayer( await adminService.reportPlayer(
"en",
reportPlayerMessage.getReporteduseruuid(), reportPlayerMessage.getReporteduseruuid(),
reportPlayerMessage.getReportcomment(), reportPlayerMessage.getReportcomment(),
client.userUuid, client.userUuid,
@ -445,7 +446,7 @@ export class SocketManager implements ZoneEventListener {
} }
public async updateRoomWithAdminData(room: PusherRoom): Promise<void> { public async updateRoomWithAdminData(room: PusherRoom): Promise<void> {
const data = await adminService.fetchMapDetails(room.roomUrl); const data = await adminService.fetchMapDetails("en", room.roomUrl);
const mapDetailsData = isMapDetailsData.safeParse(data); const mapDetailsData = isMapDetailsData.safeParse(data);
if (mapDetailsData.success) { if (mapDetailsData.success) {
@ -696,7 +697,7 @@ export class SocketManager implements ZoneEventListener {
let tabUrlRooms: string[]; let tabUrlRooms: string[];
if (playGlobalMessageEvent.getBroadcasttoworld()) { if (playGlobalMessageEvent.getBroadcasttoworld()) {
tabUrlRooms = await adminService.getUrlRoomsFromSameWorld(clientRoomUrl); tabUrlRooms = await adminService.getUrlRoomsFromSameWorld("en", clientRoomUrl);
} else { } else {
tabUrlRooms = [clientRoomUrl]; tabUrlRooms = [clientRoomUrl];
} }