From 122329444eafa54b6aae3efcf39e90981e89fc87 Mon Sep 17 00:00:00 2001 From: Marigold Date: Mon, 11 Nov 2024 10:37:18 +0100 Subject: [PATCH 1/4] :sparkles: add column githubUsername to users table --- adminSiteServer/authentication.tsx | 20 +++++++--- .../1731317168994-AddGithubUsernameToUsers.ts | 39 +++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 db/migration/1731317168994-AddGithubUsernameToUsers.ts diff --git a/adminSiteServer/authentication.tsx b/adminSiteServer/authentication.tsx index 8118ff66e5e..4c045987a88 100644 --- a/adminSiteServer/authentication.tsx +++ b/adminSiteServer/authentication.tsx @@ -301,14 +301,22 @@ export async function tailscaleAuthMiddleware( return next() } - const user = await db - .knexInstance() - .table("users") - .where({ fullName: githubUserName }) - .first() + let user + try { + // Look up user by 'githubUsername' + user = await db + .knexInstance() + .table("users") + .where({ githubUsername: githubUserName }) + .first() + } catch (error) { + console.error(`Error looking up user by githubUsername: ${error}`) + return next() + } + if (!user) { console.error( - `User with name ${githubUserName} not found in MySQL. Please change your Github profile name to match your MySQL user.` + `User with githubUsername ${githubUserName} not found in MySQL.` ) return next() } diff --git a/db/migration/1731317168994-AddGithubUsernameToUsers.ts b/db/migration/1731317168994-AddGithubUsernameToUsers.ts new file mode 100644 index 00000000000..4e0a0e1f171 --- /dev/null +++ b/db/migration/1731317168994-AddGithubUsernameToUsers.ts @@ -0,0 +1,39 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class AddGithubUsernameToUsers1731317168994 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + // Add 'githubUsername' column using raw SQL + await queryRunner.query(` + ALTER TABLE users ADD COLUMN githubUsername VARCHAR(255) NULL; + `) + + // Set 'githubUsername' = 'fullName' by default + await queryRunner.query(` + UPDATE users + SET githubUsername = fullName; + `) + + // Update 'githubUsername' for specific users + await queryRunner.query(` + UPDATE users + SET githubUsername = 'Tuna' WHERE fullName = 'Tuna Acisu'; + UPDATE users + SET githubUsername = 'bastianherre' WHERE fullName = 'Bastian Herre'; + UPDATE users + SET githubUsername = 'JoeHasell' WHERE fullName = 'Joe Hasell'; + UPDATE users + SET githubUsername = 'mrwbkrm' WHERE fullName = 'Marwa Boukarim'; + UPDATE users + SET githubUsername = 'veronikasamborska1994' WHERE fullName = 'Veronika Samborska'; + `) + } + + public async down(queryRunner: QueryRunner): Promise { + // Remove 'githubUsername' column using raw SQL + await queryRunner.query(` + ALTER TABLE users DROP COLUMN githubUsername; + `) + } +} From 1437ba08bc0b77599b6b67ed89939dcfedccae0e Mon Sep 17 00:00:00 2001 From: Marigold Date: Mon, 11 Nov 2024 10:58:12 +0100 Subject: [PATCH 2/4] wip --- .../1731317168994-AddGithubUsernameToUsers.ts | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/db/migration/1731317168994-AddGithubUsernameToUsers.ts b/db/migration/1731317168994-AddGithubUsernameToUsers.ts index 4e0a0e1f171..fa91df56be0 100644 --- a/db/migration/1731317168994-AddGithubUsernameToUsers.ts +++ b/db/migration/1731317168994-AddGithubUsernameToUsers.ts @@ -16,18 +16,27 @@ export class AddGithubUsernameToUsers1731317168994 `) // Update 'githubUsername' for specific users - await queryRunner.query(` - UPDATE users - SET githubUsername = 'Tuna' WHERE fullName = 'Tuna Acisu'; - UPDATE users - SET githubUsername = 'bastianherre' WHERE fullName = 'Bastian Herre'; - UPDATE users - SET githubUsername = 'JoeHasell' WHERE fullName = 'Joe Hasell'; - UPDATE users - SET githubUsername = 'mrwbkrm' WHERE fullName = 'Marwa Boukarim'; + const updates = [ + { fullName: "Tuna Acisu", githubUsername: "Tuna" }, + { fullName: "Bastian Herre", githubUsername: "bastianherre" }, + { fullName: "Joe Hasell", githubUsername: "JoeHasell" }, + { fullName: "Marwa Boukarim", githubUsername: "mrwbkrm" }, + { + fullName: "Veronika Samborska", + githubUsername: "veronikasamborska1994", + }, + ] + + for (const { fullName, githubUsername } of updates) { + await queryRunner.query( + ` UPDATE users - SET githubUsername = 'veronikasamborska1994' WHERE fullName = 'Veronika Samborska'; - `) + SET githubUsername = ? + WHERE fullName = ?; + `, + [githubUsername, fullName] + ) + } } public async down(queryRunner: QueryRunner): Promise { From 6fb9e5df78e030ff68ab30974ea1ececffcb3b11 Mon Sep 17 00:00:00 2001 From: Marigold Date: Mon, 11 Nov 2024 11:32:21 +0100 Subject: [PATCH 3/4] wip --- db/migration/1731317168994-AddGithubUsernameToUsers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migration/1731317168994-AddGithubUsernameToUsers.ts b/db/migration/1731317168994-AddGithubUsernameToUsers.ts index fa91df56be0..766e6769481 100644 --- a/db/migration/1731317168994-AddGithubUsernameToUsers.ts +++ b/db/migration/1731317168994-AddGithubUsernameToUsers.ts @@ -17,14 +17,14 @@ export class AddGithubUsernameToUsers1731317168994 // Update 'githubUsername' for specific users const updates = [ - { fullName: "Tuna Acisu", githubUsername: "Tuna" }, { fullName: "Bastian Herre", githubUsername: "bastianherre" }, - { fullName: "Joe Hasell", githubUsername: "JoeHasell" }, { fullName: "Marwa Boukarim", githubUsername: "mrwbkrm" }, { - fullName: "Veronika Samborska", - githubUsername: "veronikasamborska1994", + fullName: "Natalie Reynolds-Garcia", + githubUsername: "natreygar", }, + { fullName: "Max Roser", githubUsername: "Max" }, + { fullName: "Valerie Muigai", githubUsername: "ValRMuigai" }, ] for (const { fullName, githubUsername } of updates) { From 3bb3ec342427e2adb720f2731c3ac9de9ba6f343 Mon Sep 17 00:00:00 2001 From: Marigold Date: Thu, 14 Nov 2024 14:12:21 +0100 Subject: [PATCH 4/4] wip --- adminSiteServer/authentication.tsx | 14 ++-- .../1731317168994-AddGithubUsernameToUsers.ts | 76 ++++++++++++++++--- 2 files changed, 72 insertions(+), 18 deletions(-) diff --git a/adminSiteServer/authentication.tsx b/adminSiteServer/authentication.tsx index 4c045987a88..605fb4c6747 100644 --- a/adminSiteServer/authentication.tsx +++ b/adminSiteServer/authentication.tsx @@ -273,6 +273,7 @@ interface TailscaleStatus { User?: { [key: string]: { DisplayName?: string + LoginName?: string } } } @@ -357,15 +358,14 @@ async function getTailscaleIpToUserMap(): Promise> { const ipToUser: Record = {} // Map UserIDs to LoginNames - const userIdToDisplayName: Record = {} + const userIdToLoginName: Record = {} if (tailscaleStatus.User) { for (const [userId, userInfo] of Object.entries( tailscaleStatus.User )) { - if (userInfo.DisplayName) { - userIdToDisplayName[parseInt(userId)] = - userInfo.DisplayName + if (userInfo.LoginName) { + userIdToLoginName[parseInt(userId)] = userInfo.LoginName } } } @@ -373,10 +373,10 @@ async function getTailscaleIpToUserMap(): Promise> { // Include Peers if (tailscaleStatus.Peer) { for (const peer of Object.values(tailscaleStatus.Peer)) { - if (peer.UserID in userIdToDisplayName) { - const displayName = userIdToDisplayName[peer.UserID] + if (peer.UserID in userIdToLoginName) { + const LoginName = userIdToLoginName[peer.UserID] for (const ip of peer.TailscaleIPs) { - ipToUser[ip] = displayName + ipToUser[ip] = LoginName } } } diff --git a/db/migration/1731317168994-AddGithubUsernameToUsers.ts b/db/migration/1731317168994-AddGithubUsernameToUsers.ts index 766e6769481..2287a20d673 100644 --- a/db/migration/1731317168994-AddGithubUsernameToUsers.ts +++ b/db/migration/1731317168994-AddGithubUsernameToUsers.ts @@ -9,22 +9,76 @@ export class AddGithubUsernameToUsers1731317168994 ALTER TABLE users ADD COLUMN githubUsername VARCHAR(255) NULL; `) - // Set 'githubUsername' = 'fullName' by default - await queryRunner.query(` - UPDATE users - SET githubUsername = fullName; - `) - // Update 'githubUsername' for specific users const updates = [ - { fullName: "Bastian Herre", githubUsername: "bastianherre" }, - { fullName: "Marwa Boukarim", githubUsername: "mrwbkrm" }, + { fullName: "Martin Račák", githubUsername: "rakyi@github" }, + { + fullName: "Marcel Gerber", + githubUsername: "marcelgerber@github", + }, + { fullName: "Lars Yencken", githubUsername: "larsyencken@github" }, + { fullName: "Matthieu Bergel", githubUsername: "mlbrgl@github" }, + { + fullName: "Simon van Teutem", + githubUsername: "simonvanteutem@github", + }, + { + fullName: "Lucas Rodés-Guirao", + githubUsername: "lucasrodes@github", + }, + { + fullName: "Veronika Samborska", + githubUsername: "veronikasamborska1994@github", + }, + { fullName: "Saloni Dattani", githubUsername: "saloni-nd@github" }, + { + fullName: "Charlie Giattino", + githubUsername: "CGiattino@github", + }, + { + fullName: "Hannah Ritchie", + githubUsername: "HannahRitchie@github", + }, + { fullName: "Mojmir Vinkler", githubUsername: "Marigold@github" }, + { fullName: "Ike Saunders", githubUsername: "ikesau@github" }, + { + fullName: "Sophia Mersmann", + githubUsername: "sophiamersmann@github", + }, + { fullName: "Joe Hasell", githubUsername: "JoeHasell@github" }, + { fullName: "Edouard Mathieu", githubUsername: "edomt@github" }, + { fullName: "Daniel Bachler", githubUsername: "danyx23@github" }, + { fullName: "Fiona Spooner", githubUsername: "spoonerf@github" }, + { fullName: "Marwa Boukarim", githubUsername: "mrwbkrm@github" }, + { fullName: "Max Roser", githubUsername: "maxroser@github" }, + { + fullName: "Pablo Arriagada", + githubUsername: "paarriagadap@github", + }, + { fullName: "Tuna Acisu", githubUsername: "antea04@github" }, + { + fullName: "Esteban Ortiz-Ospina", + githubUsername: "eoo-owid@github", + }, { fullName: "Natalie Reynolds-Garcia", - githubUsername: "natreygar", + githubUsername: "natreygar@github", + }, + { fullName: "Bertha Rohenkohl", githubUsername: "bertharc@github" }, + { + fullName: "Bobbie Macdonald", + githubUsername: "bnjmacdonald@github", + }, + { + fullName: "Angela Wenham", + githubUsername: "angelawenham@github", + }, + { fullName: "Pablo Rosado", githubUsername: "pabloarosado@github" }, + { + fullName: "Bastian Herre", + githubUsername: "bastianherre@github", }, - { fullName: "Max Roser", githubUsername: "Max" }, - { fullName: "Valerie Muigai", githubUsername: "ValRMuigai" }, + { fullName: "Valerie Muigai", githubUsername: "ValRMuigai@github" }, ] for (const { fullName, githubUsername } of updates) {