diff --git a/CHANGELOG.md b/CHANGELOG.md index de74c2d5..880cf6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.0.32] - 2024-12-12 + +### Fixed +- issue with scoping where Project would not be loaded when `serviceId` flag was used + ## [v1.0.27] - 2024-10-03 ### Fixed diff --git a/src/cmd/scope/scopeProject.go b/src/cmd/scope/scopeProject.go index 9aa93c7e..bcdeab53 100644 --- a/src/cmd/scope/scopeProject.go +++ b/src/cmd/scope/scopeProject.go @@ -30,6 +30,15 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm var project *entity.Project var err error + // service scope is set - use project from it + if cmdData.Service != nil { + project, err = repository.GetProjectById(ctx, cmdData.RestApiClient, cmdData.Service.ProjectID) + if err == nil { + cmdData.Project = project + return nil + } + } + // project scope is set if cmdData.CliStorage.Data().ScopeProjectId.Filled() { projectId, _ := cmdData.CliStorage.Data().ScopeProjectId.Get() @@ -68,7 +77,7 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm infoText = i18n.SelectedProject } - // service id is passed as a flag + // project id is passed as a flag if projectId := cmdData.Params.GetString(ProjectArgName); projectId != "" { project, err = repository.GetProjectById(ctx, cmdData.RestApiClient, uuid.ProjectId(projectId)) if err != nil { diff --git a/src/cmd/scope/scopeService.go b/src/cmd/scope/scopeService.go index e3cd4ecf..f3a2c154 100644 --- a/src/cmd/scope/scopeService.go +++ b/src/cmd/scope/scopeService.go @@ -53,14 +53,11 @@ func (s *service) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm } } - // now we have to load project, because we need projectId going forwards - if service == nil { + if serviceIdOrName, exists := cmdData.Args[ServiceArgName]; exists && service == nil { + // we have to load project, because we need projectId if err := s.parent.LoadSelectedScope(ctx, cmd, cmdData); err != nil { return err } - } - - if serviceIdOrName, exists := cmdData.Args[ServiceArgName]; exists && service == nil { service, err = repository.GetServiceByIdOrName(ctx, cmdData.RestApiClient, cmdData.Project.ID, serviceIdOrName[0]) if err != nil { return err @@ -77,5 +74,13 @@ func (s *service) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm cmdData.Service = service cmdData.UxBlocks.PrintInfo(styles.InfoWithValueLine(i18n.T(infoText), cmdData.Service.Name.String())) + + // Load parent scope from selected service if it wasn't loaded already above + if cmdData.Project == nil { + if err := s.parent.LoadSelectedScope(ctx, cmd, cmdData); err != nil { + return err + } + } + return nil } diff --git a/src/entity/repository/service.go b/src/entity/repository/service.go index eb0edd98..4ad4acea 100644 --- a/src/entity/repository/service.go +++ b/src/entity/repository/service.go @@ -130,6 +130,7 @@ func GetNonSystemServicesByProject( func serviceFromEsSearch(esServiceStack output.EsServiceStack) entity.Service { return entity.Service{ ID: esServiceStack.Id, + ProjectID: esServiceStack.ProjectId, ClientId: esServiceStack.ClientId, Name: esServiceStack.Name, Status: esServiceStack.Status, @@ -142,6 +143,7 @@ func serviceFromEsSearch(esServiceStack output.EsServiceStack) entity.Service { func serviceFromApiOutput(service output.ServiceStack) entity.Service { return entity.Service{ ID: service.Id, + ProjectID: service.ProjectId, ClientId: service.Project.ClientId, Name: service.Name, Status: service.Status, diff --git a/src/entity/service.go b/src/entity/service.go index fe7ffd76..c3c440dd 100644 --- a/src/entity/service.go +++ b/src/entity/service.go @@ -9,6 +9,7 @@ import ( type Service struct { ID uuid.ServiceStackId + ProjectID uuid.ProjectId ClientId uuid.ClientId Name types.String Status enum.ServiceStackStatusEnum