(userReferenceId *auth.SessionUser, transaction *sqlx.Tx)
| 454 | } |
| 455 | |
| 456 | func IsAdminWithTransaction(userReferenceId *auth.SessionUser, transaction *sqlx.Tx) bool { |
| 457 | if userReferenceId == nil { |
| 458 | return false |
| 459 | } |
| 460 | userUUid, _ := uuid.FromBytes(userReferenceId.UserReferenceId[:]) |
| 461 | key := "admin." + string(userReferenceId.UserReferenceId[:]) |
| 462 | adminGroupId := CRUD_MAP[USER_ACCOUNT_TABLE_NAME].AdministratorGroupId |
| 463 | for _, ugid := range userReferenceId.Groups { |
| 464 | if ugid.GroupReferenceId == adminGroupId { |
| 465 | return true |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | if OlricCache != nil { |
| 470 | //fmt.Println("IsAdminWithTransaction [" + key + "]") |
| 471 | value, err := OlricCache.Get(context.Background(), key) |
| 472 | if err == nil && value != nil { |
| 473 | if val, err := value.Bool(); val && err == nil { |
| 474 | return true |
| 475 | } else { |
| 476 | return false |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | admins := GetAdminReferenceIdWithTransaction(transaction) |
| 481 | _, ok := admins[userUUid] |
| 482 | if ok { |
| 483 | if OlricCache != nil { |
| 484 | OlricCache.Put(context.Background(), key, true, olric.EX(2*time.Minute), olric.NX()) |
| 485 | //CheckErr(err, "[320] Failed to set admin id value in olric cache") |
| 486 | } |
| 487 | return true |
| 488 | } |
| 489 | if OlricCache != nil { |
| 490 | OlricCache.Put(context.Background(), key, false, olric.EX(2*time.Minute), olric.NX()) |
| 491 | } |
| 492 | //CheckErr(err, "[327] Failed to set admin id value in olric cache") |
| 493 | return false |
| 494 | |
| 495 | } |
| 496 | |
| 497 | func (dbResource *DbResource) TableInfo() *table_info.TableInfo { |
| 498 | return dbResource.tableInfo |
no test coverage detected