working commit
This commit is contained in:
+27
-1
@@ -13,6 +13,7 @@ import (
|
||||
// CreateGrant
|
||||
type CreateGrantParams struct {
|
||||
AccountID string `json:"accountID"`
|
||||
Username string `json:"username"`
|
||||
Right string `json:"operation"`
|
||||
Pattern string `json:"pattern"`
|
||||
}
|
||||
@@ -43,6 +44,31 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||
return res, err
|
||||
}
|
||||
default:
|
||||
err := fmt.Errorf("Empty username and accountId parameter")
|
||||
return res, err
|
||||
}
|
||||
grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -55,7 +81,7 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
|
||||
now := auxtool.TimeNow()
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: params.AccountID,
|
||||
AccountID: accountDescr.ID,
|
||||
Right: params.Right,
|
||||
Pattern: params.Pattern,
|
||||
CreatedAt: now,
|
||||
|
||||
Reference in New Issue
Block a user