mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Remove user from preferences, stars, orguser, team member * Fix lint * Add Delete user from org and dashboard acl * Delete user from user auth * Add DeleteUser to quota * Add test files and adjust user auth store * Rename package in wire for user auth * Import Quota Service interface in other services * do the same in tests * fix lint tests * Fix tests * Add some tests * Rename InsertUser and DeleteUser to InsertOrgUser and DeleteOrgUser * Rename DeleteUser to DeleteByUser in quota * changing a method name in few additional places * Fix in other places * Fix lint * Fix tests * Rename DeleteOrgUser to DeleteUserFromAll * Update pkg/services/org/orgimpl/org_test.go Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> * Update pkg/services/preference/prefimpl/inmemory_test.go Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> * Rename Acl to ACL * Fix wire after merge with main * Move test to uni test Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package orgimpl
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
type Service struct {
|
|
store store
|
|
cfg *setting.Cfg
|
|
log log.Logger
|
|
}
|
|
|
|
func ProvideService(db db.DB, cfg *setting.Cfg) org.Service {
|
|
return &Service{
|
|
store: &sqlStore{
|
|
db: db,
|
|
dialect: db.GetDialect(),
|
|
},
|
|
cfg: cfg,
|
|
log: log.New("org service"),
|
|
}
|
|
}
|
|
|
|
func (s *Service) GetIDForNewUser(ctx context.Context, cmd org.GetOrgIDForNewUserCommand) (int64, error) {
|
|
var orga org.Org
|
|
if cmd.SkipOrgSetup {
|
|
return -1, nil
|
|
}
|
|
|
|
if setting.AutoAssignOrg && cmd.OrgID != 0 {
|
|
_, err := s.store.Get(ctx, cmd.OrgID)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
return cmd.OrgID, nil
|
|
}
|
|
|
|
orgName := cmd.OrgName
|
|
if len(orgName) == 0 {
|
|
orgName = util.StringsFallback2(cmd.Email, cmd.Login)
|
|
}
|
|
|
|
if setting.AutoAssignOrg {
|
|
orga, err := s.store.Get(ctx, int64(s.cfg.AutoAssignOrgId))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if orga.ID != 0 {
|
|
return orga.ID, nil
|
|
}
|
|
if setting.AutoAssignOrgId != 1 {
|
|
s.log.Error("Could not create user: organization ID does not exist", "orgID",
|
|
setting.AutoAssignOrgId)
|
|
return 0, fmt.Errorf("could not create user: organization ID %d does not exist",
|
|
setting.AutoAssignOrgId)
|
|
}
|
|
orga.Name = MainOrgName
|
|
orga.ID = int64(setting.AutoAssignOrgId)
|
|
} else {
|
|
orga.Name = orgName
|
|
}
|
|
orga.Created = time.Now()
|
|
orga.Updated = time.Now()
|
|
|
|
return s.store.Insert(ctx, &orga)
|
|
}
|
|
|
|
func (s *Service) InsertOrgUser(ctx context.Context, orguser *org.OrgUser) (int64, error) {
|
|
return s.store.InsertOrgUser(ctx, orguser)
|
|
}
|
|
|
|
func (s *Service) DeleteUserFromAll(ctx context.Context, userID int64) error {
|
|
return s.store.DeleteUserFromAll(ctx, userID)
|
|
}
|