Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Improve canJoin check for public link

Neeraj Guptaafe77053553f
diff --git a/server/ente/public_collection.go b/server/ente/public_collection.go
index d1e4819c49..420a215f79 100644
--- a/server/ente/public_collection.go
+++ b/server/ente/public_collection.go
@@ -4,7 +4,6 @@ import (
"database/sql/driver"
"encoding/json"
"github.com/ente-io/museum/pkg/utils/time"
-
"github.com/ente-io/stacktrace"
)
@@ -57,6 +56,22 @@ type PublicCollectionToken struct {
EnableJoin bool
}
+func (p PublicCollectionToken) CanJoin() error {
+ if p.IsDisabled {
+ return NewBadRequestWithMessage("link disabled")
+ }
+ if p.ValidTill > 0 && p.ValidTill < time.Microseconds() {
+ return NewBadRequestWithMessage("token expired")
+ }
+ if p.EnableDownload == false {
+ return NewBadRequestWithMessage("can not join as download is disabled")
+ }
+ if p.EnableJoin == false {
+ return NewBadRequestWithMessage("can not join as join is disabled")
+ }
+ return nil
+}
+
// PublicURL represents information about non-disabled public url for a collection
type PublicURL struct {
URL string `json:"url"`
@@ -94,16 +109,6 @@ type PublicCollectionSummary struct {
PassHash *string
}
-func (p PublicCollectionToken) CanJoin() error {
- if p.IsDisabled {
- return stacktrace.NewError("disabled token")
- }
- if p.ValidTill > 0 && p.ValidTill < time.Microseconds() {
- return stacktrace.NewError("expired token")
- }
- return nil
-}
-
type AbuseReportRequest struct {
URL string `json:"url" binding:"required"`
Reason string `json:"reason" binding:"required"`