User import is now a popover
This commit is contained in:
@@ -176,7 +176,7 @@ class Config extends BaseController
|
|||||||
public function downloadDb()
|
public function downloadDb()
|
||||||
{
|
{
|
||||||
$this->checkCSRFParam();
|
$this->checkCSRFParam();
|
||||||
$this->response->withDownload('db.sqlite.gz');
|
$this->response->withFileDownload('db.sqlite.gz');
|
||||||
$this->response->binary($this->config->downloadDatabase());
|
$this->response->binary($this->config->downloadDatabase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Export extends BaseController
|
|||||||
|
|
||||||
if ($from && $to) {
|
if ($from && $to) {
|
||||||
$data = $this->$model->$method($project['id'], $from, $to);
|
$data = $this->$model->$method($project['id'], $from, $to);
|
||||||
$this->response->withDownload($filename.'.csv');
|
$this->response->withFileDownload($filename.'.csv');
|
||||||
$this->response->csv($data);
|
$this->response->csv($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class FileViewer extends BaseController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$file = $this->getFile();
|
$file = $this->getFile();
|
||||||
$this->response->withDownload($file['name']);
|
$this->response->withFileDownload($file['name']);
|
||||||
$this->objectStorage->output($file['path']);
|
$this->objectStorage->output($file['path']);
|
||||||
} catch (ObjectStorageException $e) {
|
} catch (ObjectStorageException $e) {
|
||||||
$this->logger->error($e->getMessage());
|
$this->logger->error($e->getMessage());
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class TaskImport extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function template()
|
public function template()
|
||||||
{
|
{
|
||||||
$this->response->withDownload('tasks.csv');
|
$this->response->withFileDownload('tasks.csv');
|
||||||
$this->response->csv(array($this->taskImport->getColumnMapping()));
|
$this->response->csv(array($this->taskImport->getColumnMapping()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,40 +7,63 @@ use Kanboard\Core\Csv;
|
|||||||
/**
|
/**
|
||||||
* User Import controller
|
* User Import controller
|
||||||
*
|
*
|
||||||
* @package controller
|
* @package Kanboard\Controller
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class UserImport extends BaseController
|
class UserImportController extends BaseController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Upload the file and ask settings
|
* Upload the file and ask settings
|
||||||
*
|
*
|
||||||
|
* @param array $values
|
||||||
|
* @param array $errors
|
||||||
*/
|
*/
|
||||||
public function step1(array $values = array(), array $errors = array())
|
public function show(array $values = array(), array $errors = array())
|
||||||
{
|
{
|
||||||
$this->response->html($this->helper->layout->app('user_import/step1', array(
|
$this->response->html($this->template->render('user_import/show', array(
|
||||||
'values' => $values,
|
'values' => $values,
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
'max_size' => ini_get('upload_max_filesize'),
|
'max_size' => ini_get('upload_max_filesize'),
|
||||||
'delimiters' => Csv::getDelimiters(),
|
'delimiters' => Csv::getDelimiters(),
|
||||||
'enclosures' => Csv::getEnclosures(),
|
'enclosures' => Csv::getEnclosures(),
|
||||||
'title' => t('Import users from CSV file'),
|
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process CSV file
|
* Submit form
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function step2()
|
public function save()
|
||||||
{
|
{
|
||||||
$values = $this->request->getValues();
|
$values = $this->request->getValues();
|
||||||
$filename = $this->request->getFilePath('file');
|
$filename = $this->request->getFilePath('file');
|
||||||
|
|
||||||
if (! file_exists($filename)) {
|
if (! file_exists($filename)) {
|
||||||
$this->step1($values, array('file' => array(t('Unable to read your file'))));
|
$this->flash->failure(t('Unable to read your file'));
|
||||||
|
} else {
|
||||||
|
$this->importFile($values, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->response->redirect($this->helper->url->to('user', 'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate template
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function template()
|
||||||
|
{
|
||||||
|
$this->response->withFileDownload('users.csv');
|
||||||
|
$this->response->csv(array($this->userImport->getColumnMapping()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process file
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
* @param $filename
|
||||||
|
*/
|
||||||
|
private function importFile(array $values, $filename)
|
||||||
|
{
|
||||||
$csv = new Csv($values['delimiter'], $values['enclosure']);
|
$csv = new Csv($values['delimiter'], $values['enclosure']);
|
||||||
$csv->setColumnMapping($this->userImport->getColumnMapping());
|
$csv->setColumnMapping($this->userImport->getColumnMapping());
|
||||||
$csv->read($filename, array($this->userImport, 'import'));
|
$csv->read($filename, array($this->userImport, 'import'));
|
||||||
@@ -50,17 +73,5 @@ class UserImport extends BaseController
|
|||||||
} else {
|
} else {
|
||||||
$this->flash->failure(t('Nothing have been imported!'));
|
$this->flash->failure(t('Nothing have been imported!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response->redirect($this->helper->url->to('userImport', 'step1'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate template
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function template()
|
|
||||||
{
|
|
||||||
$this->response->withDownload('users.csv');
|
|
||||||
$this->response->csv(array($this->userImport->getColumnMapping()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ class Response extends Base
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function withDownload($filename)
|
public function withFileDownload($filename)
|
||||||
{
|
{
|
||||||
$this->withHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
|
$this->withHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
|
||||||
$this->withHeader('Content-Transfer-Encoding', 'binary');
|
$this->withHeader('Content-Transfer-Encoding', 'binary');
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class AuthenticationProvider implements ServiceProviderInterface
|
|||||||
$acl->add('ProjectCreation', 'create', Role::APP_MANAGER);
|
$acl->add('ProjectCreation', 'create', Role::APP_MANAGER);
|
||||||
$acl->add('Projectuser', '*', Role::APP_MANAGER);
|
$acl->add('Projectuser', '*', Role::APP_MANAGER);
|
||||||
$acl->add('Twofactor', 'disable', Role::APP_ADMIN);
|
$acl->add('Twofactor', 'disable', Role::APP_ADMIN);
|
||||||
$acl->add('UserImport', '*', Role::APP_ADMIN);
|
$acl->add('UserImportController', '*', Role::APP_ADMIN);
|
||||||
$acl->add('User', array('index', 'create', 'save', 'authentication'), Role::APP_ADMIN);
|
$acl->add('User', array('index', 'create', 'save', 'authentication'), Role::APP_ADMIN);
|
||||||
$acl->add('UserStatus', '*', Role::APP_ADMIN);
|
$acl->add('UserStatus', '*', Role::APP_ADMIN);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li>
|
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li>
|
||||||
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li>
|
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li>
|
||||||
<li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'userImport', 'step1') ?></li>
|
<li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?></li>
|
||||||
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
|
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|||||||
41
app/Template/user_import/show.php
Normal file
41
app/Template/user_import/show.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<div class="page-header">
|
||||||
|
<h2><?= t('Import users from CSV file') ?></h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<i class="fa fa-download fa-fw"></i>
|
||||||
|
<?= $this->url->link(t('Download CSV template'), 'UserImportController', 'template') ?>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert">
|
||||||
|
<ul>
|
||||||
|
<li><?= t('Your file must use the predefined CSV format') ?></li>
|
||||||
|
<li><?= t('Your file must be encoded in UTF-8') ?></li>
|
||||||
|
<li><?= t('The first row must be the header') ?></li>
|
||||||
|
<li><?= t('Duplicates are not imported') ?></li>
|
||||||
|
<li><?= t('Usernames must be lowercase and unique') ?></li>
|
||||||
|
<li><?= t('Passwords will be encrypted if present') ?></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="<?= $this->url->href('UserImportController', 'save') ?>" method="post" enctype="multipart/form-data">
|
||||||
|
<?= $this->form->csrf() ?>
|
||||||
|
|
||||||
|
<?= $this->form->label(t('Delimiter'), 'delimiter') ?>
|
||||||
|
<?= $this->form->select('delimiter', $delimiters, $values) ?>
|
||||||
|
|
||||||
|
<?= $this->form->label(t('Enclosure'), 'enclosure') ?>
|
||||||
|
<?= $this->form->select('enclosure', $enclosures, $values) ?>
|
||||||
|
|
||||||
|
<?= $this->form->label(t('CSV File'), 'file') ?>
|
||||||
|
<?= $this->form->file('file', $errors) ?>
|
||||||
|
|
||||||
|
<p class="form-help"><?= t('Maximum size: ') ?><?= is_integer($max_size) ? $this->text->bytes($max_size) : $max_size ?></p>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-blue"><?= t('Import') ?></button>
|
||||||
|
<?= t('or') ?>
|
||||||
|
<?= $this->url->link(t('cancel'), 'user', 'index', array(), false, 'close-popover') ?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<section id="main">
|
|
||||||
<div class="page-header">
|
|
||||||
<?php if ($this->user->hasAccess('user', 'create')): ?>
|
|
||||||
<ul>
|
|
||||||
<li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('All users'), 'user', 'index') ?></li>
|
|
||||||
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li>
|
|
||||||
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li>
|
|
||||||
</ul>
|
|
||||||
<?php endif ?>
|
|
||||||
</div>
|
|
||||||
<div class="page-header">
|
|
||||||
<h2><?= t('Import') ?></h2>
|
|
||||||
</div>
|
|
||||||
<form action="<?= $this->url->href('userImport', 'step2') ?>" method="post" enctype="multipart/form-data">
|
|
||||||
<?= $this->form->csrf() ?>
|
|
||||||
|
|
||||||
<?= $this->form->label(t('Delimiter'), 'delimiter') ?>
|
|
||||||
<?= $this->form->select('delimiter', $delimiters, $values) ?>
|
|
||||||
|
|
||||||
<?= $this->form->label(t('Enclosure'), 'enclosure') ?>
|
|
||||||
<?= $this->form->select('enclosure', $enclosures, $values) ?>
|
|
||||||
|
|
||||||
<?= $this->form->label(t('CSV File'), 'file') ?>
|
|
||||||
<?= $this->form->file('file', $errors) ?>
|
|
||||||
|
|
||||||
<p class="form-help"><?= t('Maximum size: ') ?><?= is_integer($max_size) ? $this->text->bytes($max_size) : $max_size ?></p>
|
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="submit" class="btn btn-blue"><?= t('Import') ?></button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div class="page-header">
|
|
||||||
<h2><?= t('Instructions') ?></h2>
|
|
||||||
</div>
|
|
||||||
<div class="alert">
|
|
||||||
<ul>
|
|
||||||
<li><?= t('Your file must use the predefined CSV format') ?></li>
|
|
||||||
<li><?= t('Your file must be encoded in UTF-8') ?></li>
|
|
||||||
<li><?= t('The first row must be the header') ?></li>
|
|
||||||
<li><?= t('Duplicates are not imported') ?></li>
|
|
||||||
<li><?= t('Usernames must be lowercase and unique') ?></li>
|
|
||||||
<li><?= t('Passwords will be encrypted if present') ?></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<p><i class="fa fa-download fa-fw"></i><?= $this->url->link(t('Download CSV template'), 'userImport', 'template') ?></p>
|
|
||||||
</section>
|
|
||||||
Reference in New Issue
Block a user