mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 15:22:47 +01:00
46 lines
983 B
Go
46 lines
983 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
|
|
"github.com/SecurityBrewery/catalyst/database/busdb"
|
|
"github.com/SecurityBrewery/catalyst/generated/model"
|
|
"github.com/SecurityBrewery/catalyst/role"
|
|
)
|
|
|
|
func (s *Service) GetSettings(ctx context.Context) (*model.Settings, error) {
|
|
user, ok := busdb.UserFromContext(ctx)
|
|
if !ok {
|
|
return nil, errors.New("no user in context")
|
|
}
|
|
|
|
setting, err := s.database.UserDataGet(ctx, user.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
settings := mergeSettings(s.settings, setting)
|
|
|
|
ticketTypeList, err := s.database.TicketTypeList(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
settings.TicketTypes = ticketTypeList
|
|
|
|
return settings, nil
|
|
}
|
|
|
|
func mergeSettings(globalSettings *model.Settings, user *model.UserDataResponse) *model.Settings {
|
|
if user.Timeformat != nil {
|
|
globalSettings.Timeformat = *user.Timeformat
|
|
}
|
|
roles := role.Strings(role.List())
|
|
sort.Strings(roles)
|
|
globalSettings.Roles = roles
|
|
|
|
return globalSettings
|
|
}
|