Skip to content

Commit

Permalink
Merge branch 'master' into PHRAS-4088-improve-workerrunningjob-finished
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaillat authored Oct 23, 2024
2 parents 99dec4e + 47371bb commit 5064b93
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Root/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ public function displayAccount()

$initiatedValidations = $this->getBasketRepository()->findby(['vote_initiator' => $user, ]);

$this->setSessionFormToken('userAccount');

return $this->render('account/account.html.twig', [
'user' => $user,
'evt_mngr' => $manager,
Expand Down Expand Up @@ -417,6 +419,10 @@ public function confirmDeleteAccount(Request $request)
*/
public function updateAccount(Request $request)
{
if (!$this->isCrsfValid($request, 'userAccount')) {
return new Response('invalid crsf token form', 403);
}

$registrations = $request->request->get('registrations', []);

if (false === is_array($registrations)) {
Expand Down
6 changes: 6 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Root/DeveloperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public function authorizeGrantPassword(Request $request, ApiApplication $applica
*/
public function newApp(Request $request)
{
if (!$this->isCrsfValid($request, 'newApplication')) {
return new Response('invalid crsf token form', 403);
}

if ($request->request->get('type') === ApiApplication::DESKTOP_TYPE) {
$form = new \API_OAuth2_Form_DevAppDesktop($request);
} else {
Expand Down Expand Up @@ -223,6 +227,8 @@ public function listApps()
*/
public function displayFormApp(Request $request)
{
$this->setSessionFormToken('newApplication');

return $this->render('developers/application_form.html.twig', [
"violations" => null,
'form' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function getUserSetting(User $user, $name, $default = null)
return array_key_exists($name, $this->usersSettings) ? $this->usersSettings[$name] : $default;
}

if ($name == 'start_page_query') {
return htmlentities($user->getSettings()->get($name)->getValue());
}

return $user->getSettings()->get($name)->getValue();
}

Expand Down
1 change: 1 addition & 0 deletions templates/web/account/account.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@

</div>
</div>
<input type="hidden" name="userAccount_token" value="{{ app['session'].get('userAccount_token') }}">
</form>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions templates/web/developers/application_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@
</div>

</div>
<input type="hidden" name="newApplication_token" value="{{ app['session'].get('newApplication_token') }}">
</form>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/web/prod/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@
{{ 'Aide' | trans }}
</option>
</select>
<input type="text" class="span4" name="start_page_value" value="{{ app['settings'].getUserSetting(app.getAuthenticatedUser(), 'start_page_query')}}" style="display:{% if start_page_pref == 'QUERY' %}inline{% else %}none{% endif %}" />
<input type="text" class="span4" name="start_page_value" value="{{ app['settings'].getUserSetting(app.getAuthenticatedUser(), 'start_page_query') | raw }}" style="display:{% if start_page_pref == 'QUERY' %}inline{% else %}none{% endif %}" />
<input type="button" class="btn btn-inverse preferences-options-submit" value="{{'boutton::valider' | trans }}" />
</form>
</div>
Expand Down
4 changes: 3 additions & 1 deletion tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public function testUpdateAccount()
$app = $this->getApplication();
$client = $this->getClient();
$bases = $notifs = [];
$randomValue = $this->setSessionFormToken('userAccount');

foreach ($app->getDataboxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
Expand Down Expand Up @@ -424,7 +425,8 @@ public function testUpdateAccount()
'form_retryFTP' => '',
'notifications' => $notifs,
'form_defaultdataFTP' => ['document', 'preview', 'caption'],
'mail_notifications' => '1'
'mail_notifications' => '1',
'userAccount_token' => $randomValue
]);

$response = $client->getResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public function testDisplayformApp()
*/
public function testPostNewAppInvalidArguments()
{
$randomValue = $this->setSessionFormToken('newApplication');

$crawler = self::$DI['client']->request('POST', '/developers/application/', [
'type' => ApiApplication::WEB_TYPE,
'name' => '',
'description' => 'okok',
'website' => 'my.website.com',
'callback' => 'my.callback.com',
'scheme-website' => 'http://',
'scheme-callback' => 'http://'
'scheme-callback' => 'http://',
'newApplication_token' => $randomValue
]);

$this->assertTrue(self::$DI['client']->getResponse()->isOk());
Expand All @@ -63,6 +66,7 @@ public function testPostNewApp()
{
$apps = self::$DI['app']['repo.api-applications']->findByCreator(self::$DI['user']);
$nbApp = count($apps);
$randomValue = $this->setSessionFormToken('newApplication');

self::$DI['client']->request('POST', '/developers/application/', [
'type' => ApiApplication::WEB_TYPE,
Expand All @@ -71,7 +75,8 @@ public function testPostNewApp()
'website' => 'my.website.com',
'callback' => 'my.callback.com',
'scheme-website' => 'http://',
'scheme-callback' => 'http://'
'scheme-callback' => 'http://',
'newApplication_token' => $randomValue
]);

$apps = self::$DI['app']['repo.api-applications']->findByCreator(self::$DI['user']);
Expand Down

0 comments on commit 5064b93

Please sign in to comment.