working commit
This commit is contained in:
@@ -19,7 +19,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) UpdateAccountByID(ctx context.Context, accountID uint64, account *descr.Account) error {
|
||||
func (db *Database) UpdateAccountByID(ctx context.Context, accountID string, account *descr.Account) error {
|
||||
var err error
|
||||
request := `UPDATE accounts SET username = $1, passhash = $2, disabled = $3, updated_at = $4, updated_by = $5 WHERE id = $6`
|
||||
_, err = db.db.Exec(request, account.Username, account.Passhash, account.Disabled, account.UpdatedAt, account.UpdatedBy, accountID)
|
||||
@@ -51,7 +51,7 @@ func (db *Database) ListAccounts(ctx context.Context) ([]descr.Account, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetAccountByID(ctx context.Context, accountID uint64) (bool, *descr.Account, error) {
|
||||
func (db *Database) GetAccountByID(ctx context.Context, accountID string) (bool, *descr.Account, error) {
|
||||
var err error
|
||||
var res *descr.Account
|
||||
var exists bool = false
|
||||
@@ -90,7 +90,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
|
||||
return exists, res, err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteAccountByID(ctx context.Context, accountID uint64) error {
|
||||
func (db *Database) DeleteAccountByID(ctx context.Context, accountID string) error {
|
||||
var err error
|
||||
|
||||
request := `DELETE FROM accounts WHERE id = $1`
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) UpdateFileByID(ctx context.Context, fileID uint64, file *descr.File) error {
|
||||
func (db *Database) UpdateFileByID(ctx context.Context, fileID string, file *descr.File) error {
|
||||
var err error
|
||||
request := `UPDATE files SET id = $1, collection = $2, name = $3, type = $4, checksum = $5,
|
||||
size = $6, updated_at = $7, created_by = $8, updated_by = $9
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"time"
|
||||
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/auxid"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
+10
-11
@@ -13,7 +13,6 @@ import (
|
||||
"context"
|
||||
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/term"
|
||||
)
|
||||
|
||||
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
|
||||
@@ -28,7 +27,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) UpdateGrantByID(ctx context.Context, grantID uint64, grant *descr.Grant) error {
|
||||
func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *descr.Grant) error {
|
||||
var err error
|
||||
request := `UPDATE grants SET pattern = $1, updated_at = $2, updated_by = $3 WHERE id = $4`
|
||||
_, err = db.db.Exec(request, grant.Pattern, grant.UpdatedAt, grant.UpdatedBy, grantID)
|
||||
@@ -38,7 +37,7 @@ func (db *Database) UpdateGrantByID(ctx context.Context, grantID uint64, grant *
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID uint64) ([]descr.Grant, error) {
|
||||
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID string) ([]descr.Grant, error) {
|
||||
var err error
|
||||
request := `SELECT * FROM grants WHERE account_id = $1`
|
||||
res := make([]descr.Grant, 0)
|
||||
@@ -60,12 +59,12 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetGrantByID(ctx context.Context, id uint64) (bool, *descr.Grant, error) {
|
||||
func (db *Database) GetGrantByID(ctx context.Context, garntID string) (bool, *descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
request := `SELECT * FROM grants WHERE id = $1 LIMIT 1`
|
||||
dbRes := make([]descr.Grant, 0)
|
||||
err = db.db.Select(&dbRes, request, id)
|
||||
err = db.db.Select(&dbRes, request, garntID)
|
||||
if err != nil {
|
||||
return false, res, err
|
||||
}
|
||||
@@ -77,7 +76,7 @@ func (db *Database) GetGrantByID(ctx context.Context, id uint64) (bool, *descr.G
|
||||
return true, res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID uint64, right term.Right) (bool, *descr.Grant, error) {
|
||||
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID, right string) (bool, *descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 LIMIT 1`
|
||||
@@ -94,7 +93,7 @@ func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID uint
|
||||
return true, res, err
|
||||
}
|
||||
|
||||
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID uint64, right term.Right) (bool, []descr.Grant, error) {
|
||||
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, right string) (bool, []descr.Grant, error) {
|
||||
var err error
|
||||
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2`
|
||||
res := make([]descr.Grant, 0)
|
||||
@@ -108,7 +107,7 @@ func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID ui
|
||||
return true, res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID uint64, right term.Right, pattern string) (bool, *descr.Grant, error) {
|
||||
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID, right, pattern string) (bool, *descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3 LIMIT 1`
|
||||
@@ -125,7 +124,7 @@ func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, account
|
||||
return true, res, err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID uint64, right, pattern string) error {
|
||||
func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID, right, pattern string) error {
|
||||
var err error
|
||||
request := `DELETE FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3`
|
||||
_, err = db.db.Exec(request, accountID, right, pattern)
|
||||
@@ -135,7 +134,7 @@ func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, acco
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteGrantByID(ctx context.Context, grantID uint64) error {
|
||||
func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
|
||||
var err error
|
||||
request := `DELETE FROM grants WHERE id = $1`
|
||||
_, err = db.db.Exec(request, grantID)
|
||||
@@ -145,7 +144,7 @@ func (db *Database) DeleteGrantByID(ctx context.Context, grantID uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID uint64) error {
|
||||
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID string) error {
|
||||
var err error
|
||||
request := `DELETE FROM grants WHERE account_id = $1`
|
||||
_, err = db.db.Exec(request, grantID)
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
"time"
|
||||
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/auxid"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
+9
-9
@@ -15,9 +15,9 @@ import (
|
||||
|
||||
"mstore/pkg/auxpwd"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/term"
|
||||
"mstore/pkg/auxid"
|
||||
)
|
||||
|
||||
func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
@@ -41,7 +41,7 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightReadFiles,
|
||||
Pattern: ".*",
|
||||
@@ -55,7 +55,7 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightReadImages,
|
||||
Pattern: ".*",
|
||||
@@ -93,7 +93,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
}
|
||||
// Files
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightReadFiles,
|
||||
Pattern: ".*",
|
||||
@@ -107,7 +107,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightWriteFiles,
|
||||
Pattern: ".*",
|
||||
@@ -122,7 +122,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
}
|
||||
// Accounts
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightReadAccounts,
|
||||
Pattern: ".*",
|
||||
@@ -136,7 +136,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightWriteAccounts,
|
||||
Pattern: ".*",
|
||||
@@ -151,7 +151,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
}
|
||||
// Images
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightReadImages,
|
||||
Pattern: ".*",
|
||||
@@ -165,7 +165,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxid.NewID(),
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: term.RightWriteImages,
|
||||
Pattern: ".*",
|
||||
|
||||
Reference in New Issue
Block a user