Skip to content

Commit

Permalink
[go] fix admin review normal user's redis cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfeng777 committed Jan 31, 2024
1 parent 18317bb commit 86932ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion go/service/task/task_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"gorm.io/gorm"

"github.com/nooncall/owls/go/model/common/request"
"github.com/nooncall/owls/go/service/tidb_or_mysql/admin"
"github.com/nooncall/owls/go/service/tidb_or_mysql/task"
)

Expand Down Expand Up @@ -44,7 +45,16 @@ func (taskDaoImpl) ListTask(info request.SortPageInfo, isDBA bool, status []task
db = db.Where("id like ? or name like ? or status like ? or creator like ?",
fmtKey, fmtKey, fmtKey, fmtKey)
}
db = db.Where("status in (?) and creator = ?", status, info.Operator)
db = db.Where("status in (?)", status)

// check admin
isAdmin, err := admin.IsAdmin(info.Operator)
if err != nil {
return nil, 0, err
}
if !isAdmin {
db.Where("creator = ?", info.Operator)
}

var count int64
if err := db.Model(&Task{}).Count(&count).Error; err != nil {
Expand Down
7 changes: 6 additions & 1 deletion go/service/tidb_or_mysql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package admin

import (
"fmt"
"github.com/nooncall/owls/go/service/tidb_or_mysql"
"time"

"github.com/nooncall/owls/go/service/tidb_or_mysql"

"gorm.io/gorm"
)

Expand Down Expand Up @@ -47,6 +48,10 @@ func DelAdmin(id int64) error {
}

func IsAdmin(username string) (bool, error) {
if username == "admin" {
return true, nil
}

_, err := adminDao.GetAdmin(username)
if gorm.ErrRecordNotFound == err {
return false, nil
Expand Down

0 comments on commit 86932ca

Please sign in to comment.