mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
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:
parent
5983a8f819
commit
b58a05764b
@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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) {
|
||||
|
@ -55,7 +55,7 @@ export class PluginUserDataSyncServer extends Plugin {
|
||||
|
||||
this.app.acl.registerSnippet({
|
||||
name: `pm.${this.name}`,
|
||||
actions: ['userData:*', 'userDataSyncSources:*'],
|
||||
actions: ['userData:*', 'userDataSyncSources:*', 'userDataSyncTasks:*'],
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user