Merge branch 'master' into PHRAS-2741-worker-service-part1

This commit is contained in:
Nicolas Maillat
2020-03-16 15:42:48 +01:00
committed by GitHub
63 changed files with 11705 additions and 1250 deletions

View File

@@ -246,6 +246,7 @@ class UserApplicationsCommand extends Command
$account->getUser()->getId(),
$application->getName(),
$application->getClientId(),
$application->getClientSecret(),
$application->getRedirectUri(),
($token) ? $token->getOauthToken() : '-',
$application->isPasswordGranted() ? "true": "false"
@@ -253,7 +254,7 @@ class UserApplicationsCommand extends Command
}
$applicationTable = $this->getHelperSet()->get('table');
$headers = ['app_id', 'user_id', 'name', 'client_id', 'callback_url', 'generated token', 'grant_password status'];
$headers = ['app_id', 'user_id', 'name', 'client_id', 'client_secret', 'callback_url', 'generated token', 'grant_password status'];
if ($jsonformat ) {
foreach ($applicationList as $appList) {
@@ -312,7 +313,7 @@ class UserApplicationsCommand extends Command
$application->isPasswordGranted() ? "true": "false"
];
$headers = ['client secret', 'client ID', 'Authorize endpoint url', 'Access endpoint', 'generated token', 'grant_password status'];
$headers = ['client_secret', 'client_id', 'Authorize endpoint url', 'Access endpoint', 'generated token', 'grant_password status'];
if ($jsonformat ) {
$createdAppInfo = array_combine($headers, $applicationCreated);
echo json_encode($createdAppInfo);

View File

@@ -30,8 +30,8 @@ class UserListCommand extends Command
{
parent::__construct('user:list');
$this->setDescription('List of all user (experimental)')
->addOption('user_id', null, InputOption::VALUE_OPTIONAL, ' The id of user export only info this user ')
$this->setDescription('List of all user <comment>(experimental)</>')
->addOption('user_id', null, InputOption::VALUE_OPTIONAL, 'The id of user export only info this user ')
->addOption('user_email', null, InputOption::VALUE_OPTIONAL, 'The mail of user export only info this user .')
->addOption('database_id', null, InputOption::VALUE_OPTIONAL, 'Id of database.')
->addOption('collection_id', null, InputOption::VALUE_OPTIONAL, 'Id of the collection.')
@@ -39,7 +39,6 @@ class UserListCommand extends Command
->addOption('guest', null, InputOption::VALUE_NONE, 'Only guest user')
->addOption('created', null, InputOption::VALUE_OPTIONAL, 'Created at with operator,aaaa-mm-jj hh:mm:ss.')
->addOption('updated', null, InputOption::VALUE_OPTIONAL, 'Update at with operator,aaaa-mm-jj hh:mm:ss.')
->addOption('application', null, InputOption::VALUE_NONE, 'List application of user work only if --user_id is set')
->addOption('right', null, InputOption::VALUE_NONE, 'Show right information')
->addOption('adress', null, InputOption::VALUE_NONE, 'Show adress information')
->addOption('models', null, InputOption::VALUE_NONE, "Show only defined models, if --user_id is set with --models it's the template owner")
@@ -58,7 +57,6 @@ class UserListCommand extends Command
$collectionId = $input->getOption('collection_id');
$lockStatus = $input->getOption('mail_lock_status');
$guest = $input->getOption('guest');
$application = $input->getOption('application');
$withAdress = $input->getOption('adress');
$created = $input->getOption('created');
$updated = $input->getOption('updated');
@@ -77,11 +75,6 @@ class UserListCommand extends Command
if($lockStatus && !$models) $query->addSqlFilter('Users.mail_locked = 1');
if($guest && !$models) $query->include_invite(true)->addSqlFilter('Users.guest = 1');
if ($application and !$userId) {
$output->writeln('<error>You must provide --user_id when using --application option</error>');
return 0;
}
/** @var UserRepository $userRepository */
$userRepository = $this->container['repo.users'];
@@ -94,11 +87,7 @@ class UserListCommand extends Command
}
$userList = [];
$showApplication = false;
foreach ($users as $key => $user) {
if ($userId and $application) {
$showApplication = true;
}
$userList[] = $this->listUser($user, $withAdress, $withRight);
$userListRaw[] = array_combine($this->headerTable($withAdress, $withRight), $this->listUser($user, $withAdress, $withRight));
@@ -113,15 +102,6 @@ class UserListCommand extends Command
->setRows($userList)
->render($output);
;
if ($showApplication) {
$applicationTable = $this->getHelperSet()->get('table');
$applicationTable->setHeaders(array(
array(new TableCell('Applications', array('colspan' => 5))),
['name','callback','client_secret','client_id','token'],
))->setRows($this->getApplicationOfUser($users[0]))->render($output);
}
}
@@ -215,37 +195,6 @@ class UserListCommand extends Command
];
}
/**
* @param User $user
* @return array
*/
private function getApplicationOfUser(User $user)
{
$apiRepository = $this->container['repo.api-applications'];
$applications = $apiRepository->findByUser($user);
if (empty($applications)) {
return [];
}
$accountRepository = $this->container['repo.api-accounts'];
$apiOauthRepository = $this->container['repo.api-oauth-tokens'];
$usersApplication = [];
foreach ($applications as $application) {
$account = $accountRepository->findByUserAndApplication($user, $application);
$token = $account ? $apiOauthRepository->findDeveloperToken($account) : null;
$usersApplication[] = [
$application->getName(),
$application->getRedirectUri(),
$application->getClientSecret(),
$application->getClientId(),
($token) ? $token->getOauthToken() : '-'
];
}
return $usersApplication;
}
/**
* @param $withAdress
* @param $withRight

View File

@@ -0,0 +1,178 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\User;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\LazyLocator;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class UserPasswordCommand extends Command
{
use NotifierAware;
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct('user:password');
$this->setDescription('Set user password in Phraseanet <comment>(experimental)</>')
->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.')
->addOption('generate', null, InputOption::VALUE_NONE, 'Generate and set with a random value')
->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Set the user password to the input value')
->addOption('send_renewal_email', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if --password or --generate are not define')
->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce')
->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash')
->addOption('dump', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce')
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions')
->setHelp('');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getHelperSet()->get('dialog');
$userRepository = $this->container['repo.users'];
$userManipulator = $this->container['manipulator.user'];
$user = $userRepository->find($input->getOption('user_id'));
$password = $input->getOption('password');
$generate = $input->getOption('generate');
$sendRenewalEmail = $input->getOption('send_renewal_email');
$dump = $input->getOption('dump');
$passwordHash = $input->getOption('password_hash');
$passwordNonce = $input->getOption('password_nonce');
$jsonformat = $input->getOption('jsonformat');
$yes = $input->getOption('yes');
if ($user === null) {
$output->writeln('<info>Not found User.</info>');
return 0;
}
if ($passwordHash && $passwordNonce) {
$user->setNonce($passwordNonce);
$user->setPassword($passwordHash);
$userManipulator->updateUser($user);
$output->writeln('<info>password set with hashed pass</info>');
return 0;
}
if ($dump) {
$oldHash = $user->getPassword();
$oldNonce = $user->getNonce();
}
if ($generate) {
$oldHash = $user->getPassword();
$oldNonce = $user->getNonce();
$password = $this->container['random.medium']->generateString(64);
} else {
if (!$password && $sendRenewalEmail) {
$this->sendPasswordSetupMail($user);
$output->writeln('<info>email link sended for password renewing!</info>');
return 0;
} elseif (!$password && !$sendRenewalEmail && ! $dump) {
$output->writeln('<error>choose one option to set a password!</error>');
return 0;
}
}
if ($password) {
if (!$yes) {
do {
$continue = mb_strtolower($dialog->ask($output, '<question>Do you want really set password to this user? (y/N)</question>', 'N'));
} while (!in_array($continue, ['y', 'n']));
if ($continue !== 'y') {
$output->writeln('Aborting !');
return;
}
}
$oldHash = $user->getPassword();
$oldNonce = $user->getNonce();
$userManipulator->setPassword($user,$password);
}
if ($dump) {
if ($jsonformat) {
$hash['password_hash'] = $oldHash;
$hash['nonce'] = $oldNonce;
echo json_encode($hash);
return 0;
} else {
$output->writeln('<info>password_hash :</info>' . $oldHash);
$output->writeln('<info>nonce :</info>' . $oldNonce);
return 0;
}
}
if (($password || $generate)) {
if ($jsonformat) {
$hash['new_password'] = $password;
$hash['previous_password_hash'] = $oldHash;
$hash['previous_nonce'] = $oldNonce;
echo json_encode($hash);
} else {
$output->writeln('<info>new_password :</info>' . $password);
$output->writeln('<info>previous_password_hash :</info>' . $oldHash);
$output->writeln('<info>previous_nonce :</info>' . $oldNonce);
}
}
return 0;
}
/**
* Send mail for renew password
* @param User $user
*/
private function sendPasswordSetupMail(User $user)
{
$this->setDelivererLocator(new LazyLocator($this->container, 'notification.deliverer'));
$receiver = Receiver::fromUser($user);
$token = $this->container['manipulator.token']->createResetPasswordToken($user);
$url = $this->container['url_generator']->generate('login_renew_password', [ 'token' => $token->getValue() ], true);
$mail = MailRequestPasswordUpdate::create($this->container, $receiver);
$servername = $this->container['conf']->get('servername');
$mail->setButtonUrl($url);
$mail->setLogin($user->getLogin());
$mail->setExpiration(new \DateTime('+1 day'));
$this->deliver($mail);
}
}

View File

@@ -1,79 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\User;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class UserSetPasswordCommand extends Command
{
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct('user:set-password');
$this->setDescription('Set user password in Phraseanet')
->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.')
->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password')
->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password')
->setHelp('');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getHelperSet()->get('dialog');
$userRepository = $this->container['repo.users'];
$userManipulator = $this->container['manipulator.user'];
$user = $userRepository->find($input->getOption('user_id'));
$password = $input->getOption('password');
$generate = $input->getOption('generate');
if ($user === null) {
$output->writeln('<info>Not found User.</info>');
return 0;
}
if ($generate) {
$password = $this->container['random.medium']->generateString(64);
} else {
if (!$password) {
$output->writeln('<error>--password option not specified</error>');
return 0;
}
}
do {
$continue = mb_strtolower($dialog->ask($output, '<question>Do you want really set password to this user? (y/N)</question>', 'N'));
} while (!in_array($continue, ['y', 'n']));
if ($continue !== 'y') {
$output->writeln('Aborting !');
return;
}
$userManipulator->setPassword($user,$password);
$output->writeln('New password: <info>' . $password . '</info>');
return 0;
}
}

View File

@@ -450,6 +450,51 @@ class LightboxController extends Controller
return $this->app->json($data);
}
/**
* @param Basket $basket
* @return Response
*/
public function ajaxGetElementsAction(Basket $basket)
{
$ret = [
'error' => false,
'datas' => [
'counts' => [
'yes' => 0,
'no' => 0,
'nul' => 0,
'total' => 0
]
]
];
try {
if (!$basket->getValidation()) {
throw new Exception('There is no validation session attached to this basket');
}
foreach ($basket->getElements() as $element) {
$vd = $element->getUserValidationDatas($this->getAuthenticatedUser());
if($vd->getAgreement() === true) {
$ret['datas']['counts']['yes']++;
}
elseif($vd->getAgreement() === false) {
$ret['datas']['counts']['no']++;
}
elseif($vd->getAgreement() === null) {
$ret['datas']['counts']['nul']++;
}
$ret['datas']['counts']['total']++;
}
}
catch (Exception $e) {
$ret = [
'error' => true,
'datas' => $e->getMessage()
];
}
return $this->app->json($ret);
}
/**
* @param Basket $basket
* @throws Exception

View File

@@ -105,6 +105,11 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface
->assert('basket', '\d+')
;
$controllers->get('/ajax/GET_ELEMENTS/{basket}/', 'controller.lightbox:ajaxGetElementsAction')
->bind('lightbox_ajax_get_elements')
->assert('basket', '\d+')
;
return $controllers;
}

View File

@@ -17,7 +17,7 @@ class Version
* @var string
*/
private $number = '4.1.0-alpha.23a';
private $number = '4.1.0-alpha.25a';
/**
* @var string