Skip to content

Commit 789693b

Browse files
committed
Merge branch 'v0.8' into release
2 parents 1fe933e + 8b109ba commit 789693b

18 files changed

+219
-63
lines changed

app/Http/routes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
Route::delete('/{id}', 'BookController@destroy');
2020
Route::get('/{slug}/sort-item', 'BookController@getSortItem');
2121
Route::get('/{slug}', 'BookController@show');
22-
Route::get('/{bookSlug}/restrict', 'BookController@showRestrict');
23-
Route::put('/{bookSlug}/restrict', 'BookController@restrict');
22+
Route::get('/{bookSlug}/permissions', 'BookController@showRestrict');
23+
Route::put('/{bookSlug}/permissions', 'BookController@restrict');
2424
Route::get('/{slug}/delete', 'BookController@showDelete');
2525
Route::get('/{bookSlug}/sort', 'BookController@sort');
2626
Route::put('/{bookSlug}/sort', 'BookController@saveSort');
@@ -36,8 +36,8 @@
3636
Route::get('/{bookSlug}/page/{pageSlug}/edit', 'PageController@edit');
3737
Route::get('/{bookSlug}/page/{pageSlug}/delete', 'PageController@showDelete');
3838
Route::get('/{bookSlug}/draft/{pageId}/delete', 'PageController@showDeleteDraft');
39-
Route::get('/{bookSlug}/page/{pageSlug}/restrict', 'PageController@showRestrict');
40-
Route::put('/{bookSlug}/page/{pageSlug}/restrict', 'PageController@restrict');
39+
Route::get('/{bookSlug}/page/{pageSlug}/permissions', 'PageController@showRestrict');
40+
Route::put('/{bookSlug}/page/{pageSlug}/permissions', 'PageController@restrict');
4141
Route::put('/{bookSlug}/page/{pageSlug}', 'PageController@update');
4242
Route::delete('/{bookSlug}/page/{pageSlug}', 'PageController@destroy');
4343
Route::delete('/{bookSlug}/draft/{pageId}', 'PageController@destroyDraft');
@@ -54,8 +54,8 @@
5454
Route::get('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@show');
5555
Route::put('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@update');
5656
Route::get('/{bookSlug}/chapter/{chapterSlug}/edit', 'ChapterController@edit');
57-
Route::get('/{bookSlug}/chapter/{chapterSlug}/restrict', 'ChapterController@showRestrict');
58-
Route::put('/{bookSlug}/chapter/{chapterSlug}/restrict', 'ChapterController@restrict');
57+
Route::get('/{bookSlug}/chapter/{chapterSlug}/permissions', 'ChapterController@showRestrict');
58+
Route::put('/{bookSlug}/chapter/{chapterSlug}/permissions', 'ChapterController@restrict');
5959
Route::get('/{bookSlug}/chapter/{chapterSlug}/delete', 'ChapterController@showDelete');
6060
Route::delete('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@destroy');
6161

app/Services/RestrictionService.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ public function checkIfEntityRestricted(Entity $entity, $action)
4141
return false;
4242
}
4343

44+
/**
45+
* Check if an entity has restrictions set on itself or its
46+
* parent tree.
47+
* @param Entity $entity
48+
* @param $action
49+
* @return bool|mixed
50+
*/
51+
public function checkIfRestrictionsSet(Entity $entity, $action)
52+
{
53+
$this->currentAction = $action;
54+
if ($entity->isA('page')) {
55+
return $entity->restricted || ($entity->chapter && $entity->chapter->restricted) || $entity->book->restricted;
56+
} elseif ($entity->isA('chapter')) {
57+
return $entity->restricted || $entity->book->restricted;
58+
} elseif ($entity->isA('book')) {
59+
return $entity->restricted;
60+
}
61+
}
62+
4463
/**
4564
* Add restrictions for a page query
4665
* @param $query

app/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,19 @@ public function getEditUrl()
162162
{
163163
return '/settings/users/' . $this->id;
164164
}
165+
166+
/**
167+
* Get a shortened version of the user's name.
168+
* @param int $chars
169+
* @return string
170+
*/
171+
public function getShortName($chars = 8)
172+
{
173+
if (strlen($this->name) <= $chars) return $this->name;
174+
175+
$splitName = explode(' ', $this->name);
176+
if (strlen($splitName[0]) <= $chars) return $splitName[0];
177+
178+
return '';
179+
}
165180
}

app/helpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ function userCan($permission, \BookStack\Ownable $ownable = null)
5252

5353
if (!$ownable instanceof \BookStack\Entity) return $hasPermission;
5454

55-
// Check restrictions on the entitiy
55+
// Check restrictions on the entity
5656
$restrictionService = app('BookStack\Services\RestrictionService');
5757
$explodedPermission = explode('-', $permission);
5858
$action = end($explodedPermission);
5959
$hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action);
60-
return $hasAccess && $hasPermission;
60+
$restrictionsSet = $restrictionService->checkIfRestrictionsSet($ownable, $action);
61+
return ($hasAccess && $restrictionsSet) || (!$restrictionsSet && $hasPermission);
6162
}
6263

6364
/**

resources/assets/sass/_header.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,14 @@ header {
5656
padding-top: $-xxs;
5757
}
5858
> i {
59-
padding-top: $-xs*1.2;
59+
padding-top: 4px;
60+
font-size: 18px;
6061
}
6162
@include smaller-than($screen-md) {
6263
padding-left: $-xs;
6364
.name {
6465
display: none;
6566
}
66-
i {
67-
font-size: 2em;
68-
padding-left: 0;
69-
padding-top: 0;
70-
}
7167
}
7268
}
7369
@include smaller-than($screen-md) {

resources/views/base.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<div class="dropdown-container" dropdown>
5757
<span class="user-name" dropdown-toggle>
5858
<img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}">
59-
<span class="name" ng-non-bindable>{{ $currentUser->name }}</span> <i class="zmdi zmdi-caret-down"></i>
59+
<span class="name" ng-non-bindable>{{ $currentUser->getShortName(9) }}</span> <i class="zmdi zmdi-caret-down"></i>
6060
</span>
6161
<ul>
6262
<li>

resources/views/books/restrictions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
<div class="container" ng-non-bindable>
19-
<h1>Book Restrictions</h1>
19+
<h1>Book Permissions</h1>
2020
@include('form/restriction-form', ['model' => $book])
2121
</div>
2222

resources/views/books/show.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<li><a href="{{ $book->getUrl() }}/sort" class="text-primary"><i class="zmdi zmdi-sort"></i>Sort</a></li>
2525
@endif
2626
@if(userCan('restrictions-manage', $book))
27-
<li><a href="{{$book->getUrl()}}/restrict" class="text-primary"><i class="zmdi zmdi-lock-outline"></i>Restrict</a></li>
27+
<li><a href="{{$book->getUrl()}}/permissions" class="text-primary"><i class="zmdi zmdi-lock-outline"></i>Permissions</a></li>
2828
@endif
2929
@if(userCan('book-delete', $book))
3030
<li><a href="{{ $book->getUrl() }}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete</a></li>
@@ -90,9 +90,9 @@
9090
@if($book->restricted)
9191
<p class="text-muted">
9292
@if(userCan('restrictions-manage', $book))
93-
<a href="{{ $book->getUrl() }}/restrict"><i class="zmdi zmdi-lock-outline"></i>Book Restricted</a>
93+
<a href="{{ $book->getUrl() }}/permissions"><i class="zmdi zmdi-lock-outline"></i>Book Permissions Active</a>
9494
@else
95-
<i class="zmdi zmdi-lock-outline"></i>Book Restricted
95+
<i class="zmdi zmdi-lock-outline"></i>Book Permissions Active
9696
@endif
9797
</p>
9898
@endif

resources/views/chapters/restrictions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818

1919
<div class="container" ng-non-bindable>
20-
<h1>Chapter Restrictions</h1>
20+
<h1>Chapter Permissions</h1>
2121
@include('form/restriction-form', ['model' => $chapter])
2222
</div>
2323

resources/views/chapters/show.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<a href="{{$chapter->getUrl() . '/edit'}}" class="text-primary text-button"><i class="zmdi zmdi-edit"></i>Edit</a>
2020
@endif
2121
@if(userCan('restrictions-manage', $chapter))
22-
<a href="{{$chapter->getUrl()}}/restrict" class="text-primary text-button"><i class="zmdi zmdi-lock-outline"></i>Restrict</a>
22+
<a href="{{$chapter->getUrl()}}/permissions" class="text-primary text-button"><i class="zmdi zmdi-lock-outline"></i>Permissions</a>
2323
@endif
2424
@if(userCan('chapter-delete', $chapter))
2525
<a href="{{$chapter->getUrl() . '/delete'}}" class="text-neg text-button"><i class="zmdi zmdi-delete"></i>Delete</a>
@@ -69,18 +69,18 @@
6969

7070
@if($book->restricted)
7171
@if(userCan('restrictions-manage', $book))
72-
<a href="{{ $book->getUrl() }}/restrict"><i class="zmdi zmdi-lock-outline"></i>Book Restricted</a>
72+
<a href="{{ $book->getUrl() }}/permissions"><i class="zmdi zmdi-lock-outline"></i>Book Permissions Active</a>
7373
@else
74-
<i class="zmdi zmdi-lock-outline"></i>Book Restricted
74+
<i class="zmdi zmdi-lock-outline"></i>Book Permissions Active
7575
@endif
7676
<br>
7777
@endif
7878

7979
@if($chapter->restricted)
8080
@if(userCan('restrictions-manage', $chapter))
81-
<a href="{{ $chapter->getUrl() }}/restrict"><i class="zmdi zmdi-lock-outline"></i>Chapter Restricted</a>
81+
<a href="{{ $chapter->getUrl() }}/permissions"><i class="zmdi zmdi-lock-outline"></i>Chapter Permissions Active</a>
8282
@else
83-
<i class="zmdi zmdi-lock-outline"></i>Chapter Restricted
83+
<i class="zmdi zmdi-lock-outline"></i>Chapter Permissions Active
8484
@endif
8585
@endif
8686
</div>

0 commit comments

Comments
 (0)