From 46c9a3742e2d74322f6b499793f5b9bc926411ee Mon Sep 17 00:00:00 2001
From: Daniel Supernault
Date: Sun, 8 Dec 2019 00:51:14 -0700
Subject: [PATCH 1/4] Update CollectionController
---
app/Http/Controllers/CollectionController.php | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php
index 588340a35..4fc7dfe65 100644
--- a/app/Http/Controllers/CollectionController.php
+++ b/app/Http/Controllers/CollectionController.php
@@ -205,4 +205,36 @@ class CollectionController extends Controller
];
});
}
+
+ public function deleteId(Request $request)
+ {
+ $this->validate($request, [
+ 'collection_id' => 'required|int|min:1|exists:collections,id',
+ 'post_id' => 'required|int|min:1|exists:statuses,id'
+ ]);
+
+ $profileId = Auth::user()->profile_id;
+ $collectionId = $request->input('collection_id');
+ $postId = $request->input('post_id');
+
+ $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId);
+ $count = $collection->items()->count();
+
+ if($count == 1) {
+ abort(400, 'You cannot delete the only post of a collection!');
+ }
+
+ $status = Status::whereScope('public')
+ ->whereIn('type', ['photo', 'photo:album', 'video'])
+ ->findOrFail($postId);
+
+ $item = CollectionItem::whereCollectionId($collection->id)
+ ->whereObjectType('App\Status')
+ ->whereObjectId($status->id)
+ ->firstOrFail();
+
+ $item->delete();
+
+ return 200;
+ }
}
From 0569846f15fe6d5e9a6304214f3c64023dfd3ef8 Mon Sep 17 00:00:00 2001
From: Daniel Supernault
Date: Sun, 8 Dec 2019 00:51:31 -0700
Subject: [PATCH 2/4] Update web routes
---
routes/web.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/routes/web.php b/routes/web.php
index a2dc0bc23..66284debb 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -156,6 +156,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('bookmarks', 'InternalApiController@bookmarks');
Route::get('collection/items/{id}', 'CollectionController@getItems');
Route::post('collection/item', 'CollectionController@storeId');
+ Route::delete('collection/item', 'CollectionController@deleteId');
Route::get('collection/{id}', 'CollectionController@get');
Route::post('collection/{id}', 'CollectionController@store');
Route::delete('collection/{id}', 'CollectionController@delete')->middleware('throttle:maxCollectionsPerHour,60')->middleware('throttle:maxCollectionsPerDay,1440')->middleware('throttle:maxCollectionsPerMonth,43800');
From 076023eac97528e37260092c3236e4c739bbf6f9 Mon Sep 17 00:00:00 2001
From: Daniel Supernault
Date: Sun, 8 Dec 2019 00:53:31 -0700
Subject: [PATCH 3/4] Update CollectionComponent.vue
---
.../js/components/CollectionComponent.vue | 116 ++++++++++++++++--
1 file changed, 109 insertions(+), 7 deletions(-)
diff --git a/resources/assets/js/components/CollectionComponent.vue b/resources/assets/js/components/CollectionComponent.vue
index bf7c4b58f..18d6ccf5b 100644
--- a/resources/assets/js/components/CollectionComponent.vue
+++ b/resources/assets/js/components/CollectionComponent.vue
@@ -15,7 +15,7 @@
-