summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-15 21:20:46 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-15 21:20:46 -0400
commit20052c7dd295464c7782350628701675b1f07db7 (patch)
tree5eb416262114feb864694ae05a3c04667f54f727 /app
parent4eaab1f6da1a56376a840231f7b8a10469308f97 (diff)
User import is now a popover
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Config.php2
-rw-r--r--app/Controller/Export.php2
-rw-r--r--app/Controller/FileViewer.php2
-rw-r--r--app/Controller/TaskImport.php2
-rw-r--r--app/Controller/UserImportController.php (renamed from app/Controller/UserImport.php)51
-rw-r--r--app/Core/Http/Response.php2
-rw-r--r--app/ServiceProvider/AuthenticationProvider.php2
-rw-r--r--app/Template/user/index.php2
-rw-r--r--app/Template/user_import/show.php41
-rw-r--r--app/Template/user_import/step1.php46
10 files changed, 79 insertions, 73 deletions
diff --git a/app/Controller/Config.php b/app/Controller/Config.php
index ebb541d2..deafd05b 100644
--- a/app/Controller/Config.php
+++ b/app/Controller/Config.php
@@ -176,7 +176,7 @@ class Config extends BaseController
public function downloadDb()
{
$this->checkCSRFParam();
- $this->response->withDownload('db.sqlite.gz');
+ $this->response->withFileDownload('db.sqlite.gz');
$this->response->binary($this->config->downloadDatabase());
}
diff --git a/app/Controller/Export.php b/app/Controller/Export.php
index f5783b72..7e1d2fdc 100644
--- a/app/Controller/Export.php
+++ b/app/Controller/Export.php
@@ -29,7 +29,7 @@ class Export extends BaseController
if ($from && $to) {
$data = $this->$model->$method($project['id'], $from, $to);
- $this->response->withDownload($filename.'.csv');
+ $this->response->withFileDownload($filename.'.csv');
$this->response->csv($data);
}
diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php
index a990e12a..52ff0d0e 100644
--- a/app/Controller/FileViewer.php
+++ b/app/Controller/FileViewer.php
@@ -123,7 +123,7 @@ class FileViewer extends BaseController
{
try {
$file = $this->getFile();
- $this->response->withDownload($file['name']);
+ $this->response->withFileDownload($file['name']);
$this->objectStorage->output($file['path']);
} catch (ObjectStorageException $e) {
$this->logger->error($e->getMessage());
diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php
index 5dbf8678..5e37fb2f 100644
--- a/app/Controller/TaskImport.php
+++ b/app/Controller/TaskImport.php
@@ -69,7 +69,7 @@ class TaskImport extends BaseController
*/
public function template()
{
- $this->response->withDownload('tasks.csv');
+ $this->response->withFileDownload('tasks.csv');
$this->response->csv(array($this->taskImport->getColumnMapping()));
}
}
diff --git a/app/Controller/UserImport.php b/app/Controller/UserImportController.php
index b99e56a0..b3cb52d1 100644
--- a/app/Controller/UserImport.php
+++ b/app/Controller/UserImportController.php
@@ -7,51 +7,43 @@ use Kanboard\Core\Csv;
/**
* User Import controller
*
- * @package controller
+ * @package Kanboard\Controller
* @author Frederic Guillot
*/
-class UserImport extends BaseController
+class UserImportController extends BaseController
{
/**
* 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,
'errors' => $errors,
'max_size' => ini_get('upload_max_filesize'),
'delimiters' => Csv::getDelimiters(),
'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();
$filename = $this->request->getFilePath('file');
if (! file_exists($filename)) {
- $this->step1($values, array('file' => array(t('Unable to read your file'))));
- }
-
- $csv = new Csv($values['delimiter'], $values['enclosure']);
- $csv->setColumnMapping($this->userImport->getColumnMapping());
- $csv->read($filename, array($this->userImport, 'import'));
-
- if ($this->userImport->counter > 0) {
- $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
+ $this->flash->failure(t('Unable to read your file'));
} else {
- $this->flash->failure(t('Nothing have been imported!'));
+ $this->importFile($values, $filename);
}
- $this->response->redirect($this->helper->url->to('userImport', 'step1'));
+ $this->response->redirect($this->helper->url->to('user', 'index'));
}
/**
@@ -60,7 +52,26 @@ class UserImport extends BaseController
*/
public function template()
{
- $this->response->withDownload('users.csv');
+ $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->setColumnMapping($this->userImport->getColumnMapping());
+ $csv->read($filename, array($this->userImport, 'import'));
+
+ if ($this->userImport->counter > 0) {
+ $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
+ } else {
+ $this->flash->failure(t('Nothing have been imported!'));
+ }
+ }
}
diff --git a/app/Core/Http/Response.php b/app/Core/Http/Response.php
index fd67ec95..1c5310d0 100644
--- a/app/Core/Http/Response.php
+++ b/app/Core/Http/Response.php
@@ -172,7 +172,7 @@ class Response extends Base
* @param string $filename
* @return $this
*/
- public function withDownload($filename)
+ public function withFileDownload($filename)
{
$this->withHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
$this->withHeader('Content-Transfer-Encoding', 'binary');
diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php
index b9082c26..8baa02ea 100644
--- a/app/ServiceProvider/AuthenticationProvider.php
+++ b/app/ServiceProvider/AuthenticationProvider.php
@@ -137,7 +137,7 @@ class AuthenticationProvider implements ServiceProviderInterface
$acl->add('ProjectCreation', 'create', Role::APP_MANAGER);
$acl->add('Projectuser', '*', Role::APP_MANAGER);
$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('UserStatus', '*', Role::APP_ADMIN);
diff --git a/app/Template/user/index.php b/app/Template/user/index.php
index 0b5da17c..00cd0c82 100644
--- a/app/Template/user/index.php
+++ b/app/Template/user/index.php
@@ -4,7 +4,7 @@
<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 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>
</ul>
<?php endif ?>
diff --git a/app/Template/user_import/show.php b/app/Template/user_import/show.php
new file mode 100644
index 00000000..54a66237
--- /dev/null
+++ b/app/Template/user_import/show.php
@@ -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>
diff --git a/app/Template/user_import/step1.php b/app/Template/user_import/step1.php
deleted file mode 100644
index 592587a3..00000000
--- a/app/Template/user_import/step1.php
+++ /dev/null
@@ -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> \ No newline at end of file