Skip to content

Commit

Permalink
fixing user list bug, added new category 'Draft Help'
Browse files Browse the repository at this point in the history
  • Loading branch information
CaffeineSheep committed Mar 23, 2023
1 parent f56ed3e commit ab9b4be
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 15 deletions.
24 changes: 24 additions & 0 deletions app/Auth/Queries/UsersAllPaginatedAndSorted.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,28 @@ public function run(int $count, SimpleListOptions $listOptions, $limitToContribu

return $query->paginate($count);
}

public function runColl(int $count, SimpleListOptions $listOptions, $limitToContributionActivity = false)
{
$sort = $listOptions->getSort();
if ($sort === 'created_at') {
$sort = 'users.created_at';
}

$query = User::query()->select(['*'])
->withLastActivityAt($limitToContributionActivity)
->with(['roles', 'avatar'])
->withCount('mfaValues')
->orderBy($sort, $listOptions->getOrder());

if ($listOptions->getSearch()) {
$term = '%' . $listOptions->getSearch() . '%';
$query->where(function ($query) use ($term) {
$query->where('name', 'like', $term)
->orWhere('email', 'like', $term);
});
}

return $query->all();
}
}
2 changes: 1 addition & 1 deletion app/Entities/Repos/PageRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function move(Page $page, string $parentIdentifier): Entity
throw new MoveOperationException('Book or chapter to move page into not found');
}

if (!userCan('page-create', $parent) && !($parent->slug === 'community-review' && userCan('page-update', $parent))) {
if (!userCan('page-create', $parent) && !(($parent->slug === 'community-review' || $parent->slug === 'draft-help') && userCan('page-update', $parent))) {
throw new PermissionsException('User does not have permission to create a page within the new parent');
}

Expand Down
9 changes: 9 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public function index(Request $request, ActivityQueries $activities)
// ->select(Page::$listAttributes)
->get();

$latestDraftHelp = Page::getVisiblePagesInBookshelf('contribute')
// ->where('book_id', '=', '5')
->where('book_id', '=', Book::getBySlug('draft-help', true)->id)
->orderBy('created_at', 'desc')
// ->take(3)
// ->select(Page::$listAttributes)
->get();

$latestCommunityReviews = Page::getVisiblePagesInBookshelf('contribute')
// ->where('book_id', '=', '5')
->where('book_id', '=', Book::getBySlug('community-review', true)->id)
Expand Down Expand Up @@ -73,6 +81,7 @@ public function index(Request $request, ActivityQueries $activities)
'activeUsers' => $activeUsers,
'latestDrafts' => $latestDrafts,
'latestCommunityReviews' => $latestCommunityReviews,
'latestDraftHelp' => $latestDraftHelp,
'newSymbols' => $newSymbols,
'quickLinks' => $quickLinks,
'symbolTypesList' => $symbolTypesList,
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public function showMove(string $bookSlug, string $pageSlug)
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-update', $page);

if ($bookSlug !== 'community-review') {
$this->checkOwnablePermission('page-delete', $page);
}
// if ($bookSlug !== 'community-review') {
// $this->checkOwnablePermission('page-delete', $page);
// }

return view('pages.move', [
'book' => $page->book,
Expand All @@ -445,7 +445,7 @@ public function move(Request $request, string $bookSlug, string $pageSlug)
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-update', $page);

if ($bookSlug !== 'community-review') {
if ($bookSlug !== 'community-review' && $bookSlug !== 'draft-help') {
$this->checkOwnablePermission('page-delete', $page);
}

Expand Down
27 changes: 20 additions & 7 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,31 @@ public function showAll(Request $request, ActivityQueries $activities)
{

$listOptions = SimpleListOptions::fromRequest($request, 'users', true)->withSortOptions([
'last_activity_at' => trans('settings.users_latest_activity'),
// 'last_activity_at' => trans('settings.users_latest_activity'),
'name' => trans('common.sort_name')
]);

$users = (new UsersAllPaginatedAndSorted())->run(10, $listOptions, true)
->through(function ($user) use ($activities) {
$user->activity = Arr::first($activities->userActivity($user, 1));
return $user;
});
// $users = (new UsersAllPaginatedAndSorted())->run(10, $listOptions, true)
// ->through(function ($user) use ($activities) {
// $user->activity = Arr::first($activities->userActivity($user, 1));
// return $user;
// });
$users = (new UsersAllPaginatedAndSorted())->run(10, $listOptions, true);
// $users1 = new UsersAllPaginatedAndSorted();

// $users2 = $users1->runColl(5, $listOptions, true);

// // $users = $users2->paginate(5);

// $users = $users2->through(function ($user) use ($activities) {
// $user->activity = Arr::first($activities->userActivity($user, 1));
// return $user;
// });

return view('users.list', [
'title' => 'All '.max(count($users) - 1, 0).' Users',
// 'title' => 'All '.max(count($users) - 1, 0).' Users',
'title' => 'All '.$users->total().' Users',
// 'users' => $users,
'users' => $users,
'skippedUserIds' => [User::getDefault()->id],
'listOptions' => $listOptions,
Expand Down
16 changes: 14 additions & 2 deletions resources/views/home/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
])
</div>
</div>
</div>
<div>
<div id="recent-pages" class="card mb-xl">
<h3 class="card-title">Newest Symbols 🌅</h3>
<div id="recently-updated-pages" class="px-m">
Expand All @@ -60,6 +58,8 @@
<a href="/pages/newest-symbols"
class="card-footer-link">{{ trans('common.view_all') }}</a>
</div>
</div>
<div>
<div id="recent-pages" class="card mb-xl">
<h3 class="card-title">Ready For Review 🤓</h3>
<div id="recently-updated-pages" class="px-m">
Expand All @@ -72,6 +72,18 @@ class="card-footer-link">{{ trans('common.view_all') }}</a>
<a href="{{ url('/books/community-review') }}"
class="card-footer-link">{{ trans('common.view_all') }}</a>
</div>
<div id="recent-pages" class="card mb-xl">
<h3 class="card-title">Looking for help 🙋‍♂️</h3>
<div id="recently-updated-pages" class="px-m">
@include('entities.list', [
'entities' => $latestDrafts,
'style' => 'compact',
'emptyText' => trans('entities.no_pages_recently_updated'),
])
</div>
<a href="{{ url('/pages/drafts-recently-updated') }}"
class="card-footer-link">{{ trans('common.view_all') }}</a>
</div>
</div>
<div>
<div id="recent-activity">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@include('entities.list-item', [
'entity' => $entity,
'showPath' => true,
'locked' => $permission !== 'view' && !userCan($permission, $entity) && (($entity->slug !== 'community-review' && userCan('page-update', $entity)) || ($entity->slug == 'general' && !userCan('page-update', $entity))) && $entity instanceof \BookStack\Entities\Models\Book
'locked' => $permission !== 'view' && !userCan($permission, $entity) && ((($entity->slug !== 'community-review' && $entity->slug !== 'draft-help') && userCan('page-update', $entity)) || ($entity->slug == 'general' && !userCan('page-update', $entity))) && $entity instanceof \BookStack\Entities\Models\Book
])

@if($index !== count($entities) - 1)
Expand Down

0 comments on commit ab9b4be

Please sign in to comment.