add notifications for shared access granted/revoked/login
This commit is contained in:
parent
2a13e97863
commit
35a167701f
10 changed files with 260 additions and 12 deletions
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { AccessTokensRepository } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { NotificationService } from '@/core/NotificationService.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
|
@ -37,29 +38,37 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.accessTokensRepository)
|
||||
private accessTokensRepository: AccessTokensRepository,
|
||||
|
||||
private readonly notificationService: NotificationService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
if (ps.tokenId) {
|
||||
const tokenExist = await this.accessTokensRepository.exists({ where: { id: ps.tokenId } });
|
||||
const tokenExist = await this.accessTokensRepository.findOne({ where: { id: ps.tokenId } });
|
||||
|
||||
if (tokenExist) {
|
||||
for (const granteeId of tokenExist.granteeIds) {
|
||||
this.notificationService.createNotification(granteeId, 'sharedAccessRevoked', {}, me.id);
|
||||
}
|
||||
|
||||
await this.accessTokensRepository.delete({
|
||||
id: ps.tokenId,
|
||||
userId: me.id,
|
||||
});
|
||||
}
|
||||
} else if (ps.token) {
|
||||
const tokenExist = await this.accessTokensRepository.exists({ where: { token: ps.token } });
|
||||
const tokenExist = await this.accessTokensRepository.findOne({ where: { token: ps.token } });
|
||||
|
||||
if (tokenExist) {
|
||||
for (const granteeId of tokenExist.granteeIds) {
|
||||
this.notificationService.createNotification(granteeId, 'sharedAccessRevoked', {}, me.id);
|
||||
}
|
||||
|
||||
await this.accessTokensRepository.delete({
|
||||
token: ps.token,
|
||||
userId: me.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// TODO notify of access revoked
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import type { AccessTokensRepository } from '@/models/_.js';
|
||||
import { ApiError } from '@/server/api/error.js';
|
||||
import { NotificationService } from '@/core/NotificationService.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
|
@ -57,6 +58,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.accessTokensRepository)
|
||||
private readonly accessTokensRepository: AccessTokensRepository,
|
||||
|
||||
private readonly notificationService: NotificationService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const token = await this.accessTokensRepository.findOneBy({ id: ps.grantId });
|
||||
|
|
@ -69,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.noSuchAccess);
|
||||
}
|
||||
|
||||
// TODO notify of login
|
||||
this.notificationService.createNotification(token.userId, 'sharedAccessLogin', {}, me.id);
|
||||
|
||||
return {
|
||||
token: token.token,
|
||||
|
|
|
|||
|
|
@ -117,7 +117,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
granteeIds: ps.grantees,
|
||||
});
|
||||
|
||||
// TODO notify of access granted
|
||||
if (ps.grantees) {
|
||||
for (const granteeId of ps.grantees) {
|
||||
this.notificationService.createNotification(granteeId, 'sharedAccessGranted', { tokenId: accessTokenId }, me.id);
|
||||
}
|
||||
}
|
||||
|
||||
// アクセストークンが生成されたことを通知
|
||||
this.notificationService.createNotification(me.id, 'createToken', {});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue