Skip to content

Commit

Permalink
Merge pull request #711 from desci-labs/fix/repo-share-policy
Browse files Browse the repository at this point in the history
Reduce log traces in repo service
  • Loading branch information
shadrach-tayo authored Dec 11, 2024
2 parents 0c4dc2f + 77ec2a6 commit 15b31d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
3 changes: 0 additions & 3 deletions desci-repo/src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ const config: RepoConfig = {
sharePolicy: async (peerId, documentId) => {
try {
if (!documentId) {
logger.trace({ peerId }, 'SharePolicy: Document ID NOT found');
return false;
}
// peer format: `peer-[user#id]:[unique string combination]
if (peerId.toString().length < 8) {
logger.error({ peerId }, 'SharePolicy: Peer ID invalid');
return false;
}

const userId = peerId.split(':')?.[0]?.split('-')?.[1];
const isAuthorised = await verifyNodeDocumentAccess(Number(userId), documentId);
logger.trace({ peerId, userId, documentId, isAuthorised }, '[SHARE POLICY CALLED]::');
return isAuthorised;
} catch (err) {
logger.error({ err }, 'Error in share policy');
Expand Down
9 changes: 2 additions & 7 deletions desci-repo/src/services/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ import { logger } from '../logger.js';

export const verifyNodeDocumentAccess = async (userId: number, documentId: DocumentId) => {
try {
logger.trace({ userId, documentId }, 'START [verifyNodeDocumentAccess]::Node');
const rows = await query('SELECT * FROM "Node" WHERE "manifestDocumentId" = $1 AND "ownerId" = $2', [
documentId,
userId,
]);
const node = rows?.[0];
logger.trace(
{ uuid: node.uuid, userId, ownerId: node.ownerId, documentId: node.manifestDocumentId },
'[verifyNodeDocumentAccess]::Node',
);

if (!node) return false;

if (node.manifestDocumentId === documentId && node.ownerId === userId) return true;
return false;
} catch (e) {
} catch (error) {
logger.error({ error }, 'VerifyNodeDocumentAccess');
return false;
}
};

0 comments on commit 15b31d1

Please sign in to comment.