From dcc8da83e7685b2d22a47184363c8545ddec54ae Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Sat, 16 Nov 2024 15:13:22 +0100 Subject: [PATCH] makes profiles public --- .../1731762218_updated_summit_logs.go | 38 +++++ .../1731762869_updated_users_anonymous.go | 156 ++++++++++++++++++ db/migrations/1731764020_updated_waypoints.go | 34 ++++ .../1731764074_updated_summit_logs.go | 38 +++++ web/src/lib/components/nav_bar.svelte | 6 +- web/src/lib/components/share_info.svelte | 4 +- .../summit_log/summit_log_table.svelte | 11 +- .../summit_log/summit_log_table_row.svelte | 33 +++- .../components/trail/trail_info_panel.svelte | 8 +- web/src/lib/models/summit_log.ts | 2 + web/src/lib/models/trail_share.ts | 4 +- web/src/lib/models/user.ts | 1 + web/src/lib/stores/summit_log_store.ts | 14 +- web/src/lib/stores/user_store.ts | 8 +- web/src/routes/api/v1/summit-log/+server.ts | 10 ++ .../routes/api/v1/summit-log/[id]/+server.ts | 6 + web/src/routes/api/v1/trail/[id]/+server.ts | 6 + .../routes/profile/{ => [id]}/+page.svelte | 14 +- web/src/routes/profile/{ => [id]}/+page.ts | 12 +- 19 files changed, 364 insertions(+), 41 deletions(-) create mode 100644 db/migrations/1731762218_updated_summit_logs.go create mode 100644 db/migrations/1731762869_updated_users_anonymous.go create mode 100644 db/migrations/1731764020_updated_waypoints.go create mode 100644 db/migrations/1731764074_updated_summit_logs.go rename web/src/routes/profile/{ => [id]}/+page.svelte (97%) rename web/src/routes/profile/{ => [id]}/+page.ts (68%) diff --git a/db/migrations/1731762218_updated_summit_logs.go b/db/migrations/1731762218_updated_summit_logs.go new file mode 100644 index 00000000..a5371b8d --- /dev/null +++ b/db/migrations/1731762218_updated_summit_logs.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) || (author = @request.auth.id)") + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) || (author = @request.auth.id)") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true) || (author = @request.auth.id)") + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true) || (author = @request.auth.id)") + + return dao.SaveCollection(collection) + }) +} diff --git a/db/migrations/1731762869_updated_users_anonymous.go b/db/migrations/1731762869_updated_users_anonymous.go new file mode 100644 index 00000000..07164348 --- /dev/null +++ b/db/migrations/1731762869_updated_users_anonymous.go @@ -0,0 +1,156 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models/schema" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("xku110v5a5xbufa") + if err != nil { + return err + } + + options := map[string]any{} + if err := json.Unmarshal([]byte(`{ + "query": "SELECT id, username, avatar, created FROM users" + }`), &options); err != nil { + return err + } + collection.SetOptions(options) + + // remove + collection.Schema.RemoveField("ogrxf4ps") + + // remove + collection.Schema.RemoveField("7k4bozux") + + // add + new_username := &schema.SchemaField{} + if err := json.Unmarshal([]byte(`{ + "system": false, + "id": "kvteagv6", + "name": "username", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }`), new_username); err != nil { + return err + } + collection.Schema.AddField(new_username) + + // add + new_avatar := &schema.SchemaField{} + if err := json.Unmarshal([]byte(`{ + "system": false, + "id": "m9efnpak", + "name": "avatar", + "type": "file", + "required": false, + "presentable": false, + "unique": false, + "options": { + "mimeTypes": [ + "image/jpeg", + "image/png", + "image/svg+xml", + "image/gif", + "image/webp" + ], + "thumbs": null, + "maxSelect": 1, + "maxSize": 5242880, + "protected": false + } + }`), new_avatar); err != nil { + return err + } + collection.Schema.AddField(new_avatar) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("xku110v5a5xbufa") + if err != nil { + return err + } + + options := map[string]any{} + if err := json.Unmarshal([]byte(`{ + "query": "SELECT id, username, avatar FROM users" + }`), &options); err != nil { + return err + } + collection.SetOptions(options) + + // add + del_username := &schema.SchemaField{} + if err := json.Unmarshal([]byte(`{ + "system": false, + "id": "ogrxf4ps", + "name": "username", + "type": "text", + "required": false, + "presentable": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }`), del_username); err != nil { + return err + } + collection.Schema.AddField(del_username) + + // add + del_avatar := &schema.SchemaField{} + if err := json.Unmarshal([]byte(`{ + "system": false, + "id": "7k4bozux", + "name": "avatar", + "type": "file", + "required": false, + "presentable": false, + "unique": false, + "options": { + "mimeTypes": [ + "image/jpeg", + "image/png", + "image/svg+xml", + "image/gif", + "image/webp" + ], + "thumbs": null, + "maxSelect": 1, + "maxSize": 5242880, + "protected": false + } + }`), del_avatar); err != nil { + return err + } + collection.Schema.AddField(del_avatar) + + // remove + collection.Schema.RemoveField("kvteagv6") + + // remove + collection.Schema.RemoveField("m9efnpak") + + return dao.SaveCollection(collection) + }) +} diff --git a/db/migrations/1731764020_updated_waypoints.go b/db/migrations/1731764020_updated_waypoints.go new file mode 100644 index 00000000..44b39785 --- /dev/null +++ b/db/migrations/1731764020_updated_waypoints.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("goeo2ubp103rzp9") + if err != nil { + return err + } + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.waypoints.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.waypoints.id ?= id && @collection.trails.public ?= true) || \n(@collection.trail_share.trail.waypoints.id ?= id && @collection.trail_share.user ?= @request.auth.id) ||\n(author = @request.auth.id)") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("goeo2ubp103rzp9") + if err != nil { + return err + } + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.waypoints.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.waypoints.id ?= id && @collection.trails.public ?= true) || (author = @request.auth.id)") + + return dao.SaveCollection(collection) + }) +} diff --git a/db/migrations/1731764074_updated_summit_logs.go b/db/migrations/1731764074_updated_summit_logs.go new file mode 100644 index 00000000..732b80e2 --- /dev/null +++ b/db/migrations/1731764074_updated_summit_logs.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) ||\n(@collection.trail_share.trail.summit_logs.id ?= id && @collection.trail_share.user ?= @request.auth.id) ||\n(author = @request.auth.id)") + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) || \n(@collection.trail_share.trail.summit_logs.id ?= id && @collection.trail_share.user ?= @request.auth.id) ||\n(author = @request.auth.id)") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) || (author = @request.auth.id)") + + collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public ?= true) || (author = @request.auth.id)") + + return dao.SaveCollection(collection) + }) +} diff --git a/web/src/lib/components/nav_bar.svelte b/web/src/lib/components/nav_bar.svelte index fe78731b..1dedfe08 100644 --- a/web/src/lib/components/nav_bar.svelte +++ b/web/src/lib/components/nav_bar.svelte @@ -78,7 +78,7 @@ function handleDropdownClick(item: { text: string; value: any }) { if (item.value == "profile") { - goto("/profile"); + goto(`/profile/${$currentUser?.id}`); } else if (item.value == "logout") { logout(); window.location.href = "/"; @@ -128,7 +128,7 @@
{$currentUser.username}
{$currentUser.email} diff --git a/web/src/lib/components/share_info.svelte b/web/src/lib/components/share_info.svelte index cb789fe3..a1a82eaa 100644 --- a/web/src/lib/components/share_info.svelte +++ b/web/src/lib/components/share_info.svelte @@ -1,7 +1,7 @@ @@ -130,6 +129,26 @@ > {/if} + {#if showAuthor && log.expand.author} +
+
+
+
+
Joined: - {new Date($currentUser.created ?? "").toLocaleDateString( + {new Date(data.user.created ?? "").toLocaleDateString( undefined, { month: "2-digit", @@ -420,7 +420,7 @@ {$_("all-activities")} -