mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 06:23:18 +00:00
Fix #1570 Remove accept tou link if there are no TOU
This commit is contained in:
@@ -58,14 +58,16 @@ class PhraseaRegisterForm extends AbstractType
|
||||
),
|
||||
));
|
||||
|
||||
$builder->add('accept-tou', 'checkbox', array(
|
||||
'label' => _('Terms of Use'),
|
||||
'mapped' => false,
|
||||
"constraints" => array(
|
||||
new Assert\True(array(
|
||||
"message" => _("Please accept the Terms and conditions in order to register.")
|
||||
))),
|
||||
));
|
||||
if ($this->app->hasTermsOfUse()) {
|
||||
$builder->add('accept-tou', 'checkbox', array(
|
||||
'label' => _('Terms of Use'),
|
||||
'mapped' => false,
|
||||
"constraints" => array(
|
||||
new Assert\True(array(
|
||||
"message" => _("Please accept the Terms and conditions in order to register.")
|
||||
))),
|
||||
));
|
||||
}
|
||||
|
||||
$builder->add('provider-id', 'hidden');
|
||||
|
||||
|
@@ -59,17 +59,19 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
{% set label %}
|
||||
<a target="_blank" href="{{ path("login_cgus") }}">
|
||||
{% trans "I have read the terms of use" %}
|
||||
</a>
|
||||
{% endset %}
|
||||
{% if has_terms_of_use %}
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
{% set label %}
|
||||
<a target="_blank" href="{{ path("login_cgus") }}">
|
||||
{% trans "I have read the terms of use" %}
|
||||
</a>
|
||||
{% endset %}
|
||||
|
||||
{{ auth_macro.checkboxInput(form['accept-tou'], label) }}
|
||||
{{ auth_macro.checkboxInput(form['accept-tou'], label) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# form.collections is not defined if current instance is configured with auto collection selection #}
|
||||
{% if form.collections is defined %}
|
||||
|
@@ -60,17 +60,19 @@
|
||||
* {% trans "Mandatory fields" %}
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
{% set label %}
|
||||
<a href="{{ path("login_cgus") }}">
|
||||
{% trans "I have read the terms of use" %}
|
||||
</a>
|
||||
{% endset %}
|
||||
{% if has_terms_of_use %}
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
{% set label %}
|
||||
<a href="{{ path("login_cgus") }}">
|
||||
{% trans "I have read the terms of use" %}
|
||||
</a>
|
||||
{% endset %}
|
||||
|
||||
{{ auth_macro.checkboxInput(form['remember-me']) }}
|
||||
{{ auth_macro.checkboxInput(form['remember-me']) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{ form_rest(form) }}
|
||||
|
||||
|
@@ -20,6 +20,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
public static $login;
|
||||
public static $email;
|
||||
|
||||
private static $termsOfUse;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -45,6 +47,50 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->resetTOU();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testRegisterWithNoTou()
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
$this->disableTOU();
|
||||
self::$DI['client']->followRedirects();
|
||||
$crawler = self::$DI['client']->request('GET', '/login/register-classic');
|
||||
$this->assertEquals(0, $crawler->filter('a[href="'.self::$DI['app']->path('login_cgus').'"]')->count());
|
||||
}
|
||||
|
||||
public function testRegisterWithTou()
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
$this->enableTOU();
|
||||
self::$DI['client']->followRedirects();
|
||||
$crawler = self::$DI['client']->request('GET', '/login/register-classic');
|
||||
$this->assertEquals(2, $crawler->filter('a[href="'.self::$DI['app']->path('login_cgus').'"]')->count());
|
||||
}
|
||||
|
||||
public function testRegisterWithAutoSelect()
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
$gvAutoSelectDb = !! self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB');
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', false, \registry::TYPE_BOOLEAN);
|
||||
$crawler = self::$DI['client']->request('GET', '/login/register-classic/');
|
||||
$this->assertEquals(1, $crawler->filter('select[name="collections[]"]')->count());
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', $gvAutoSelectDb, \registry::TYPE_BOOLEAN);
|
||||
}
|
||||
|
||||
public function testRegisterWithNoAutoSelect()
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
$gvAutoSelectDb = !! self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB');
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', true, \registry::TYPE_BOOLEAN);
|
||||
$crawler = self::$DI['client']->request('GET', '/login/register-classic/');
|
||||
$this->assertEquals(0, $crawler->filter('select[name="collections[]"]')->count());
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', $gvAutoSelectDb, \registry::TYPE_BOOLEAN);
|
||||
}
|
||||
|
||||
public function testLoginAlreadyAthenticated()
|
||||
{
|
||||
self::$DI['client']->request('GET', '/login/');
|
||||
@@ -70,9 +116,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
$this->logout(self::$DI['app']);
|
||||
self::$DI['app']->addFlash($type, $message);
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', '/login/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertFlashMessage($crawler, $type, 1, $message);
|
||||
@@ -86,7 +130,6 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$this->logout(self::$DI['app']);
|
||||
self::$DI['client']->request('GET', '/login/register-confirm/');
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||
$this->assertEquals('/login/', $response->headers->get('location'));
|
||||
@@ -496,8 +539,9 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
/**
|
||||
* @dataProvider provideInvalidRegistrationData
|
||||
*/
|
||||
public function testPostRegisterbadArguments($parameters, $extraParameters, $errors)
|
||||
public function testPostRegisterBadArguments($parameters, $extraParameters, $errors)
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.enabled'] = true;
|
||||
self::$DI['app']['registration.fields'] = $extraParameters;
|
||||
|
||||
@@ -521,13 +565,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
}
|
||||
|
||||
$crawler = self::$DI['client']->request('POST', '/login/register-classic/', $parameters);
|
||||
|
||||
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
|
||||
$this->assertFormOrFlashError($crawler, $errors);
|
||||
}
|
||||
|
||||
public function testPostRegisterWithoutParams()
|
||||
{
|
||||
$this->enableTOU();
|
||||
$this->logout(self::$DI['app']);
|
||||
$crawler = self::$DI['client']->request('POST', '/login/register-classic/');
|
||||
|
||||
@@ -781,6 +825,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
public function testPostRegisterWithProviderIdAndAlreadyBoundProvider()
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.fields'] = array();
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
@@ -831,6 +876,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
public function testPostRegisterWithUnknownProvider()
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.fields'] = array();
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
@@ -866,6 +912,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
public function testPostRegisterWithProviderNotAuthenticated()
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.fields'] = array();
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
@@ -908,6 +955,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
public function testPostRegisterWithProviderId()
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.fields'] = array();
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
@@ -981,6 +1029,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testPostRegister($parameters, $extraParameters)
|
||||
{
|
||||
$this->enableTOU();
|
||||
self::$DI['app']['registration.fields'] = $extraParameters;
|
||||
|
||||
$this->logout(self::$DI['app']);
|
||||
@@ -1006,7 +1055,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
}
|
||||
}
|
||||
|
||||
if ( self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
|
||||
if (self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
|
||||
unset($parameters['collections']);
|
||||
}
|
||||
|
||||
@@ -1753,4 +1802,50 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
return \random::generatePassword() . '_email@email.com';
|
||||
}
|
||||
|
||||
private function disableTOU()
|
||||
{
|
||||
if (null === self::$termsOfUse) {
|
||||
self::$termsOfUse = array();
|
||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
|
||||
|
||||
foreach( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
|
||||
$databox->update_cgus($lng, '', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function enableTOU()
|
||||
{
|
||||
if (null === self::$termsOfUse) {
|
||||
self::$termsOfUse = array();
|
||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
|
||||
|
||||
foreach( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
|
||||
$databox->update_cgus($lng, 'something', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resetTOU()
|
||||
{
|
||||
if (null === self::$termsOfUse) {
|
||||
return;
|
||||
}
|
||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
if (!isset(self::$termsOfUse[$databox->get_sbas_id()])) {
|
||||
continue;
|
||||
}
|
||||
$tous = self::$termsOfUse[$databox->get_sbas_id()];
|
||||
foreach ($tous as $lng => $tou) {
|
||||
$databox->update_cgus($lng, $tou['value'], false);
|
||||
}
|
||||
}
|
||||
|
||||
self::$termsOfUse = null;
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,8 @@ require([
|
||||
}, function () {
|
||||
Common.initialize();
|
||||
|
||||
var rules = [
|
||||
var rules = [];
|
||||
var defaultRules = [
|
||||
{
|
||||
name: "email",
|
||||
rules: "required",
|
||||
@@ -85,7 +86,13 @@ require([
|
||||
"message": i18n.t("validation_blank")
|
||||
};
|
||||
|
||||
rules.push(rule);
|
||||
defaultRules.push(rule);
|
||||
}
|
||||
});
|
||||
|
||||
_.each(defaultRules, function (rule) {
|
||||
// add rule if element exists
|
||||
if ($("[name='" + rule.name + "']").length >= 1) {
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -30,7 +30,8 @@ require([
|
||||
resGetPath: Common.languagePath,
|
||||
useLocalStorage: true
|
||||
}, function () {
|
||||
var rules = [
|
||||
var rules = [];
|
||||
var defaultRules = [
|
||||
{
|
||||
name: "email",
|
||||
rules: "required",
|
||||
@@ -84,6 +85,13 @@ require([
|
||||
"message": i18n.t("validation_blank")
|
||||
};
|
||||
|
||||
defaultRules.push(rule);
|
||||
}
|
||||
});
|
||||
|
||||
_.each(defaultRules, function (rule) {
|
||||
// add rule if element exists
|
||||
if ($("[name='" + rule.name + "']").length >= 1) {
|
||||
rules.push(rule);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user