Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
lelemm and coderabbitai[bot] authored Nov 11, 2024
1 parent d0b21ab commit b9cc5a5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/services/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,18 @@ export function getUserAccess(fileId, userId, isAdmin) {
}

export function countUserAccess(fileId, userId) {
const { countUserAccess } =
const { accessCount } =
getAccountDb().first(
`SELECT SUM(countUserAccess) as countUserAccess FROM
(
SELECT count(*) as countUserAccess
FROM user_access
WHERE user_access.user_id = ? and user_access.file_id = ?
UNION ALL
SELECT count(*) from files
WHERE files.id = ? and files.owner = ?
) as z
`,
[userId, fileId, fileId, userId],
`SELECT COUNT(*) as accessCount
FROM files
WHERE files.id = ? AND (files.owner = ? OR EXISTS (
SELECT 1 FROM user_access
WHERE user_access.user_id = ? AND user_access.file_id = ?)
)`,
[fileId, userId, userId, fileId],
) || {};

return countUserAccess || 0;
return accessCount || 0;
}

export function checkFilePermission(fileId, userId) {
Expand Down

0 comments on commit b9cc5a5

Please sign in to comment.