(ctx context.Context, req *adminv1.GetReportMetaRequest)
| 28 | ) |
| 29 | |
| 30 | func (s *Server) GetReportMeta(ctx context.Context, req *adminv1.GetReportMetaRequest) (*adminv1.GetReportMetaResponse, error) { |
| 31 | observability.AddRequestAttributes(ctx, |
| 32 | attribute.String("args.project_id", req.ProjectId), |
| 33 | attribute.String("args.report", req.Report), |
| 34 | attribute.StringSlice("args.email_recipients", req.EmailRecipients), |
| 35 | attribute.String("args.execution_time", req.ExecutionTime.String()), |
| 36 | attribute.Bool("args.anon_recipients", req.AnonRecipients), |
| 37 | attribute.String("args.owner_id", req.OwnerId), |
| 38 | attribute.String("args.web_open_mode", req.WebOpenMode), |
| 39 | ) |
| 40 | |
| 41 | proj, err := s.admin.DB.FindProject(ctx, req.ProjectId) |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | |
| 46 | permissions := auth.GetClaims(ctx).ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 47 | if !permissions.ReadProdStatus { |
| 48 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read report meta") |
| 49 | } |
| 50 | |
| 51 | webOpenMode := WebOpenMode(req.WebOpenMode) |
| 52 | if !webOpenMode.Valid() { |
| 53 | return nil, status.Errorf(codes.InvalidArgument, "invalid web open mode %q", req.WebOpenMode) |
| 54 | } |
| 55 | |
| 56 | org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | |
| 61 | delivery := make(map[string]*adminv1.GetReportMetaResponse_DeliveryMeta) |
| 62 | |
| 63 | var recipients []string |
| 64 | recipients = append(recipients, req.EmailRecipients...) |
| 65 | if req.AnonRecipients { |
| 66 | // add empty email for slack and other notifiers token |
| 67 | recipients = append(recipients, "") |
| 68 | } |
| 69 | |
| 70 | var ownerEmail string |
| 71 | if req.OwnerId != "" { |
| 72 | owner, err := s.admin.DB.FindUser(ctx, req.OwnerId) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | ownerEmail = owner.Email |
| 77 | } |
| 78 | |
| 79 | var tokens map[string]string |
| 80 | if webOpenMode == WebOpenModeRecipient { |
| 81 | tokens, err = s.createUnsubMagicTokens(ctx, proj.ID, req.Report, req.OwnerId, ownerEmail, recipients) |
| 82 | } else { |
| 83 | tokens, err = s.createMagicTokens(ctx, proj.OrganizationID, proj.ID, req.Report, req.OwnerId, recipients, req.Resources) |
| 84 | } |
| 85 | if err != nil { |
| 86 | return nil, fmt.Errorf("failed to issue magic auth tokens: %w", err) |
| 87 | } |
nothing calls this directly
no test coverage detected