fix(user-data-sync): skip unsupported data types during synchronization instead of throwing an error (#5835)

* fix: support sync user when departments plugin disabled

* chore: delete submodule

* fix: support sync user when departments plugin disabled

* chore: add test case

* fix: fix synctasks list acl
This commit is contained in:
Zhi Chen 2024-12-10 12:02:19 +08:00 committed by GitHub
parent 5983a8f819
commit b58a05764b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 6 deletions

View File

@ -51,4 +51,23 @@ describe('api', async () => {
nickname: 'test',
});
});
it('push data with unsupported type', async () => {
const res = await agent.resource('userData').push({
values: {
dataType: 'unsupported',
records: [
{
uid: '1',
nickname: 'test',
},
],
},
});
expect(res.status).toBe(500);
expect(res.body.data).toMatchObject({
code: 500,
message: 'dataType unsupported is not supported',
});
});
});

View File

@ -26,6 +26,15 @@ export default {
const data = ctx.action.params.values || {};
const plugin = ctx.app.pm.get(PluginUserDataSyncServer) as PluginUserDataSyncServer;
try {
let supported = false;
for (const resource of plugin.resourceManager.resources.nodes) {
if (resource.accepts.includes(data.dataType)) {
supported = true;
}
}
if (!supported) {
throw new Error(`dataType ${data.dataType} is not supported`);
}
const result = await plugin.syncService.push(data);
ctx.body = { code: 0, message: 'success', result };
} catch (error) {

View File

@ -55,7 +55,7 @@ export class PluginUserDataSyncServer extends Plugin {
this.app.acl.registerSnippet({
name: `pm.${this.name}`,
actions: ['userData:*', 'userDataSyncSources:*'],
actions: ['userData:*', 'userDataSyncSources:*', 'userDataSyncTasks:*'],
});
}

View File

@ -194,14 +194,12 @@ export class UserDataResourceManager {
await this.saveOriginRecords(data);
const { dataType, sourceName, records, matchKey } = data;
const sourceUks = records.map((record) => record.uid);
let processed = false;
const syncResults: SyncResult[] = [];
for (const resource of this.resources.nodes) {
if (!resource.accepts.includes(dataType)) {
continue;
}
const associateResource = resource.name;
processed = true;
const originRecords = await this.findOriginRecords({ sourceName, sourceUks, dataType });
if (!(originRecords && originRecords.length)) {
continue;
@ -266,9 +264,6 @@ export class UserDataResourceManager {
},
});
}
if (!processed) {
throw new Error(`dataType "${dataType}" is not support`);
}
return syncResults;
}
}