2021-07-13 05:13:39 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2022-05-03 13:58:38 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
2023-12-05 11:12:01 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/i18n"
|
2022-04-26 23:01:45 +00:00
|
|
|
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
2021-07-13 05:13:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) GetSupportedLanguages(ctx context.Context, req *admin_pb.GetSupportedLanguagesRequest) (*admin_pb.GetSupportedLanguagesResponse, error) {
|
2023-12-05 11:12:01 +00:00
|
|
|
return &admin_pb.GetSupportedLanguagesResponse{Languages: domain.LanguagesToStrings(i18n.SupportedLanguages())}, nil
|
2021-07-13 05:13:39 +00:00
|
|
|
}
|
2022-02-16 15:49:17 +00:00
|
|
|
|
|
|
|
func (s *Server) SetDefaultLanguage(ctx context.Context, req *admin_pb.SetDefaultLanguageRequest) (*admin_pb.SetDefaultLanguageResponse, error) {
|
2023-12-05 11:12:01 +00:00
|
|
|
lang, err := domain.ParseLanguage(req.Language)
|
2022-02-16 15:49:17 +00:00
|
|
|
if err != nil {
|
2023-12-05 11:12:01 +00:00
|
|
|
return nil, err
|
2022-02-16 15:49:17 +00:00
|
|
|
}
|
2023-12-05 11:12:01 +00:00
|
|
|
details, err := s.command.SetDefaultLanguage(ctx, lang[0])
|
2022-05-03 13:58:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &admin_pb.SetDefaultLanguageResponse{
|
|
|
|
Details: object.DomainToChangeDetailsPb(details),
|
|
|
|
}, nil
|
2022-02-16 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 09:16:36 +00:00
|
|
|
func (s *Server) GetDefaultLanguage(ctx context.Context, _ *admin_pb.GetDefaultLanguageRequest) (*admin_pb.GetDefaultLanguageResponse, error) {
|
|
|
|
return &admin_pb.GetDefaultLanguageResponse{Language: authz.GetInstance(ctx).DefaultLanguage().String()}, nil
|
2022-02-16 15:49:17 +00:00
|
|
|
}
|
2023-12-07 08:43:23 +00:00
|
|
|
|
|
|
|
func (s *Server) GetAllowedLanguages(ctx context.Context, _ *admin_pb.GetAllowedLanguagesRequest) (*admin_pb.GetAllowedLanguagesResponse, error) {
|
|
|
|
restrictions, err := s.query.GetInstanceRestrictions(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
allowed := restrictions.AllowedLanguages
|
|
|
|
if len(allowed) == 0 {
|
|
|
|
allowed = i18n.SupportedLanguages()
|
|
|
|
}
|
|
|
|
return &admin_pb.GetAllowedLanguagesResponse{Languages: domain.LanguagesToStrings(allowed)}, nil
|
|
|
|
}
|