feat(backend/db): add function to get user's rights to a file
This commit is contained in:
parent
35d41a46c0
commit
057ba22b18
@ -12,6 +12,28 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// Check if user can view file
|
||||
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
|
||||
`, user_id, file_id)
|
||||
err = row.Scan(&canView, &canEdit)
|
||||
if err == pgx.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get a set of files
|
||||
func FileGetSlice(user_id int, filter, sort string, limit, offset int) (files models.Slice[models.FileItem], statusCode int, err error) {
|
||||
filterCond, statusCode, err := filterToSQL(filter)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user