access.go 917 B

12345678910111213141516171819202122232425262728293031323334
  1. package access
  2. import (
  3. "github.com/ente-io/museum/pkg/repo"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // Controller exposes helper methods to perform access checks while fetching or editing
  7. // any entity.
  8. type Controller interface {
  9. GetCollection(ctx *gin.Context, req *GetCollectionParams) (*GetCollectionResponse, error)
  10. VerifyFileOwnership(ctx *gin.Context, req *VerifyFileOwnershipParams) error
  11. }
  12. // controllerImpl implements Controller
  13. type controllerImpl struct {
  14. FileRepo *repo.FileRepository
  15. CollectionRepo *repo.CollectionRepository
  16. }
  17. // https://stackoverflow.com/a/33089540/546896
  18. var _ Controller = (*controllerImpl)(nil) // Verify that *T implements I.
  19. var _ Controller = controllerImpl{}
  20. func NewAccessController(
  21. collRepo *repo.CollectionRepository,
  22. fileRepo *repo.FileRepository,
  23. ) Controller {
  24. comp := &controllerImpl{
  25. CollectionRepo: collRepo,
  26. FileRepo: fileRepo,
  27. }
  28. return comp
  29. }