(ctx context.Context, req *adminv1.DeleteReportRequest)
| 432 | } |
| 433 | |
| 434 | func (s *Server) DeleteReport(ctx context.Context, req *adminv1.DeleteReportRequest) (*adminv1.DeleteReportResponse, error) { |
| 435 | observability.AddRequestAttributes(ctx, |
| 436 | attribute.String("args.organization", req.Org), |
| 437 | attribute.String("args.project", req.Project), |
| 438 | attribute.String("args.name", req.Name), |
| 439 | ) |
| 440 | |
| 441 | proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project) |
| 442 | if err != nil { |
| 443 | return nil, err |
| 444 | } |
| 445 | |
| 446 | claims := auth.GetClaims(ctx) |
| 447 | permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 448 | if !permissions.ReadProd { |
| 449 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read project repo") |
| 450 | } |
| 451 | |
| 452 | if proj.PrimaryDeploymentID == nil { |
| 453 | return nil, status.Error(codes.FailedPrecondition, "project does not have a production deployment") |
| 454 | } |
| 455 | |
| 456 | depl, err := s.admin.DB.FindDeployment(ctx, *proj.PrimaryDeploymentID) |
| 457 | if err != nil { |
| 458 | return nil, err |
| 459 | } |
| 460 | |
| 461 | spec, err := s.admin.LookupReport(ctx, depl, req.Name) |
| 462 | if err != nil { |
| 463 | return nil, fmt.Errorf("could not get report: %w", err) |
| 464 | } |
| 465 | annotations := parseReportAnnotations(spec.Annotations) |
| 466 | |
| 467 | if !annotations.AdminManaged { |
| 468 | return nil, status.Error(codes.FailedPrecondition, "can't edit report because it was not created from the UI") |
| 469 | } |
| 470 | |
| 471 | isOwner := claims.OwnerType() == auth.OwnerTypeUser && annotations.AdminOwnerUserID == claims.OwnerID() |
| 472 | if !permissions.ManageReports && !isOwner { |
| 473 | return nil, status.Error(codes.PermissionDenied, "does not have permission to edit report") |
| 474 | } |
| 475 | |
| 476 | err = s.admin.DB.UpdateVirtualFileDeleted(ctx, proj.ID, "prod", virtualFilePathForManagedReport(req.Name)) |
| 477 | if err != nil { |
| 478 | return nil, fmt.Errorf("failed to delete virtual file: %w", err) |
| 479 | } |
| 480 | |
| 481 | err = s.admin.TriggerParserAndAwaitResource(ctx, depl, req.Name, runtime.ResourceKindReport) |
| 482 | if err != nil { |
| 483 | return nil, fmt.Errorf("failed to reconcile report: %w", err) |
| 484 | } |
| 485 | |
| 486 | return &adminv1.DeleteReportResponse{}, nil |
| 487 | } |
| 488 | |
| 489 | func (s *Server) TriggerReport(ctx context.Context, req *adminv1.TriggerReportRequest) (*adminv1.TriggerReportResponse, error) { |
| 490 | observability.AddRequestAttributes(ctx, |
nothing calls this directly
no test coverage detected