(ctx context.Context, req *adminv1.ListProjectsForFingerprintRequest)
| 159 | } |
| 160 | |
| 161 | func (s *Server) ListProjectsForFingerprint(ctx context.Context, req *adminv1.ListProjectsForFingerprintRequest) (*adminv1.ListProjectsForFingerprintResponse, error) { |
| 162 | observability.AddRequestAttributes(ctx, |
| 163 | attribute.String("args.directory_name", req.DirectoryName), |
| 164 | attribute.String("args.git_remote", req.GitRemote), |
| 165 | attribute.String("args.sub_path", req.SubPath), |
| 166 | attribute.String("args.rill_mgd_git_remote", req.RillMgdGitRemote), |
| 167 | ) |
| 168 | |
| 169 | claims := auth.GetClaims(ctx) |
| 170 | if claims.OwnerType() != auth.OwnerTypeUser { |
| 171 | return nil, status.Error(codes.PermissionDenied, "only users can list projects by fingerprint") |
| 172 | } |
| 173 | userID := claims.OwnerID() |
| 174 | |
| 175 | // check if rill mgd remote was transferred |
| 176 | // we do not support transfers from self hosted git repos so no need to check for that |
| 177 | rillMgdRemote := req.RillMgdGitRemote |
| 178 | transfer, err := s.admin.DB.FindGitRepoTransfer(ctx, rillMgdRemote) |
| 179 | if err != nil && !errors.Is(err, database.ErrNotFound) { |
| 180 | return nil, err |
| 181 | } |
| 182 | if transfer != nil { |
| 183 | rillMgdRemote = transfer.To |
| 184 | } |
| 185 | |
| 186 | projects, err := s.admin.DB.FindProjectsForUserAndFingerprint(ctx, userID, req.DirectoryName, normalizeGitRemote(req.GitRemote), req.SubPath, rillMgdRemote) |
| 187 | if err != nil { |
| 188 | return nil, err |
| 189 | } |
| 190 | |
| 191 | if len(projects) == 0 && req.GitRemote != "" { |
| 192 | // if no project is found check if there is project user doesn't have access to |
| 193 | projects, err = s.admin.DB.FindProjectsByGitRemote(ctx, normalizeGitRemote(req.GitRemote)) |
| 194 | if err != nil { |
| 195 | return nil, err |
| 196 | } |
| 197 | for _, p := range projects { |
| 198 | if p.Subpath != req.SubPath { |
| 199 | continue |
| 200 | } |
| 201 | org, err := s.admin.DB.FindOrganization(ctx, p.OrganizationID) |
| 202 | if err != nil { |
| 203 | return nil, err |
| 204 | } |
| 205 | return &adminv1.ListProjectsForFingerprintResponse{ |
| 206 | UnauthorizedProject: fmt.Sprintf("%s/%s", org.Name, p.Name), |
| 207 | }, nil |
| 208 | } |
| 209 | return &adminv1.ListProjectsForFingerprintResponse{}, nil |
| 210 | } |
| 211 | |
| 212 | dtos := make([]*adminv1.Project, len(projects)) |
| 213 | orgNames := make(map[string]string) |
| 214 | for i, p := range projects { |
| 215 | orgName := orgNames[p.OrganizationID] |
| 216 | if orgName == "" { |
| 217 | org, err := s.admin.DB.FindOrganization(ctx, p.OrganizationID) |
| 218 | if err != nil { |
nothing calls this directly
no test coverage detected