зеркало из https://github.com/nextcloud/spreed.git
Prevent duplicate room names.
This commit is contained in:
Родитель
95159f7bda
Коммит
e51d236bae
|
@ -50,6 +50,15 @@
|
|||
<notnull>true</notnull>
|
||||
<length>255</length>
|
||||
</field>
|
||||
|
||||
<index>
|
||||
<name>spreedme_rooms_name_index</name>
|
||||
<unique>true</unique>
|
||||
<field>
|
||||
<name>name</name>
|
||||
<sorting>ascending</sorting>
|
||||
</field>
|
||||
</index>
|
||||
</declaration>
|
||||
</table>
|
||||
<table>
|
||||
|
@ -84,4 +93,4 @@
|
|||
</index>
|
||||
</declaration>
|
||||
</table>
|
||||
</database>
|
||||
</database>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<licence>AGPLv3+</licence>
|
||||
<author>Lukas Reschke, Jan-Christoph Borchardt</author>
|
||||
<default_enable/>
|
||||
<version>1.0.6</version>
|
||||
<version>1.0.7</version>
|
||||
<dependencies>
|
||||
<owncloud min-version="9.1" max-version="9.2" />
|
||||
</dependencies>
|
||||
|
|
19
js/rooms.js
19
js/rooms.js
|
@ -1,4 +1,10 @@
|
|||
(function(OCA) {
|
||||
$(document).ready(function() {
|
||||
|
||||
var editRoomname = $('#edit-roomname');
|
||||
editRoomname.keyup(function() {
|
||||
editRoomname.tooltip('hide');
|
||||
editRoomname.removeClass('error');
|
||||
});
|
||||
|
||||
OCA.SpreedMe = OCA.SpreedMe || {};
|
||||
var currentRoomId = 0;
|
||||
|
@ -11,6 +17,14 @@
|
|||
roomName: roomName
|
||||
},
|
||||
function(data) {
|
||||
if (data.status !== 'success') {
|
||||
editRoomname.prop('title', data.message);
|
||||
editRoomname.tooltip({placement: 'right', trigger: 'manual'});
|
||||
editRoomname.tooltip('show');
|
||||
editRoomname.addClass('error');
|
||||
return;
|
||||
}
|
||||
|
||||
var roomId = data.roomId;
|
||||
OCA.SpreedMe.Rooms.join(roomId);
|
||||
}
|
||||
|
@ -54,4 +68,5 @@
|
|||
);
|
||||
}
|
||||
}
|
||||
})(OCA);
|
||||
|
||||
});
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
|
||||
namespace OCA\Spreed\Controller;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
||||
class ApiController extends Controller {
|
||||
|
@ -33,6 +35,8 @@ class ApiController extends Controller {
|
|||
private $userId;
|
||||
/** @var IDBConnection */
|
||||
private $dbConnection;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
|
@ -43,10 +47,12 @@ class ApiController extends Controller {
|
|||
public function __construct($appName,
|
||||
$UserId,
|
||||
IRequest $request,
|
||||
IDBConnection $dbConnection) {
|
||||
IDBConnection $dbConnection,
|
||||
IL10N $l10n) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->userId = $UserId;
|
||||
$this->dbConnection = $dbConnection;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,17 +132,29 @@ class ApiController extends Controller {
|
|||
* @return JSONResponse
|
||||
*/
|
||||
public function createRoom($roomName) {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert('spreedme_rooms')
|
||||
$query = $this->dbConnection->getQueryBuilder();
|
||||
$query->insert('spreedme_rooms')
|
||||
->values(
|
||||
[
|
||||
'name' => $qb->createNamedParameter($roomName),
|
||||
'name' => $query->createNamedParameter($roomName),
|
||||
]
|
||||
)->execute();
|
||||
);
|
||||
|
||||
try {
|
||||
$query->execute();
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
return new JSONResponse(
|
||||
[
|
||||
'status' => 'error',
|
||||
'message' => $this->l10n->t('A room with this name already exists.'),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return new JSONResponse(
|
||||
[
|
||||
'roomId' => $qb->getLastInsertId(),
|
||||
'status' => 'success',
|
||||
'roomId' => $query->getLastInsertId(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ script(
|
|||
<div id="app" data-sessionId="<?php p($_['sessionId']) ?>">
|
||||
<div id="app-navigation" class="icon-loading">
|
||||
<form id="oca-spreedme-add-room">
|
||||
<input type="text" placeholder="<?php p($l->t('Choose room name …')) ?>"/>
|
||||
<input id="edit-roomname" type="text" placeholder="<?php p($l->t('Choose room name …')) ?>"/>
|
||||
<button class="icon-confirm" title="<?php p($l->t('Create new room')) ?>"></button>
|
||||
</form>
|
||||
<ul>
|
||||
|
|
Загрузка…
Ссылка в новой задаче