Skip to content

Commit 62a359f

Browse files
authored
[webapp] Drop "admin" role for "admin-user" (#16948)
* [db] Align IDs of "admin-user" (follow up for #15974) * [db] Drop "admin" role for "admin-user"
1 parent e01ca57 commit 62a359f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { BUILTIN_INSTLLATION_ADMIN_USER_ID } from "../../user-db";
9+
10+
const OLD_BUILTIN_INSTLLATION_ADMIN_USER_ID = "builtin-installation-admin-user-0000";
11+
12+
/**
13+
* Because we changed IDs of the "admin-user" in this PR (https://github.com/gitpod-io/gitpod/pull/15974/files) we have to make sure we're all aligned on that new id.
14+
*/
15+
export class AlignAdminUsers1679391121672 implements MigrationInterface {
16+
public async up(queryRunner: QueryRunner): Promise<void> {
17+
// Double add it to make sure every installation has one with the new ID
18+
await queryRunner.query(
19+
`INSERT IGNORE INTO d_b_user (id, creationDate, avatarUrl, name, fullName, rolesOrPermissions, blocked) VALUES ('${BUILTIN_INSTLLATION_ADMIN_USER_ID}', '${new Date().toISOString()}', '', 'admin-user', '', '["admin"]', TRUE)`,
20+
);
21+
// Drop the old user
22+
await queryRunner.query(`DELETE FROM d_b_user WHERE id = '${OLD_BUILTIN_INSTLLATION_ADMIN_USER_ID}'`);
23+
}
24+
25+
public async down(queryRunner: QueryRunner): Promise<void> {
26+
// Insert the old user again
27+
await queryRunner.query(
28+
`INSERT IGNORE INTO d_b_user (id, creationDate, avatarUrl, name, fullName, rolesOrPermissions, blocked) VALUES ('${OLD_BUILTIN_INSTLLATION_ADMIN_USER_ID}', '${new Date().toISOString()}', '', 'admin-user', '', '["admin"]', TRUE)`,
29+
);
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { BUILTIN_INSTLLATION_ADMIN_USER_ID } from "../../user-db";
9+
10+
export class AdminUserDropAdminRole1679410564277 implements MigrationInterface {
11+
public async up(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query(
13+
`UPDATE d_b_user SET rolesOrPermissions = '[]' WHERE id = '${BUILTIN_INSTLLATION_ADMIN_USER_ID}'`,
14+
);
15+
}
16+
17+
public async down(queryRunner: QueryRunner): Promise<void> {
18+
await queryRunner.query(
19+
`UPDATE d_b_user SET rolesOrPermissions = '["admin"]' WHERE id = '${BUILTIN_INSTLLATION_ADMIN_USER_ID}'`,
20+
);
21+
}
22+
}

0 commit comments

Comments
 (0)