working commit

This commit is contained in:
2026-02-13 16:28:05 +02:00
parent e72ffda8b1
commit 04cf117632
6 changed files with 387 additions and 11 deletions
+70 -8
View File
@@ -12,7 +12,13 @@ import (
func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject string) (bool, error) {
var err error
var res bool
hand.logg.Debugf("CheckRight %s: %s %s", accountID, right, subject)
hand.logg.Debugf("Cop check your right %s: %s %s", accountID, right, subject)
// =[]=
// /------\
// .---[-] [#] \--,
// >| [ ] [ ] |
// '--0-------0----'
// Bad news for you, baby.... #
res = true
return res, err
@@ -28,23 +34,23 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
hand.SendError(rctx, err)
return
}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, params.Username)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
if err != nil {
err := fmt.Errorf("CreateAccount error: %v", err)
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
if !opEnable {
err := fmt.Errorf("CreateAccount not enabled for this user")
err := fmt.Errorf("Operation not enabled for this account")
hand.SendError(rctx, err)
return
}
// Execution of the operation
res, err := hand.oper.CreateAccount(rctx.Ctx, operatorID, params)
if err != nil {
hand.logg.Errorf("CreateAccount error: %v", err)
hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
@@ -61,9 +67,23 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
hand.SendError(rctx, err)
return
}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
if err != nil {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
if !opEnable {
err := fmt.Errorf("Operation not enabled for this account")
hand.SendError(rctx, err)
return
}
// Execution of the operation
res, err := hand.oper.GetAccount(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("CreateAccount error: %v", err)
hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
@@ -80,6 +100,20 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
hand.SendError(rctx, err)
return
}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
if err != nil {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
if !opEnable {
err := fmt.Errorf("Operation not enabled for this account")
hand.SendError(rctx, err)
return
}
// Execution of the operation
res, err := hand.oper.ListAccounts(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("ListAccounts error: %v", err)
@@ -99,6 +133,20 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
hand.SendError(rctx, err)
return
}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
if err != nil {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
if !opEnable {
err := fmt.Errorf("Operation not enabled for this account")
hand.SendError(rctx, err)
return
}
// Execution of the operation
res, err := hand.oper.UpdateAccount(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("UpdateAccount error: %v", err)
@@ -118,6 +166,20 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
hand.SendError(rctx, err)
return
}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, params.Username)
if err != nil {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
return
}
if !opEnable {
err := fmt.Errorf("Operation not enabled for this account")
hand.SendError(rctx, err)
return
}
// Execution of the operation
res, err := hand.oper.DeleteAccount(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("DeleteAccount error: %v", err)