IsFeatureEnabledForInstance returns whether a feature is enabled for the instance.
(ctx context.Context, workspaceID string, f v1pb.PlanFeature, instance *store.InstanceMessage)
| 299 | |
| 300 | // IsFeatureEnabledForInstance returns whether a feature is enabled for the instance. |
| 301 | func (s *LicenseService) IsFeatureEnabledForInstance(ctx context.Context, workspaceID string, f v1pb.PlanFeature, instance *store.InstanceMessage) error { |
| 302 | plan := s.GetEffectivePlan(ctx, workspaceID) |
| 303 | // DO NOT check instance license fo FREE plan. |
| 304 | if plan == v1pb.PlanType_FREE { |
| 305 | return s.IsFeatureEnabled(ctx, workspaceID, f) |
| 306 | } |
| 307 | if err := s.IsFeatureEnabled(ctx, workspaceID, f); err != nil { |
| 308 | return err |
| 309 | } |
| 310 | if !s.IsInstanceEffectivelyActivated(ctx, workspaceID, instance) { |
| 311 | instanceID := "" |
| 312 | if instance != nil { |
| 313 | instanceID = instance.ResourceID |
| 314 | } |
| 315 | return errors.Errorf(`feature "%s" requires an activated instance under the current license: %s`, f.String(), instanceID) |
| 316 | } |
| 317 | return nil |
| 318 | } |
| 319 | |
| 320 | // GetUserLimit gets the user limit value for the plan. |
| 321 | func (s *LicenseService) GetUserLimit(ctx context.Context, workspaceID string) int { |