MCPcopy
hub / github.com/daptin/daptin / IsAdminWithTransaction

Function IsAdminWithTransaction

server/resource/dbresource.go:456–495  ·  view source on GitHub ↗
(userReferenceId *auth.SessionUser, transaction *sqlx.Tx)

Source from the content-addressed store, hash-verified

454}
455
456func 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
497func (dbResource *DbResource) TableInfo() *table_info.TableInfo {
498 return dbResource.tableInfo

Callers 9

CreateConfigHandlerFunction · 0.92
InterceptAfterMethod · 0.85
InterceptBeforeMethod · 0.85
CreateWithoutFilterMethod · 0.85
UpdateWithoutFiltersMethod · 0.85
InterceptAfterMethod · 0.85
InterceptBeforeMethod · 0.85
HandleActionRequestMethod · 0.85

Calls 2

GetMethod · 0.65

Tested by

no test coverage detected