Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error update price #126

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"type": "node"
}
]
}
}
9 changes: 5 additions & 4 deletions src/imports/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export async function find({

return acc;
}, {});

const startTime = process.hrtime();

tracingSpan?.addEvent('Executing find query', { query, queryOptions });
Expand Down Expand Up @@ -346,6 +346,7 @@ export async function find({
*
* @returns {Promise<import('../types/result').KonectyResult<object[]>>} - Konecty result
*/

export async function findById({ authTokenId, document, fields, dataId, withDetailFields, contextUser }) {
const { success, data: user, errors } = await getUserSafe(authTokenId, contextUser);
if (success === false) {
Expand Down Expand Up @@ -1697,8 +1698,8 @@ export async function update({ authTokenId, document, data, contextUser, tracing
}
}

const responseData = updatedRecords.map(record => removeUnauthorizedDataForRead(access, record)).map(record => dateToString(record));

const responseData = updatedRecords.map(record => removeUnauthorizedDataForRead(access, record, user, metaObject)).map(record => dateToString(record));
if (emailsToSend.length > 0) {
tracingSpan?.addEvent('Sending emails');

Expand Down Expand Up @@ -2681,4 +2682,4 @@ export async function historyFind({ authTokenId, document, dataId, fields, conte
});

return successReturn(resultData);
}
}
22 changes: 18 additions & 4 deletions src/imports/utils/accessUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import isObject from 'lodash/isObject';

import { Filter } from '@imports/model/Filter';
import { MetaAccess } from '@imports/model/MetaAccess';
import { MetaObject } from '@imports/model/MetaObject';
import { MetaObjectType } from '@imports/types/metadata';
import { User } from '@imports/model/User';
import { filterConditionToFn } from '@imports/data/filterUtils';

export function getFieldConditions(metaAccess: MetaAccess, fieldName: string) {
const accessField = metaAccess.fields?.[fieldName];
Expand Down Expand Up @@ -124,17 +125,30 @@ export function getAccessFor(documentName: string, user: User): MetaAccess | fal
return false;
}

export function removeUnauthorizedDataForRead(metaAccess: MetaAccess, data: Record<string, unknown>) {
export function removeUnauthorizedDataForRead(metaAccess: MetaAccess, data: Record<string, unknown>, user: User, metaObject: MetaObjectType) {
if (!isObject(data)) {
return data;
}
const newData: typeof data = {};

for (const fieldName in data) {
const access = getFieldPermissions(metaAccess, fieldName);
if (access.isReadable !== true) {
delete data[fieldName];
continue
}
const accessFieldConditions = getFieldConditions(metaAccess, fieldName);
if (accessFieldConditions.READ != null) {
const condition = filterConditionToFn(accessFieldConditions.READ, metaObject, { user });
if(condition.success === false) {
continue
}

if(condition.data(data) === false) {
continue
}
}
newData[fieldName] = data[fieldName];
}

return data;
return newData;
}
Loading