From 4125ce0ba76e17d66d94abaf544506c2f5fc8289 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 3 Oct 2024 12:15:47 +0200 Subject: [PATCH] imp: Allow to follow a shared collection --- .../stylesheets/components/sections.css | 4 ++ src/controllers/collections/Groups.php | 4 +- src/models/dao/Collection.php | 10 ++- src/models/dao/links/NewsQueries.php | 5 +- src/views/collections/show.phtml | 70 +++++++++++++++---- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/assets/stylesheets/components/sections.css b/src/assets/stylesheets/components/sections.css index 98fd169b..707c8c4a 100644 --- a/src/assets/stylesheets/components/sections.css +++ b/src/assets/stylesheets/components/sections.css @@ -122,6 +122,10 @@ } .section__actions { + display: flex; + + gap: var(--space-small); + flex-shrink: 0; } diff --git a/src/controllers/collections/Groups.php b/src/controllers/collections/Groups.php index 01d9f6b7..8da33ac6 100644 --- a/src/controllers/collections/Groups.php +++ b/src/controllers/collections/Groups.php @@ -154,7 +154,9 @@ public function update(Request $request): Response if ($can_update) { $collection->group_id = $group_id; $collection->save(); - } else { + } + + if ($is_following) { $followed_collection = models\FollowedCollection::findBy([ 'user_id' => $user->id, 'collection_id' => $collection->id, diff --git a/src/models/dao/Collection.php b/src/models/dao/Collection.php index 5bbc21a6..d6030216 100644 --- a/src/models/dao/Collection.php +++ b/src/models/dao/Collection.php @@ -238,7 +238,15 @@ public static function listComputedFollowedByUserId( WHERE fc.collection_id = c.id AND fc.user_id = :user_id - AND c.is_public = true + AND ( + c.is_public = true + OR c.user_id = :user_id + OR EXISTS ( + SELECT 1 FROM collection_shares cs + WHERE cs.user_id = :user_id + AND cs.collection_id = c.id + ) + ) {$type_clause} diff --git a/src/models/dao/links/NewsQueries.php b/src/models/dao/links/NewsQueries.php index 99a27135..67ea113f 100644 --- a/src/models/dao/links/NewsQueries.php +++ b/src/models/dao/links/NewsQueries.php @@ -44,8 +44,9 @@ public static function listFromFollowedCollections(string $user_id, int $max): a AND lc.collection_id = c.id AND ( - (l.is_hidden = false AND c.is_public = true) OR - EXISTS ( + (l.is_hidden = false AND c.is_public = true) + OR c.user_id = :user_id + OR EXISTS ( SELECT 1 FROM collection_shares cs WHERE cs.user_id = :user_id AND cs.collection_id = c.id diff --git a/src/views/collections/show.phtml b/src/views/collections/show.phtml index 273e3ad3..ebe74f38 100644 --- a/src/views/collections/show.phtml +++ b/src/views/collections/show.phtml @@ -75,6 +75,9 @@ + isFollowing($collection->id); ?> + shares()) > 0; ?> +