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) {
|
||||
ctx := context.Background()
|
||||
row := connPool.QueryRow(ctx, `
|
||||
WITH extras AS (
|
||||
SELECT
|
||||
(SELECT creator_id FROM data.files WHERE id=$2)=$1 AS is_creator,
|
||||
(SELECT is_admin FROM system.users WHERE id=$1) AS is_admin
|
||||
)
|
||||
SELECT
|
||||
af.view OR (SELECT is_creator OR is_admin FROM extras),
|
||||
af.edit OR (SELECT is_creator OR is_admin FROM extras)
|
||||
FROM acl.files af
|
||||
WHERE af.user_id=$1 AND af.file_id=$2
|
||||
SELECT
|
||||
COALESCE(a.view, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE),
|
||||
COALESCE(a.edit, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE)
|
||||
FROM data.files f
|
||||
LEFT JOIN acl.files a ON a.file_id=f.id AND a.user_id=$1
|
||||
LEFT JOIN system.users u ON u.id=$1
|
||||
WHERE f.id=$2
|
||||
`, user_id, file_id)
|
||||
err = row.Scan(&canView, &canEdit)
|
||||
if err == pgx.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user