(ctx context.Context, req types.LfsLockReq)
| 437 | } |
| 438 | |
| 439 | func (c *GitHTTPComponent) CreateLock(ctx context.Context, req types.LfsLockReq) (*database.LfsLock, error) { |
| 440 | var ( |
| 441 | lock *database.LfsLock |
| 442 | ) |
| 443 | repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) |
| 444 | if err != nil { |
| 445 | return nil, fmt.Errorf("failed to find repo, error: %w", err) |
| 446 | } |
| 447 | |
| 448 | user, err := c.user.FindByUsername(ctx, req.CurrentUser) |
| 449 | if err != nil { |
| 450 | return nil, ErrUnauthorized |
| 451 | } |
| 452 | |
| 453 | allowed, err := c.AllowWriteAccess(ctx, req.RepoType, req.Namespace, req.Name, req.CurrentUser) |
| 454 | if err != nil { |
| 455 | slog.Error("Unable to check user write access:", slog.Any("error", err)) |
| 456 | return nil, err |
| 457 | } |
| 458 | |
| 459 | if !allowed { |
| 460 | return nil, ErrUnauthorized |
| 461 | } |
| 462 | lfsLock := database.LfsLock{ |
| 463 | Path: req.Path, |
| 464 | UserID: user.ID, |
| 465 | RepositoryID: repo.ID, |
| 466 | } |
| 467 | |
| 468 | lock, err = c.lfsLockStore.FindByPath(ctx, lfsLock.RepositoryID, lfsLock.Path) |
| 469 | if err != nil { |
| 470 | if errors.Is(err, sql.ErrNoRows) { |
| 471 | lock, err = c.lfsLockStore.Create(ctx, lfsLock) |
| 472 | if err != nil { |
| 473 | return nil, ErrAlreadyExists |
| 474 | } |
| 475 | return lock, nil |
| 476 | } |
| 477 | return lock, fmt.Errorf("failed to find lfs lock, error: %w", err) |
| 478 | } |
| 479 | |
| 480 | return lock, ErrAlreadyExists |
| 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) |
nothing calls this directly
no test coverage detected