working commit
This commit is contained in:
+14
-14
@@ -10,13 +10,13 @@ import (
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
|
||||
func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
|
||||
func (oper *Operator) SetGrant(ctx context.Context, accountID string, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
|
||||
var err error
|
||||
res := &mbctl.SetGrantResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
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
|
||||
}
|
||||
@@ -45,12 +45,12 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
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
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
return res, err
|
||||
}
|
||||
|
||||
grantExists, _, err = lg.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
grantExists, _, err = oper.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -75,20 +75,20 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
CreatedAt: now,
|
||||
Operation: params.Operation,
|
||||
}
|
||||
err = lg.db.InsertGrant(ctx, grantDescr)
|
||||
err = oper.db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
|
||||
func (oper *Operator) DeleteGrant(ctx context.Context, accountID string, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
|
||||
var err error
|
||||
res := &mbctl.DeleteGrantResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
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
|
||||
}
|
||||
@@ -117,12 +117,12 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
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
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
return res, err
|
||||
}
|
||||
|
||||
grantExists, _, err = lg.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
grantExists, _, err = oper.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
err := fmt.Errorf("Requested grant for the user not found")
|
||||
return res, err
|
||||
}
|
||||
err = lg.db.DeleteGrantByAccountID(ctx, accountDescr.ID, params.Operation)
|
||||
err = oper.db.DeleteGrantByAccountID(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user