-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6835 from getkirby/v5/lock-response
New LockException and Lock Dialog
- Loading branch information
Showing
8 changed files
with
223 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<k-dialog | ||
ref="dialog" | ||
v-bind="$props" | ||
:cancel-button="false" | ||
:submit-button="{ theme: 'passive' }" | ||
class="k-lock-alert-dialog" | ||
@cancel="$emit('cancel')" | ||
@submit="$emit('submit')" | ||
> | ||
<k-dialog-text :text="$t('form.locked')" /> | ||
|
||
<dl> | ||
<div> | ||
<dt><k-icon type="user" /></dt> | ||
<dd>{{ lock.user.email }}</dd> | ||
</div> | ||
<div> | ||
<dt><k-icon type="clock" /></dt> | ||
<dd> | ||
{{ $library.dayjs(lock.modified).format("YYYY-MM-DD HH:mm:ss") }} | ||
</dd> | ||
</div> | ||
</dl> | ||
</k-dialog> | ||
</template> | ||
|
||
<script> | ||
import Dialog from "@/mixins/dialog.js"; | ||
export const props = { | ||
mixins: [Dialog], | ||
props: { | ||
cancelButton: null, | ||
submitButton: null, | ||
lock: Object, | ||
preview: String | ||
} | ||
}; | ||
export default { | ||
mixins: [props] | ||
}; | ||
</script> | ||
|
||
<style> | ||
.k-lock-alert-dialog dl { | ||
margin: var(--spacing-6) 0 var(--spacing-2) 0; | ||
} | ||
.k-lock-alert-dialog dl div { | ||
padding: var(--spacing-1) 0; | ||
line-height: var(--leading-normal); | ||
display: flex; | ||
align-items: center; | ||
gap: 0.75rem; | ||
color: var(--color-gray-500); | ||
} | ||
.k-lock-alert-dialog .k-dialog-buttons { | ||
grid-template-columns: 1fr; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Kirby\Content; | ||
|
||
use Kirby\Exception\LogicException; | ||
|
||
/** | ||
* @package Kirby Content | ||
* @author Bastian Allgeier <[email protected]> | ||
* @link https://getkirby.com | ||
* @copyright Bastian Allgeier | ||
* @license https://getkirby.com/license | ||
*/ | ||
class LockedContentException extends LogicException | ||
{ | ||
protected static string $defaultKey = 'content.lock'; | ||
protected static string $defaultFallback = 'The version is locked'; | ||
protected static int $defaultHttpCode = 423; | ||
|
||
public function __construct( | ||
Lock $lock, | ||
string|null $key = null, | ||
string|null $message = null, | ||
) { | ||
parent::__construct( | ||
message: $message, | ||
key: $key, | ||
details: $lock->toArray() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Kirby\Content; | ||
|
||
use Kirby\Cms\User; | ||
|
||
/** | ||
* @coversDefaultClass \Kirby\Content\LockedContentException | ||
*/ | ||
class LockedContentExceptionTest extends TestCase | ||
{ | ||
public function testException() | ||
{ | ||
$lock = new Lock( | ||
user: new User(['username' => 'test']), | ||
modified: $time = time() | ||
); | ||
|
||
$exception = new LockedContentException( | ||
lock: $lock | ||
); | ||
|
||
$this->assertSame('The version is locked', $exception->getMessage()); | ||
$this->assertSame($lock->toArray(), $exception->getDetails()); | ||
$this->assertSame(423, $exception->getHttpCode()); | ||
$this->assertSame('error.content.lock', $exception->getKey()); | ||
} | ||
|
||
public function testCustomMessage() | ||
{ | ||
$lock = new Lock( | ||
user: new User(['username' => 'test']), | ||
modified: $time = time() | ||
); | ||
|
||
$exception = new LockedContentException( | ||
lock: $lock, | ||
message: $message = 'The version is locked and cannot be deleted' | ||
); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
} |
Oops, something went wrong.