MCPcopy Create free account
hub / github.com/PostHog/duckgres / updateOrg

Method updateOrg

controlplane/admin/api.go:559–656  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

557 return nil, nil, err
558 }
559 return &prev, &stored, nil
560}
561
562func (s *gormAPIStore) ListUsers() ([]configstore.OrgUser, error) {
563 var users []configstore.OrgUser
564 if err := s.db().Find(&users).Error; err != nil {
565 return nil, err
566 }
567 return users, nil
568}
569
570func (s *gormAPIStore) CreateUser(user *configstore.OrgUser) error {
571 return s.db().Create(user).Error
572}
573
574func (s *gormAPIStore) GetUser(orgID, username string) (*configstore.OrgUser, error) {
575 var user configstore.OrgUser
576 if err := s.db().First(&user, "org_id = ? AND username = ?", orgID, username).Error; err != nil {
577 return nil, err
578 }
579 return &user, nil
580}
581
582func (s *gormAPIStore) UpdateUser(orgID, username, passwordHash string, passthrough *bool, maxVCPUs *int) (*configstore.OrgUser, bool, error) {
583 updates := map[string]interface{}{}
584 if passwordHash != "" {
585 updates["password"] = passwordHash
586 }
587 if passthrough != nil {
588 updates["passthrough"] = *passthrough
589 }
590 if maxVCPUs != nil {
591 updates["max_vcpus"] = *maxVCPUs
592 }
593 if len(updates) == 0 {
594 // Nothing to change — return the current row so callers can still
595 // distinguish "user not found" from "no-op update".
596 user, err := s.GetUser(orgID, username)
597 if err != nil {
598 if errors.Is(err, gorm.ErrRecordNotFound) {
599 return nil, false, nil
600 }
601 return nil, false, err
602 }
603 return user, true, nil
604 }
605 found := false
606 err := s.db().Transaction(func(tx *gorm.DB) error {
607 if err := configstore.LockOrgConnectionAdmissionTx(tx, orgID); err != nil {
608 return err
609 }
610
611 result := tx.Model(&configstore.OrgUser{}).
612 Where("org_id = ? AND username = ?", orgID, username).
613 Updates(updates)
614 if result.Error != nil {
615 return result.Error
616 }

Callers 1

useUpdateOrgFunction · 0.80

Calls 8

orgStrFunction · 0.85
orgStrPtrFunction · 0.85
orgInt64PtrFunction · 0.85
setAuditDetailFunction · 0.85
GetOrgMethod · 0.65
UpdateOrgMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected