mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-04-25 15:41:36 -05:00
feat(account): Add device linking data to GetUserData(pid)
This API will be useful for Juxt and other services that want to use device linking for moderation purposes. The data is pretty minimalist to start with to limit exposure. Requires https://github.com/PretendoNetwork/grpc/pull/3
This commit is contained in:
parent
204b3aecba
commit
84922a5c51
|
|
@ -2,6 +2,7 @@ import { Status, ServerError } from 'nice-grpc';
|
|||
import { getPNIDByTokenAuth } from '@/database';
|
||||
import { PNID_PERMISSION_FLAGS } from '@/types/common/permission-flags';
|
||||
import { config } from '@/config-manager';
|
||||
import { Device } from '@/models/device';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import type { ExchangeTokenForUserDataRequest } from '@pretendonetwork/grpc/account/exchange_token_for_user_data';
|
||||
|
||||
|
|
@ -16,6 +17,18 @@ export async function exchangeTokenForUserData(request: ExchangeTokenForUserData
|
|||
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token');
|
||||
}
|
||||
|
||||
const devices = (await Device.find({
|
||||
linked_pids: pnid.pid
|
||||
})).map((device) => {
|
||||
return {
|
||||
model: device.get('model'), // ".model" gives the Mongoose model...
|
||||
serial: device.serial,
|
||||
linkedPids: device.linked_pids,
|
||||
accessLevel: device.access_level,
|
||||
serverAccessLevel: device.server_access_level
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
deleted: pnid.deleted,
|
||||
pid: pnid.pid,
|
||||
|
|
@ -57,6 +70,7 @@ export async function exchangeTokenForUserData(request: ExchangeTokenForUserData
|
|||
updateBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_FILES),
|
||||
deleteBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_FILES),
|
||||
updatePnidPermissions: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_PNID_PERMISSIONS)
|
||||
}
|
||||
},
|
||||
devices
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Status, ServerError } from 'nice-grpc';
|
|||
import { getPNIDByPID } from '@/database';
|
||||
import { PNID_PERMISSION_FLAGS } from '@/types/common/permission-flags';
|
||||
import { config } from '@/config-manager';
|
||||
import { Device } from '@/models/device';
|
||||
import type { GetUserDataRequest, GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
|
||||
export async function getUserData(request: GetUserDataRequest): Promise<GetUserDataResponse> {
|
||||
|
|
@ -14,6 +15,18 @@ export async function getUserData(request: GetUserDataRequest): Promise<GetUserD
|
|||
);
|
||||
}
|
||||
|
||||
const devices = (await Device.find({
|
||||
linked_pids: pnid.pid
|
||||
})).map((device) => {
|
||||
return {
|
||||
model: device.get('model'), // ".model" gives the Mongoose model...
|
||||
serial: device.serial,
|
||||
linkedPids: device.linked_pids,
|
||||
accessLevel: device.access_level,
|
||||
serverAccessLevel: device.server_access_level
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
deleted: pnid.deleted,
|
||||
pid: pnid.pid,
|
||||
|
|
@ -55,6 +68,7 @@ export async function getUserData(request: GetUserDataRequest): Promise<GetUserD
|
|||
updateBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_FILES),
|
||||
deleteBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_FILES),
|
||||
updatePnidPermissions: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_PNID_PERMISSIONS)
|
||||
}
|
||||
},
|
||||
devices
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user