2023-09-29 10:21:32 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
object_pb "github.com/zitadel/zitadel/internal/api/grpc/object"
|
2024-02-28 10:55:54 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
2023-09-29 10:21:32 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-09-29 10:21:32 +02:00
|
|
|
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) SetInstanceFeature(ctx context.Context, req *system_pb.SetInstanceFeatureRequest) (*system_pb.SetInstanceFeatureResponse, error) {
|
|
|
|
details, err := s.setInstanceFeature(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &system_pb.SetInstanceFeatureResponse{
|
|
|
|
Details: object_pb.DomainToChangeDetailsPb(details),
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) setInstanceFeature(ctx context.Context, req *system_pb.SetInstanceFeatureRequest) (*domain.ObjectDetails, error) {
|
|
|
|
feat := domain.Feature(req.FeatureId)
|
2024-02-28 10:55:54 +02:00
|
|
|
if feat != domain.FeatureLoginDefaultOrg {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "SYST-SGV45", "Errors.Feature.NotExisting")
|
2023-09-29 10:21:32 +02:00
|
|
|
}
|
|
|
|
switch t := req.Value.(type) {
|
|
|
|
case *system_pb.SetInstanceFeatureRequest_Bool:
|
2024-02-28 10:55:54 +02:00
|
|
|
return s.command.SetInstanceFeatures(ctx, &command.InstanceFeatures{
|
|
|
|
LoginDefaultOrg: &t.Bool,
|
|
|
|
})
|
2023-09-29 10:21:32 +02:00
|
|
|
default:
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "SYST-dag5g", "Errors.Feature.TypeNotSupported")
|
2023-09-29 10:21:32 +02:00
|
|
|
}
|
|
|
|
}
|