fix(backend/storage/postgres): fix FileGetAccess function
This commit is contained in:
parent
49952c62ef
commit
7384751d6b
@ -16,21 +16,15 @@ import (
|
|||||||
func FileGetAccess(user_id int, file_id string) (canView, canEdit bool, err error) {
|
func FileGetAccess(user_id int, file_id string) (canView, canEdit bool, err error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
row := connPool.QueryRow(ctx, `
|
row := connPool.QueryRow(ctx, `
|
||||||
WITH extras AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT creator_id FROM data.files WHERE id=$2)=$1 AS is_creator,
|
COALESCE(a.view, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE),
|
||||||
(SELECT is_admin FROM system.users WHERE id=$1) AS is_admin
|
COALESCE(a.edit, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE)
|
||||||
)
|
FROM data.files f
|
||||||
SELECT
|
LEFT JOIN acl.files a ON a.file_id=f.id AND a.user_id=$1
|
||||||
af.view OR (SELECT is_creator OR is_admin FROM extras),
|
LEFT JOIN system.users u ON u.id=$1
|
||||||
af.edit OR (SELECT is_creator OR is_admin FROM extras)
|
WHERE f.id=$2
|
||||||
FROM acl.files af
|
|
||||||
WHERE af.user_id=$1 AND af.file_id=$2
|
|
||||||
`, user_id, file_id)
|
`, user_id, file_id)
|
||||||
err = row.Scan(&canView, &canEdit)
|
err = row.Scan(&canView, &canEdit)
|
||||||
if err == pgx.ErrNoRows {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user