(ctx context.Context, req types.ListLFSLockReq)
| 481 | } |
| 482 | |
| 483 | func (c *GitHTTPComponent) ListLocks(ctx context.Context, req types.ListLFSLockReq) (*types.LFSLockList, error) { |
| 484 | repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) |
| 485 | if err != nil { |
| 486 | return nil, fmt.Errorf("failed to find repo, error: %w", err) |
| 487 | } |
| 488 | |
| 489 | _, err = c.user.FindByUsername(ctx, req.CurrentUser) |
| 490 | if err != nil { |
| 491 | return nil, ErrUnauthorized |
| 492 | } |
| 493 | |
| 494 | allowed, err := c.AllowReadAccess(ctx, req.RepoType, req.Namespace, req.Name, req.CurrentUser) |
| 495 | if err != nil { |
| 496 | slog.Error("Unable to check user write access:", slog.Any("error", err)) |
| 497 | return nil, err |
| 498 | } |
| 499 | |
| 500 | if !allowed { |
| 501 | return nil, ErrUnauthorized |
| 502 | } |
| 503 | |
| 504 | if req.ID != 0 { |
| 505 | l, err := c.lfsLockStore.FindByID(ctx, req.ID) |
| 506 | if err != nil { |
| 507 | if errors.Is(err, sql.ErrNoRows) { |
| 508 | return buildLFSLockList([]database.LfsLock{}), nil |
| 509 | } |
| 510 | return buildLFSLockList([]database.LfsLock{}), err |
| 511 | } |
| 512 | if l.RepositoryID != repo.ID { |
| 513 | return buildLFSLockList([]database.LfsLock{}), nil |
| 514 | } |
| 515 | return buildLFSLockList([]database.LfsLock{*l}), nil |
| 516 | } |
| 517 | |
| 518 | if req.Path != "" { |
| 519 | l, err := c.lfsLockStore.FindByPath(ctx, repo.ID, req.Path) |
| 520 | if err != nil { |
| 521 | if errors.Is(err, sql.ErrNoRows) { |
| 522 | return buildLFSLockList([]database.LfsLock{}), nil |
| 523 | } |
| 524 | return buildLFSLockList([]database.LfsLock{}), err |
| 525 | } |
| 526 | return buildLFSLockList([]database.LfsLock{*l}), nil |
| 527 | } |
| 528 | |
| 529 | locks, err := c.lfsLockStore.FindByRepoID(ctx, repo.ID, req.Cursor, req.Limit) |
| 530 | if err != nil { |
| 531 | return buildLFSLockList([]database.LfsLock{}), err |
| 532 | } |
| 533 | |
| 534 | next := "" |
| 535 | if req.Limit > 0 && len(locks) == req.Limit { |
| 536 | next = strconv.Itoa(req.Cursor + 1) |
| 537 | } |
| 538 | res := buildLFSLockList(locks) |
| 539 | res.Next = next |
| 540 |
nothing calls this directly
no test coverage detected