mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Remove DeleteUser from sqlstore * Use Delete instead of DeleteUser * Remove unused method * Remove DeleteUserSession from sqlstore * Add fake for DeleteUseraccessControl * Use user service, add fakes to tests * Add comments to sqlstore * Correct typo * Add quota service initialisation * Add config to acimpl initialisation * Add routing to initialisation * Making user provideStore private * Use InTransaction instead of session * Add cfg to userimpl * Fix lint * Make ProvideStore public again - enterprise tests * Fix back ProvideStore to public * Wrap merge user in transaction * Delete DeleteUserAccessControl use DeleteUSerPermissions instead * Add feature mgmt into acimpl * DeleteUserAccessControl from ac database * Remove case insensitive clause
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
// DO NOT ADD METHODS TO THIS FILES. SQLSTORE IS DEPRECATED AND WILL BE REMOVED.
|
|
package sqlstore
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/events"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
// MainOrgName is the name of the main organization.
|
|
const MainOrgName = "Main Org."
|
|
|
|
func verifyExistingOrg(sess *DBSession, orgId int64) error {
|
|
var org models.Org
|
|
has, err := sess.Where("id=?", orgId).Get(&org)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !has {
|
|
return models.ErrOrgNotFound
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, error) {
|
|
var org models.Org
|
|
if ss.Cfg.AutoAssignOrg {
|
|
has, err := sess.Where("id=?", ss.Cfg.AutoAssignOrgId).Get(&org)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if has {
|
|
return org.Id, nil
|
|
}
|
|
|
|
if ss.Cfg.AutoAssignOrgId != 1 {
|
|
ss.log.Error("Could not create user: organization ID does not exist", "orgID",
|
|
ss.Cfg.AutoAssignOrgId)
|
|
return 0, fmt.Errorf("could not create user: organization ID %d does not exist",
|
|
ss.Cfg.AutoAssignOrgId)
|
|
}
|
|
|
|
org.Name = MainOrgName
|
|
org.Id = int64(ss.Cfg.AutoAssignOrgId)
|
|
} else {
|
|
org.Name = orgName
|
|
}
|
|
|
|
org.Created = time.Now()
|
|
org.Updated = time.Now()
|
|
|
|
if org.Id != 0 {
|
|
if _, err := sess.InsertId(&org); err != nil {
|
|
return 0, err
|
|
}
|
|
} else {
|
|
if _, err := sess.InsertOne(&org); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
|
|
sess.publishAfterCommit(&events.OrgCreated{
|
|
Timestamp: org.Created,
|
|
Id: org.Id,
|
|
Name: org.Name,
|
|
})
|
|
|
|
return org.Id, nil
|
|
}
|