fix some foreign keys
This commit is contained in:
parent
7e56e0eec4
commit
eb5f66e4cd
23
src/migration/1663177839075-deletableclient.ts
Normal file
23
src/migration/1663177839075-deletableclient.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class deletableclient1663177839075 implements MigrationInterface {
|
||||||
|
name = 'deletableclient1663177839075';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_client_url\` DROP FOREIGN KEY \`FK_aca59c7bdd65987487eea98d00f\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_client_url\` ADD CONSTRAINT \`FK_aca59c7bdd65987487eea98d00f\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_client_url\` DROP FOREIGN KEY \`FK_aca59c7bdd65987487eea98d00f\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_client_url\` ADD CONSTRAINT \`FK_aca59c7bdd65987487eea98d00f\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
51
src/migration/1663178177421-cascades.ts
Normal file
51
src/migration/1663178177421-cascades.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class cascades1663178177421 implements MigrationInterface {
|
||||||
|
name = 'cascades1663178177421';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` DROP FOREIGN KEY \`FK_3ecb760b321ef9bbab635f05b45\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` ADD CONSTRAINT \`FK_3ecb760b321ef9bbab635f05b45\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` DROP FOREIGN KEY \`FK_81ffb9b8d672cf3af1af9e789f3\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` ADD CONSTRAINT \`FK_81ffb9b8d672cf3af1af9e789f3\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`user_token\` DROP FOREIGN KEY \`FK_d37db50eecdf9b8ce4eedd2f918\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`user_token\` ADD CONSTRAINT \`FK_d37db50eecdf9b8ce4eedd2f918\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`user_token\` DROP FOREIGN KEY \`FK_d37db50eecdf9b8ce4eedd2f918\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`user_token\` ADD CONSTRAINT \`FK_d37db50eecdf9b8ce4eedd2f918\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` DROP FOREIGN KEY \`FK_3ecb760b321ef9bbab635f05b45\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` ADD CONSTRAINT \`FK_3ecb760b321ef9bbab635f05b45\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` DROP FOREIGN KEY \`FK_81ffb9b8d672cf3af1af9e789f3\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`o_auth2_token\` ADD CONSTRAINT \`FK_81ffb9b8d672cf3af1af9e789f3\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -232,7 +232,7 @@ export class OAuth2AdminController {
|
|||||||
@Body() setter: Partial<OAuth2Client>,
|
@Body() setter: Partial<OAuth2Client>,
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), []);
|
const client = await this._oaClient.getById(parseInt(id, 10), ['owner']);
|
||||||
const reducedPermissions = !this._service.userHasPrivilege(
|
const reducedPermissions = !this._service.userHasPrivilege(
|
||||||
user,
|
user,
|
||||||
'admin:oauth2',
|
'admin:oauth2',
|
||||||
@ -301,7 +301,7 @@ export class OAuth2AdminController {
|
|||||||
@Scopes('management')
|
@Scopes('management')
|
||||||
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
||||||
async deleteOauth2Client(@Param('id') id: string, @CurrentUser() user: User) {
|
async deleteOauth2Client(@Param('id') id: string, @CurrentUser() user: User) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), []);
|
const client = await this._oaClient.getById(parseInt(id, 10), ['owner']);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ export class OAuth2AdminController {
|
|||||||
@Scopes('management')
|
@Scopes('management')
|
||||||
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
||||||
async createNewSecret(@Param('id') id: string, @CurrentUser() user: User) {
|
async createNewSecret(@Param('id') id: string, @CurrentUser() user: User) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), []);
|
const client = await this._oaClient.getById(parseInt(id, 10), ['owner']);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
@ -354,7 +354,7 @@ export class OAuth2AdminController {
|
|||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), []);
|
const client = await this._oaClient.getById(parseInt(id, 10), ['owner']);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
@ -374,7 +374,10 @@ export class OAuth2AdminController {
|
|||||||
@Scopes('management')
|
@Scopes('management')
|
||||||
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
@Privileges(['admin', 'admin:oauth2'], 'self:oauth2')
|
||||||
async oauth2ClientURLs(@Param('id') id: string, @CurrentUser() user: User) {
|
async oauth2ClientURLs(@Param('id') id: string, @CurrentUser() user: User) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['urls']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'urls',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
@ -396,7 +399,10 @@ export class OAuth2AdminController {
|
|||||||
@Param('url') urlId: string,
|
@Param('url') urlId: string,
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['urls']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'urls',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
const parsedURLId = parseInt(urlId, 10);
|
const parsedURLId = parseInt(urlId, 10);
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
@ -432,7 +438,10 @@ export class OAuth2AdminController {
|
|||||||
@Body() setter: { url: string; type: string },
|
@Body() setter: { url: string; type: string },
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['urls']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'urls',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
const plucked = this._form.pluckObject(setter, ['url', 'type']);
|
const plucked = this._form.pluckObject(setter, ['url', 'type']);
|
||||||
const parsedURLId = parseInt(urlId, 10);
|
const parsedURLId = parseInt(urlId, 10);
|
||||||
|
|
||||||
@ -472,7 +481,10 @@ export class OAuth2AdminController {
|
|||||||
@Body() setter: { url: string; type: string },
|
@Body() setter: { url: string; type: string },
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['urls']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'urls',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
@ -506,7 +518,10 @@ export class OAuth2AdminController {
|
|||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@UploadedFile() file: Express.Multer.File,
|
@UploadedFile() file: Express.Multer.File,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['picture']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'picture',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
@ -551,7 +566,10 @@ export class OAuth2AdminController {
|
|||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@CurrentUser() user: User,
|
@CurrentUser() user: User,
|
||||||
) {
|
) {
|
||||||
const client = await this._oaClient.getById(parseInt(id, 10), ['picture']);
|
const client = await this._oaClient.getById(parseInt(id, 10), [
|
||||||
|
'picture',
|
||||||
|
'owner',
|
||||||
|
]);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new NotFoundException('Client not found');
|
throw new NotFoundException('Client not found');
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ export class OAuth2ClientURL {
|
|||||||
})
|
})
|
||||||
public updated_at: Date;
|
public updated_at: Date;
|
||||||
|
|
||||||
@ManyToOne(() => OAuth2Client, (client) => client.urls)
|
@ManyToOne(() => OAuth2Client, (client) => client.urls, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
public client: OAuth2Client;
|
public client: OAuth2Client;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ export class OAuth2Token {
|
|||||||
@Column({ type: 'text', nullable: true })
|
@Column({ type: 'text', nullable: true })
|
||||||
scope: string;
|
scope: string;
|
||||||
|
|
||||||
@ManyToOne(() => User, { nullable: true })
|
@ManyToOne(() => User, { nullable: true, onDelete: 'CASCADE' })
|
||||||
user: User;
|
user: User;
|
||||||
|
|
||||||
@ManyToOne(() => OAuth2Client)
|
@ManyToOne(() => OAuth2Client, { onDelete: 'CASCADE' })
|
||||||
client: OAuth2Client;
|
client: OAuth2Client;
|
||||||
|
|
||||||
@Column({ type: 'timestamp' })
|
@Column({ type: 'timestamp' })
|
||||||
|
@ -39,6 +39,6 @@ export class UserToken {
|
|||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
public created_at: Date;
|
public created_at: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||||
user: User;
|
user: User;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user