diff --git a/server/ente/public_collection.go b/server/ente/public_collection.go index e91b916d14..86e2bd20e3 100644 --- a/server/ente/public_collection.go +++ b/server/ente/public_collection.go @@ -12,9 +12,10 @@ import ( type CreatePublicAccessTokenRequest struct { CollectionID int64 `json:"collectionID" binding:"required"` EnableCollect bool `json:"enableCollect"` - JoinViaLink bool `json:"joinViaLink"` - ValidTill int64 `json:"validTill"` - DeviceLimit int `json:"deviceLimit"` + // defaults to true + EnableJoin *bool `json:"joinViaLink"` + ValidTill int64 `json:"validTill"` + DeviceLimit int `json:"deviceLimit"` } type UpdatePublicAccessTokenRequest struct { @@ -66,10 +67,10 @@ type PublicURL struct { EnableCollect bool `json:"enableCollect"` PasswordEnabled bool `json:"passwordEnabled"` // Nonce contains the nonce value for the password if the link is password protected. - Nonce *string `json:"nonce,omitempty"` - MemLimit *int64 `json:"memLimit,omitempty"` - OpsLimit *int64 `json:"opsLimit,omitempty"` - EnableJoinViaLink bool `json:"enableJoinViaLink"` + Nonce *string `json:"nonce,omitempty"` + MemLimit *int64 `json:"memLimit,omitempty"` + OpsLimit *int64 `json:"opsLimit,omitempty"` + EnableJoin bool `json:"enableJoinViaLink"` } type PublicAccessContext struct { diff --git a/server/pkg/controller/public_collection.go b/server/pkg/controller/public_collection.go index 74733b4459..c7224813e8 100644 --- a/server/pkg/controller/public_collection.go +++ b/server/pkg/controller/public_collection.go @@ -61,7 +61,8 @@ type PublicCollectionController struct { func (c *PublicCollectionController) CreateAccessToken(ctx context.Context, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) { accessToken := shortuuid.New()[0:AccessTokenLength] - err := c.PublicCollectionRepo.Insert(ctx, req.CollectionID, accessToken, req.ValidTill, req.DeviceLimit, req.EnableCollect) + err := c.PublicCollectionRepo. + Insert(ctx, req.CollectionID, accessToken, req.ValidTill, req.DeviceLimit, req.EnableCollect, req.EnableJoin) if err != nil { if errors.Is(err, ente.ErrActiveLinkAlreadyExists) { collectionToPubUrlMap, err2 := c.PublicCollectionRepo.GetCollectionToActivePublicURLMap(ctx, []int64{req.CollectionID}) diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.go index 9310f33d47..4a0de28175 100644 --- a/server/pkg/repo/collection.go +++ b/server/pkg/repo/collection.go @@ -155,7 +155,7 @@ func (repo *CollectionRepository) GetCollectionsOwnedByUserV2(userID int64, upda SELECT c.collection_id, c.owner_id, c.encrypted_key,c.key_decryption_nonce, c.name, c.encrypted_name, c.name_decryption_nonce, c.type, c.app, c.attributes, c.updation_time, c.is_deleted, c.magic_metadata, c.pub_magic_metadata, users.user_id, users.encrypted_email, users.email_decryption_nonce, cs.role_type, -pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_at, pct.pw_hash, pct.pw_nonce, pct.mem_limit, pct.ops_limit, pct.enable_download, pct.enable_collect +pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_at, pct.pw_hash, pct.pw_nonce, pct.mem_limit, pct.ops_limit, pct.enable_download, pct.enable_collect, pct.enable_join FROM collections c LEFT JOIN collection_shares cs ON (cs.collection_id = c.collection_id AND cs.is_deleted = false) @@ -175,14 +175,14 @@ pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_ var c ente.Collection var name, encryptedName, nameDecryptionNonce sql.NullString var pctDeviceLimit sql.NullInt32 - var pctEnableDownload, pctEnableCollect sql.NullBool + var pctEnableDownload, pctEnableCollect, pctEnableJoin sql.NullBool var shareUserID, pctValidTill, pctCreatedAt, pctUpdatedAt, pctMemLimit, pctOpsLimit sql.NullInt64 var encryptedEmail, nonce []byte var shareeRoleType, pctToken, pctPwHash, pctPwNonce sql.NullString if err := rows.Scan(&c.ID, &c.Owner.ID, &c.EncryptedKey, &c.KeyDecryptionNonce, &name, &encryptedName, &nameDecryptionNonce, &c.Type, &c.App, &c.Attributes, &c.UpdationTime, &c.IsDeleted, &c.MagicMetadata, &c.PublicMagicMetadata, &shareUserID, &encryptedEmail, &nonce, &shareeRoleType, - &pctToken, &pctValidTill, &pctDeviceLimit, &pctCreatedAt, &pctUpdatedAt, &pctPwHash, &pctPwNonce, &pctMemLimit, &pctOpsLimit, &pctEnableDownload, &pctEnableCollect); err != nil { + &pctToken, &pctValidTill, &pctDeviceLimit, &pctCreatedAt, &pctUpdatedAt, &pctPwHash, &pctPwNonce, &pctMemLimit, &pctOpsLimit, &pctEnableDownload, &pctEnableCollect, &pctEnableJoin); err != nil { return nil, stacktrace.Propagate(err, "") } @@ -222,6 +222,7 @@ pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_ EnableDownload: pctEnableDownload.Bool, EnableCollect: pctEnableCollect.Bool, PasswordEnabled: pctPwNonce.Valid, + EnableJoin: pctEnableJoin.Bool, } if pctPwNonce.Valid { url.Nonce = &pctPwNonce.String diff --git a/server/pkg/repo/public_collection.go b/server/pkg/repo/public_collection.go index 6717688b58..c31e075839 100644 --- a/server/pkg/repo/public_collection.go +++ b/server/pkg/repo/public_collection.go @@ -36,10 +36,15 @@ func (pcr *PublicCollectionRepository) GetAlbumUrl(token string) string { } func (pcr *PublicCollectionRepository) Insert(ctx context.Context, - cID int64, token string, validTill int64, deviceLimit int, enableCollect bool) error { + cID int64, token string, validTill int64, deviceLimit int, enableCollect bool, enableJoin *bool) error { + // default value for enableJoin is true + join := true + if enableJoin != nil { + join = *enableJoin + } _, err := pcr.DB.ExecContext(ctx, `INSERT INTO public_collection_tokens - (collection_id, access_token, valid_till, device_limit, enable_collect) VALUES ($1, $2, $3, $4, $5)`, - cID, token, validTill, deviceLimit, enableCollect) + (collection_id, access_token, valid_till, device_limit, enable_collect, enable_join) VALUES ($1, $2, $3, $4, $5, $6)`, + cID, token, validTill, deviceLimit, enableCollect, join) if err != nil && err.Error() == "pq: duplicate key value violates unique constraint \"public_active_collection_unique_idx\"" { return ente.ErrActiveLinkAlreadyExists }