Commit ef6c9132 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FEAT(mapping): open access to all users

Refs: #896
parent f6503206
Pipeline #9779 passed with stage
in 3 minutes and 29 seconds
......@@ -422,8 +422,7 @@ class SoftwaresController extends AppController
if ($this->processExtraUserOfForm($displayUserOfForm, $user->id, $software->get('id'))) {
// if the user is an administration,
// redirect to the additional form for mapping.
if ($user->isAdminUser() && $user->isAdministrationType()) { # dev version
// if($user->isAdministrationType()) { # final version
if ($user->isAdministrationType()) {
return $this->redirect("/$lang/mappingForm/" . $software->get('id'));
}
}
......@@ -614,8 +613,7 @@ class SoftwaresController extends AppController
if ($this->processExtraUserOfForm($displayUserOfForm, $user->id, $software->get('id'))) {
// if the user is an administration,
// redirect to the additional form for mapping.
if ($user->isAdminUser() && $user->isAdministrationType()) { # dev version
// if($user->isAdministrationType()) { # final version
if ($user->isAdministrationType()) {
return $this->redirect("/$lang/mappingForm/" . $software->get('id'));
}
}
......@@ -675,6 +673,9 @@ class SoftwaresController extends AppController
return $this->redirect(["prefix" => false, 'action' => 'index']);
}
/**
* Returns list of users of a given software (GET method)
* Adds current user in the list of users declared for the current software (POST method)
......@@ -748,8 +749,7 @@ class SoftwaresController extends AppController
// if the user is an administration,
// redirect to the additional form for mapping.
if ($user->isAdminUser() && $user->isAdministrationType()) { # dev version
// if($user->isAdministrationType()) { # final version
if ($user->isAdministrationType() && !$this->request->is('json')) {
$lang = $this->selectedLanguage;
return $this->redirect("/$lang/mappingForm/" . $software->id);
} else {
......@@ -956,6 +956,7 @@ class SoftwaresController extends AppController
$links[] = [
'name' => __d('Breadcrumbs', 'Software.AlternativeTo'),
'url' => "softwares/servicesProviders/$id"
/// BUG URL à vérifier /|\
];
$this->setBreadcrumbs($links);
}
......
......@@ -193,13 +193,7 @@ class MetaTaxonomyController extends AppController
$allowedUserTypeId = $this->getUserTypeIdByName('Administration');
if ($user_type_id === $allowedUserTypeId) { // Administration
// final version
// return true;
// dev version
if ($this->Auth->user('role') === 'admin') {
return true;
}
return true;
}
return false;
}
......
......@@ -30,31 +30,23 @@ class TaxonomysController extends CommonTaxonomyController
* Actions allowed only to editor (connected user + business rules)
* @var array
*/
protected $actionsAllowedOnlyToEditor = [
// 'mapping',
// 'mappingPrimaryLevel',
// 'mappingTaxon',
];
protected $actionsAllowedOnlyToEditor = [];
/**
* Actions allowed only for connected user
* @var array
*/
protected $actionsAllowedOnlyToConnectedUser = [
// 'mapping',
// 'mappingPrimaryLevel',
// 'mappingTaxon',
];
protected $actionsAllowedOnlyToConnectedUser = [];
/**
* Actions allowed to everyone
* @var array
*/
protected $actionsAllowedToEveryone = [
// 'mapping',
// 'mappingPrimaryLevel',
// 'mappingTaxon',
// 'mappingSoftwareTaxon', // not here, see ...
'mapping',
'mappingPrimaryLevel',
'mappingTaxon',
'mappingTaxonUsersOf',
];
......
......@@ -82,8 +82,6 @@ class CheckBreadcrumbCest
* /fr/cartographie/outillage/
* /fr/cartographie/
*
* @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
*
* @group nav
* @group breadcrumb
* @group taxonomy
......@@ -91,10 +89,6 @@ class CheckBreadcrumbCest
*/
public function checkBreadcrumbOnMappingPages(AcceptanceTester $I)
{
// Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
$I->amOnPage('/');
$I->loginMe('dev-admin_person@comptoir-du-libre.org', 'comptoir', 'dev-admin_person');
$I->seeElement('div.message.success');
// URL = /fr/cartographie/
$BaseBreadcrumbs = [
......@@ -145,8 +139,6 @@ class CheckBreadcrumbCest
* Tested URL: /fr/mappingForm/10
* /en/mappingForm/10
*
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group nav
* @group breadcrumb
* @group form
......@@ -159,7 +151,7 @@ class CheckBreadcrumbCest
{
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$I->amOnPage('/');
$I->loginMe('dev-admin_administration@comptoir-du-libre.org', 'comptoir', 'dev-admin_administration');
$I->loginMe('dev-user_administration@comptoir-du-libre.org', 'comptoir', 'dev-user_administration');
$I->seeElement('div.message.success');
// declare as user (french version)
......
......@@ -134,6 +134,10 @@ class UserAdministrationCheckActionsCest
$I->dontSee('dev-collectivite', ['css' => 'ol li']); // user dev-collectivite
$I->click('(//button[@type=\'submit\'])[2]'); // button : 'Se déclarer utilisateur'
$I->seeElement('div.message.success');
$I->seeInCurrentUrl("/$lang/mappingForm/163");
$I->click('//*[@id="softwaresPage"]'); // button 'Logiciels'
$I->click($softwareToAddAsUser);
$I->seeElement('button.btn.btn-default.removeOne');
$I->see('dev-collectivite', ['css' => 'ol li']); // dev-collectivite on the list of users
}
......@@ -168,15 +172,20 @@ class UserAdministrationCheckActionsCest
*/
public function declareUserOfSoftwareWithMoreThan3Users(AcceptanceTester $I)
{
$I->amOnPage('/users/284'); // dev-collectivite's page
$lang = $this->lang;
$I->amOnPage("/$lang/users/284"); // dev-collectivite's page
$I->dontSeeElement('7-zip');
$I->click('//*[@id="softwaresPage"]'); // button 'Logiciels'
$I->click('7-zip');
$I->seeInCurrentUrl('softwares/72');
$I->seeInCurrentUrl("/$lang/softwares/72");
$I->click('//section[2]/section[1]/div/form/button'); // button : 'Se déclarer utilisateur'
$I->seeElement('div.message.success');
$I->seeInCurrentUrl("/$lang/mappingForm/72");
$I->click('//*[@id="softwaresPage"]'); // button 'Logiciels'
$I->click('7-zip');
$I->click('//section[2]/section[1]/ol/li[4]/div/p/a'); // button : see all users of 7-Zip
$I->seeInCurrentUrl('softwares/usersSoftware/72');
$I->seeInCurrentUrl("/$lang/softwares/usersSoftware/72");
$I->see('dev-collectivite', ['css' => 'ol li']); // dev-collectivite on the list of users
}
......
......@@ -1625,11 +1625,7 @@ class SoftwaresControllerTest extends ApiIntegrationTestCase
// "Administration" user
$this->setConnectedAdministrationSession();
$this->commonCheckForHtmlFormAddSoftwareWithExtraFormData('userOf');
// "Administration" user, with "admin" role @@@TODO
$this->setAdminSessionOfAdministrationType();
$this->commonCheckForHtmlFormAddSoftwareWithExtraFormData('userOf', 'mappingForm');
$this->commonCheckForHtmlFormAddSoftwareWithExtraFormData('userOf', 'mappingForm');
// "Company" user
$this->setConnectedCompanySession();
......@@ -1880,10 +1876,6 @@ class SoftwaresControllerTest extends ApiIntegrationTestCase
// "Administration" user
$this->setConnectedAdministrationSession();
$this->commonCheckForHtmlFormEditSoftwareWithExtraFormData('userOf');
// "Administration" user, with "admin" role @@@TODO
$this->setAdminSessionOfAdministrationType();
$this->commonCheckForHtmlFormEditSoftwareWithExtraFormData('userOf', 'mappingForm');
// "Company" user
......
......@@ -60,9 +60,6 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* URL: /en/mappingForm/<softwareId>
* /fr/mappingForm/<softwareId>
*
* @todo WIP
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
......@@ -76,15 +73,20 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$url = '/fr/mappingForm/2'; // software ID 2 "Lutèce"
$title = "<title>Logiciel Lutèce : déclarer vos usages</title>";
// Tempory test ---> can be remove when development is complete.
$this->setAdminSessionOfPersonType();
// Anonymous user
$this->setAnonymousUserSession();
$this->checkUrlRedirectToLogin($url, ['html'], 'fr');
// Connected user (type != "Administration")
$this->setConnectedPersonSession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedAdministrationSession();
$this->setConnectedCompanySession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedAssociationSession();
$this->checkUrlNotAuthorized($url, ['html']);
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType(); # dev version
// $this->setConnectedAdministrationSession(); # final version
// connected user (type = "Administration")
$this->setConnectedAdministrationSession();
$r = $this->checkUrlOk($url, ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
......@@ -101,18 +103,6 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$htmlCheckBox .= '<input type="checkbox" name="taxonCheckboxes[]" value="3" id="checkbox_3">';
$htmlCheckBox .= 'Urbanisme / Espace public / Environnement</label>';
$this->assertContains($htmlCheckBox, $html); // no found taxon --> no checkbox
// Connected user (type != "Administration")
$this->setConnectedPersonSession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedCompanySession();
$this->checkUrlNotAuthorized($url, ['html']);
$this->setConnectedAssociationSession();
$this->checkUrlNotAuthorized($url, ['html']);
// Anonymous user
$this->setAnonymousUserSession();
$this->checkUrlRedirectToLogin($url, ['html'], 'fr');
}
......@@ -132,9 +122,6 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* - Resend form data: user unchecks last entry
* - Check AFTER ---> no associed entry (user-software-taxon)
*
* @todo WIP
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
......@@ -151,7 +138,7 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$taxonSlugB = 'bureautique';
$softwareId = 2;
$softwareSlug = 'lutece';
$idUserA = 5;
$idUserA = 6;
$urlForm = "/fr/mappingForm/$softwareId";
$softwareUrl = "/fr/softwares/$softwareId";
$testeddUrlTaxonA = "/fr/cartographie/metiers/$taxonSlugA/$softwareSlug/$taxonIdA.$softwareId";
......@@ -159,14 +146,13 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$testeddUrlTaxonB = "/fr/cartographie/generiques/$taxonSlugB/$softwareSlug/$taxonIdB.$softwareId";
$redirectUrlTaxonB = "/fr/cartographie/generiques/$taxonSlugB/$taxonIdB";
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType(); # dev version
// $this->setConnectedAdministrationSession(); # final version
// connected user (type = "Administration")
$this->setConnectedAdministrationSession();
// Check BEFORE send form data
///////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3 | 4
// no entry for current user (ID-6), software ID-2 and taxon ID 3 | 4
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonB, $redirectUrlTaxonB, ['html'], 301);
......@@ -189,7 +175,7 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER send form data
///////////////////////////////////
// entry found for current user (ID-5), software ID-2 and taxon ID 3
// entry found for current user (ID-6), software ID-2 and taxon ID 3
$r = $this->checkUrlOk($testeddUrlTaxonA, ['html']);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingTaxon$taxonIdA-UsersOf$softwareId\"", $html); // <section id="">
......@@ -218,10 +204,10 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER resend send form data (user unchecks an entry $taxonIdA)
///////////////////////////////////////////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3
// no entry for current user (ID-6), software ID-2 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// entry found for current user (ID-5), software ID-2 and taxon ID 4
// entry found for current user (ID-6), software ID-2 and taxon ID 4
$r = $this->checkUrlOk($testeddUrlTaxonB, ['html']);
$html = $r['html']['data'];
$this->assertContains("id=\"mappingTaxon$taxonIdB-UsersOf$softwareId\"", $html); // <section id="">
......@@ -245,13 +231,13 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
// Check AFTER resend send form data (user unchecks the last entry $taxonIdB)
/////////////////////////////////////////////////////////////////////////////
// no entry for current user (ID-5), software ID-2 and taxon ID 3
// no entry for current user (ID-6), software ID-2 and taxon ID 3
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonA, $redirectUrlTaxonA, ['html'], 301);
// entry found for current user (ID-5), software ID-2 and taxon ID 4
// entry found for current user (ID-6), software ID-2 and taxon ID 4
$this->checkUrlRedirectToAnotherUrl($testeddUrlTaxonB, $redirectUrlTaxonB, ['html'], 301);
// in the form, checkbox (of taxon ID4) must be checked, but not for taxon ID3
// in the form, checkbox (of taxon ID 3|ID 4) must not be checked
$r = $this->checkUrlOk($urlForm, ['html']);
$html = $r['html']['data'];
$this->assertNotContains('id="checkbox_'.$taxonIdA.'" checked="checked"', $html);
......@@ -264,9 +250,6 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* URL: /en/mappingForm/<softwareIdNotFound> ----> redirect to /en/mapping/
* /fr/mappingForm/<softwareIdNotFound> ----> redirect to /fr/cartographie/
*
* @todo WIP
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group public
* @group taxonomy
* @group taxonomy_public
......@@ -279,8 +262,8 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
{
$url = '/fr/mappingForm/888'; // software ID 888 ---> not in database
// Admin user --> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType();
// connected user (type = "Administration")
$this->setConnectedAdministrationSession();
$this->get("/fr/"); // force user language to french
$expectedUrl = '/fr/cartographie/';
$this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);
......@@ -297,8 +280,6 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
* /api/v1/taxonomys-softwares/mappingForm.json ---> disable via parent::beforeFilter()
* /api/v1/taxonomys-softwares/mappingForm/<softwareId>.json ---> disable via parent::beforeFilter()
*
* @todo admin user to be replaced by a connected user (type = "Administration") when development is complete.
*
* @group seo
* @group public
* @group taxonomy
......@@ -312,8 +293,8 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$urlBase = '/api/v1/taxonomys-softwares/mappingForm'; // missing software ID
$url = "$urlBase/2"; // software ID 2
// Admin user ---> to be replaced by a connected user (type = "Administration") when development is complete.
$this->setAdminSessionOfAdministrationType();
// connected user (type = "Administration")
$this->setConnectedAdministrationSession();
// JSON format
$this->checkUrlNotFound($urlBase, ['json']);
......@@ -327,7 +308,7 @@ class TaxonomysSoftwaresControllerTest extends ApiIntegrationTestCase
$this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);
// Connected user (type != "Administration")
$this->setConnectedUserSession();
$this->setConnectedPersonSession();
$this->checkUrlNotFound($url, ['json']);
$this->checkUrlNotAuthorized($url, ['html']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment