Files

25 lines
744 B
Go
Raw Permalink Normal View History

package workbench
import (
"context"
"errors"
"github.com/Tencent/WeKnora/internal/types"
"gorm.io/gorm"
)
// Queue workers do not pass through the HTTP middleware that loads the
// workspace retrieval, storage and model context. Reload it for every job.
func (s *Service) restoreJobTenant(ctx context.Context, tenantID uint64) (context.Context, error) {
var tenant types.Tenant
err := s.db.WithContext(ctx).Where("id = ? AND status = ?", tenantID, "active").First(&tenant).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return ctx, ErrForbidden
}
if err != nil {
return ctx, err
}
ctx = context.WithValue(ctx, types.TenantIDContextKey, tenant.ID)
return context.WithValue(ctx, types.TenantInfoContextKey, &tenant), nil
}