working commit
This commit is contained in:
+29
-29
@@ -11,14 +11,14 @@ import (
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
|
||||
func (lg *Logic) ValidateAccount(ctx context.Context, username, password string) (bool, string, error) {
|
||||
func (oper *Operator) ValidateAccount(ctx context.Context, username, password string) (bool, string, error) {
|
||||
var err error
|
||||
var accountID string
|
||||
var valid bool
|
||||
|
||||
lg.WaitRestoring()
|
||||
oper.WaitRestoring()
|
||||
|
||||
accountExists, accountDescr, err := lg.db.GetAccountByUsername(ctx, username)
|
||||
accountExists, accountDescr, err := oper.db.GetAccountByUsername(ctx, username)
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account not exists")
|
||||
return valid, accountID, err
|
||||
@@ -32,14 +32,14 @@ func (lg *Logic) ValidateAccount(ctx context.Context, username, password string)
|
||||
return valid, accountID, err
|
||||
}
|
||||
|
||||
func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, accountID string, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.CreateAccountResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
accountExists, _, err := lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, _, err := oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
err = lg.db.InsertAccount(ctx, accountDescr)
|
||||
err = oper.db.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -83,14 +83,14 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
|
||||
func (oper *Operator) UpdateAccount(ctx context.Context, accountID string, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.UpdateAccountResult{}
|
||||
|
||||
lg.WaitRestoring()
|
||||
lg.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -103,12 +103,12 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mb
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -133,21 +133,21 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mb
|
||||
accountDescr.Disabled = params.Disabled
|
||||
}
|
||||
|
||||
err = lg.db.UpdateAccountByID(ctx, accountDescr.ID, accountDescr)
|
||||
err = oper.db.UpdateAccountByID(ctx, accountDescr.ID, accountDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
|
||||
func (oper *Operator) DeleteAccount(ctx context.Context, accountID string, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.DeleteAccountResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -160,12 +160,12 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mb
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -175,26 +175,26 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = lg.db.DeleteAllGrantsForAccountID(ctx, accountDescr.ID)
|
||||
err = oper.db.DeleteAllGrantsForAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = lg.db.DeleteAccountByID(ctx, accountDescr.ID)
|
||||
err = oper.db.DeleteAccountByID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
|
||||
func (oper *Operator) ListAccounts(ctx context.Context, accountID string, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
|
||||
var err error
|
||||
res := &mbctl.ListAccountsResult{
|
||||
Accounts: make([]*mbctl.AccountShortDescr, 0),
|
||||
}
|
||||
|
||||
lg.WaitRestoring()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbc
|
||||
return res, err
|
||||
}
|
||||
|
||||
accountDescrs, err := lg.db.ReducedListAccounts(ctx)
|
||||
accountDescrs, err := oper.db.ReducedListAccounts(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbc
|
||||
UpdatedAt: accountDescr.UpdatedAt,
|
||||
Grants: make([]*mbctl.GrantShortDescr, 0),
|
||||
}
|
||||
grantDescrs, err := lg.db.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
grantDescrs, err := oper.db.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user