mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Organised activity types and moved most to repos
Repos are generally better since otherwise we end up duplicating things between front-end and API. Types moved to by CONST values within a class for better visibilty of usage and listing of types.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
use BookStack\Exceptions\NotifyException;
|
||||
@ -55,8 +56,6 @@ class BookApiController extends ApiController
|
||||
$requestData = $this->validate($request, $this->rules['create']);
|
||||
|
||||
$book = $this->bookRepo->create($requestData);
|
||||
Activity::add($book, 'book_create', $book->id);
|
||||
|
||||
return response()->json($book);
|
||||
}
|
||||
|
||||
@ -80,7 +79,6 @@ class BookApiController extends ApiController
|
||||
|
||||
$requestData = $this->validate($request, $this->rules['update']);
|
||||
$book = $this->bookRepo->update($book, $requestData);
|
||||
Activity::add($book, 'book_update', $book->id);
|
||||
|
||||
return response()->json($book);
|
||||
}
|
||||
@ -96,8 +94,6 @@ class BookApiController extends ApiController
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
|
||||
$this->bookRepo->destroy($book);
|
||||
Activity::addMessage('book_delete', $book->name);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Entities\Repos\BookshelfRepo;
|
||||
use BookStack\Entities\Bookshelf;
|
||||
@ -63,7 +64,6 @@ class BookshelfApiController extends ApiController
|
||||
$bookIds = $request->get('books', []);
|
||||
$shelf = $this->bookshelfRepo->create($requestData, $bookIds);
|
||||
|
||||
Activity::add($shelf, 'bookshelf_create', $shelf->id);
|
||||
return response()->json($shelf);
|
||||
}
|
||||
|
||||
@ -94,12 +94,9 @@ class BookshelfApiController extends ApiController
|
||||
$this->checkOwnablePermission('bookshelf-update', $shelf);
|
||||
|
||||
$requestData = $this->validate($request, $this->rules['update']);
|
||||
|
||||
$bookIds = $request->get('books', null);
|
||||
|
||||
$shelf = $this->bookshelfRepo->update($shelf, $requestData, $bookIds);
|
||||
Activity::add($shelf, 'bookshelf_update', $shelf->id);
|
||||
|
||||
return response()->json($shelf);
|
||||
}
|
||||
|
||||
@ -115,8 +112,6 @@ class BookshelfApiController extends ApiController
|
||||
$this->checkOwnablePermission('bookshelf-delete', $shelf);
|
||||
|
||||
$this->bookshelfRepo->destroy($shelf);
|
||||
Activity::addMessage('bookshelf_delete', $shelf->name);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Repos\ChapterRepo;
|
||||
@ -58,8 +59,6 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-create', $book);
|
||||
|
||||
$chapter = $this->chapterRepo->create($request->all(), $book);
|
||||
Activity::add($chapter, 'chapter_create', $book->id);
|
||||
|
||||
return response()->json($chapter->load(['tags']));
|
||||
}
|
||||
|
||||
@ -83,8 +82,6 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
|
||||
$updatedChapter = $this->chapterRepo->update($chapter, $request->all());
|
||||
Activity::add($chapter, 'chapter_update', $chapter->book->id);
|
||||
|
||||
return response()->json($updatedChapter->load(['tags']));
|
||||
}
|
||||
|
||||
@ -97,8 +94,6 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
$this->chapterRepo->destroy($chapter);
|
||||
Activity::addMessage('chapter_delete', $chapter->name, $chapter->book->id);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use Activity;
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Managers\BookContents;
|
||||
use BookStack\Entities\Bookshelf;
|
||||
use BookStack\Entities\Managers\EntityContext;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
use BookStack\Exceptions\ImageUploadException;
|
||||
use BookStack\Exceptions\NotifyException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Throwable;
|
||||
@ -18,9 +18,6 @@ class BookController extends Controller
|
||||
protected $bookRepo;
|
||||
protected $entityContextManager;
|
||||
|
||||
/**
|
||||
* BookController constructor.
|
||||
*/
|
||||
public function __construct(EntityContext $entityContextManager, BookRepo $bookRepo)
|
||||
{
|
||||
$this->bookRepo = $bookRepo;
|
||||
@ -97,11 +94,10 @@ class BookController extends Controller
|
||||
|
||||
$book = $this->bookRepo->create($request->all());
|
||||
$this->bookRepo->updateCoverImage($book, $request->file('image', null));
|
||||
Activity::add($book, 'book_create', $book->id);
|
||||
|
||||
if ($bookshelf) {
|
||||
$bookshelf->appendBook($book);
|
||||
Activity::add($bookshelf, 'bookshelf_update');
|
||||
Activity::add($bookshelf, ActivityType::BOOKSHELF_UPDATE);
|
||||
}
|
||||
|
||||
return redirect($book->getUrl());
|
||||
@ -162,8 +158,6 @@ class BookController extends Controller
|
||||
$resetCover = $request->has('image_reset');
|
||||
$this->bookRepo->updateCoverImage($book, $request->file('image', null), $resetCover);
|
||||
|
||||
Activity::add($book, 'book_update', $book->id);
|
||||
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
|
||||
@ -187,7 +181,6 @@ class BookController extends Controller
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
|
||||
Activity::add($book, 'book_delete', $book->id);
|
||||
$this->bookRepo->destroy($book);
|
||||
|
||||
return redirect('/books');
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Managers\BookContents;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
@ -74,7 +75,7 @@ class BookSortController extends Controller
|
||||
|
||||
// Rebuild permissions and add activity for involved books.
|
||||
$booksInvolved->each(function (Book $book) {
|
||||
Activity::add($book, 'book_sort', $book->id);
|
||||
Activity::add($book, ActivityType::BOOK_SORT, $book->id);
|
||||
});
|
||||
|
||||
return redirect($book->getUrl());
|
||||
|
@ -92,7 +92,6 @@ class BookshelfController extends Controller
|
||||
$shelf = $this->bookshelfRepo->create($request->all(), $bookIds);
|
||||
$this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null));
|
||||
|
||||
Activity::add($shelf, 'bookshelf_create');
|
||||
return redirect($shelf->getUrl());
|
||||
}
|
||||
|
||||
@ -156,7 +155,6 @@ class BookshelfController extends Controller
|
||||
$shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds);
|
||||
$resetCover = $request->has('image_reset');
|
||||
$this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover);
|
||||
Activity::add($shelf, 'bookshelf_update');
|
||||
|
||||
return redirect($shelf->getUrl());
|
||||
}
|
||||
@ -182,7 +180,6 @@ class BookshelfController extends Controller
|
||||
$shelf = $this->bookshelfRepo->getBySlug($slug);
|
||||
$this->checkOwnablePermission('bookshelf-delete', $shelf);
|
||||
|
||||
Activity::add($shelf, 'bookshelf_delete');
|
||||
$this->bookshelfRepo->destroy($shelf);
|
||||
|
||||
return redirect('/shelves');
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use Activity;
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Managers\BookContents;
|
||||
use BookStack\Entities\Repos\ChapterRepo;
|
||||
@ -51,7 +50,6 @@ class ChapterController extends Controller
|
||||
$this->checkOwnablePermission('chapter-create', $book);
|
||||
|
||||
$chapter = $this->chapterRepo->create($request->all(), $book);
|
||||
Activity::add($chapter, 'chapter_create', $book->id);
|
||||
|
||||
return redirect($chapter->getUrl());
|
||||
}
|
||||
@ -100,7 +98,6 @@ class ChapterController extends Controller
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
|
||||
$this->chapterRepo->update($chapter, $request->all());
|
||||
Activity::add($chapter, 'chapter_update', $chapter->book->id);
|
||||
|
||||
return redirect($chapter->getUrl());
|
||||
}
|
||||
@ -128,7 +125,6 @@ class ChapterController extends Controller
|
||||
$chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
Activity::add($chapter, 'chapter_delete', $chapter->book->id);
|
||||
$this->chapterRepo->destroy($chapter);
|
||||
|
||||
return redirect($chapter->book->getUrl());
|
||||
@ -173,8 +169,6 @@ class ChapterController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
Activity::add($chapter, 'chapter_move', $newBook->id);
|
||||
|
||||
$this->showSuccessNotification(trans('entities.chapter_move_success', ['bookName' => $newBook->name]));
|
||||
return redirect($chapter->getUrl());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use Activity;
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Actions\CommentRepo;
|
||||
use BookStack\Entities\Page;
|
||||
use Illuminate\Http\Request;
|
||||
@ -40,7 +41,6 @@ class CommentController extends Controller
|
||||
// Create a new comment.
|
||||
$this->checkPermission('comment-create-all');
|
||||
$comment = $this->commentRepo->create($page, $request->get('text'), $request->get('parent_id'));
|
||||
Activity::add($page, 'commented_on', $page->book->id);
|
||||
return view('comments.comment', ['comment' => $comment]);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use Activity;
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Managers\BookContents;
|
||||
use BookStack\Entities\Managers\PageContent;
|
||||
use BookStack\Entities\Managers\PageEditActivity;
|
||||
@ -107,7 +108,6 @@ class PageController extends Controller
|
||||
$this->checkOwnablePermission('page-create', $draftPage->getParent());
|
||||
|
||||
$page = $this->pageRepo->publishDraft($draftPage, $request->all());
|
||||
Activity::add($page, 'page_create', $draftPage->book->id);
|
||||
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
@ -224,7 +224,6 @@ class PageController extends Controller
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
$this->pageRepo->update($page, $request->all());
|
||||
Activity::add($page, 'page_update', $page->book->id);
|
||||
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
@ -304,11 +303,9 @@ class PageController extends Controller
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
$parent = $page->getParent();
|
||||
|
||||
$book = $page->book;
|
||||
$parent = $page->chapter ?? $book;
|
||||
$this->pageRepo->destroy($page);
|
||||
Activity::add($page, 'page_delete', $page->book_id);
|
||||
|
||||
return redirect($parent->getUrl());
|
||||
}
|
||||
@ -393,7 +390,6 @@ class PageController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
Activity::add($page, 'page_move', $page->book->id);
|
||||
$this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name]));
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
@ -438,8 +434,6 @@ class PageController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
Activity::add($pageCopy, 'page_create', $pageCopy->book->id);
|
||||
|
||||
$this->showSuccessNotification(trans('entities.pages_copy_success'));
|
||||
return redirect($pageCopy->getUrl());
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Managers\PageContent;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
@ -101,7 +102,6 @@ class PageRevisionController extends Controller
|
||||
|
||||
$page = $this->pageRepo->restoreRevision($page, $revisionId);
|
||||
|
||||
Activity::add($page, 'page_restore', $page->book->id);
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user