Skip to content

Commit

Permalink
Merge branch 'b-6.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
godefroy-le-hardi committed Feb 14, 2018
2 parents 84eb228 + df4a0ca commit 49ace58
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -73,6 +73,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `OxidEsales\EshopCommunity\Application\Controller\TextEditorHandler::isTextEditorDisabled()`
- `OxidEsales\EshopCommunity\Application\Controller\Admin\AdminDetailsController::configureTextEditorHandler()`
- `OxidEsales\EshopCommunity\Application\Controller\Admin\AdminDetailsController::getTextEditorHandler()`
- `OxidEsales\EshopCommunity\Application\Controller\AccountController::deleteAccount()`
- `OxidEsales\EshopCommunity\Application\Controller\AccountController::isUserAllowedToDeleteOwnAccount()`

### Changed
- In voucher series generation, if Coupon Number radio button checked, the number is marked as Required now. [PR-476](https://github.com/OXID-eSales/oxideshop_ce/pull/476)
Expand Down
37 changes: 35 additions & 2 deletions source/Application/Controller/AccountController.php
Expand Up @@ -5,8 +5,7 @@
*/
namespace OxidEsales\EshopCommunity\Application\Controller;

use oxRegistry;
use oxUtilsUrl;
use OxidEsales\Eshop\Core\Registry;

/**
* Current user "My account" window.
Expand Down Expand Up @@ -352,4 +351,38 @@ public function getTitle()

return $title;
}

/**
* Deletes User account.
*/
public function deleteAccount()
{
$user = $this->getUser();

if ($user && $this->isUserAllowedToDeleteOwnAccount()) {
$user->delete();
$user->logout();

$session = $this->getSession();
$session->destroy();

if ($this->getConfig()->getConfigParam('blClearCacheOnLogout')) {
$this->resetContentCache(true);
}

Registry::getUtils()->redirect('index.php', true, 302);
}
}

/**
* Returns true if User is allowed to delete own account.
*
* @return bool
*/
public function isUserAllowedToDeleteOwnAccount()
{
return $this
->getConfig()
->getConfigParam('allowUsersToDeleteTheirAccount');
}
}
183 changes: 162 additions & 21 deletions source/Application/Model/User.php
Expand Up @@ -6,6 +6,7 @@

namespace OxidEsales\EshopCommunity\Application\Model;

use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsDate;
Expand Down Expand Up @@ -583,30 +584,21 @@ public function delete($sOXID = null)
$blDeleted = parent::delete($sOXID);

if ($blDeleted) {
$oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$sOXIDQuoted = $oDb->quote($sOXID);

// deleting stored payment, address, group dependencies, remarks info
$oDb->execute("delete from oxaddress where oxaddress.oxuserid = {$sOXIDQuoted}");
$oDb->execute("delete from oxobject2group where oxobject2group.oxobjectid = {$sOXIDQuoted}");

// deleting notice/wish lists
$oDb->execute("delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = {$sOXIDQuoted}");
$oDb->execute("delete from oxuserbaskets where oxuserid = {$sOXIDQuoted}");

// deleting newsletter subscription
$oDb->execute("delete from oxnewssubscribed where oxuserid = {$sOXIDQuoted}");

// delivery and delivery sets
$oDb->execute("delete from oxobject2delivery where oxobjectid = {$sOXIDQuoted}");
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$quotedUserId = $database->quote($sOXID);

// discounts
$oDb->execute("delete from oxobject2discount where oxobjectid = {$sOXIDQuoted}");
$this->deleteAddresses($database);
$this->deleteUserFromGroups($database);
$this->deleteBasket($database);
$this->deleteNewsletterSubscriptions($database);
$this->deleteDeliveries($database);
$this->deleteDiscounts($database);
$this->deleteRecommendationLists($database);
$this->deleteReviews($database);

$this->deleteAdditionally($sOXIDQuoted);
$this->deleteAdditionally($quotedUserId);

// and leaving all order related information
$oDb->execute("delete from oxremark where oxparentid = {$sOXIDQuoted} and oxtype !='o'");
$this->deleteNotOrderRelatedRemarks($database);
}

return $blDeleted;
Expand Down Expand Up @@ -2285,4 +2277,153 @@ protected function getUtilsObjectInstance()
{
return Registry::getUtilsObject();
}


/**
* Deletes not Order related remarks.
*
* @param DatabaseInterface $database
*/
private function deleteNotOrderRelatedRemarks(DatabaseInterface $database)
{
$database->execute(
'delete from oxremark where oxparentid = ? and oxtype !=\'o\'',
[$this->getId()]
);
}

/**
* Deletes User addresses.
*
* @param DatabaseInterface $database
*/
private function deleteAddresses(DatabaseInterface $database)
{
$database->execute(
'delete from oxaddress where oxaddress.oxuserid = ?',
[$this->getId()]
);
}

/**
* Deletes User from groups.
*
* @param DatabaseInterface $database
*/
private function deleteUserFromGroups(DatabaseInterface $database)
{
$database->execute(
'delete from oxobject2group where oxobject2group.oxobjectid = ?',
[$this->getId()]
);
}

/**
* Deletes deliveries.
*
* @param DatabaseInterface $database
*/
private function deleteDeliveries(DatabaseInterface $database)
{
$database->execute(
'delete from oxobject2delivery where oxobjectid = ?',
[$this->getId()]
);
}

/**
* Deletes newsletter subscriptions.
*
* @param DatabaseInterface $database
*/
private function deleteNewsletterSubscriptions(DatabaseInterface $database)
{
$database->execute(
'delete from oxnewssubscribed where oxuserid = ?',
[$this->getId()]
);
}

/**
* Deletes discounts.
*
* @param DatabaseInterface $database
*/
private function deleteDiscounts(DatabaseInterface $database)
{
$database->execute(
'delete from oxobject2discount where oxobjectid = ?',
[$this->getId()]
);
}

/**
* Deletes Basket.
*
* @param DatabaseInterface $database
*/
private function deleteBasket(DatabaseInterface $database)
{
$database->execute(
'delete
oxuserbasketitems.*
from
oxuserbasketitems,
oxuserbaskets
where
oxuserbasketitems.oxbasketid = oxuserbaskets.oxid
and oxuserid = ?
',
[$this->getId()]
);

$database->execute(
'delete from oxuserbaskets where oxuserid = ?',
[$this->getId()]
);
}

/**
* Deletes recommendation lists.
*
* @param DatabaseInterface $database
*/
private function deleteRecommendationLists(DatabaseInterface $database)
{
$database->execute(
'delete
oxobject2list
from
oxobject2list
inner join oxrecommlists
on oxobject2list.oxlistid = oxrecommlists.oxid
where
oxrecommlists.oxuserid = ?
',
[$this->getId()]
);

$database->execute(
'delete from oxrecommlists where oxuserid = ?',
[$this->getId()]
);
}

/**
* Deletes User reviews.
*
* @param DatabaseInterface $database
*/
private function deleteReviews(DatabaseInterface $database)
{
$database->execute(
'delete from oxreviews where oxuserid = ?',
[$this->getId()]
);
}
}
2 changes: 2 additions & 0 deletions source/Application/views/admin/de/lang.php
Expand Up @@ -1048,6 +1048,7 @@
'SHOP_MAIN_VATNUMBER' => 'USt.-ID',
'SHOP_MAIN_TAXNUMBER' => 'Steuernummer',
'SHOP_MAIN_PRODUCTIVE' => 'Produktivmodus',
'SHOP_CONFIG_ALLOW_USERS_TO_DELETE_THEIR_ACCOUNT' => 'Shopkunden erlauben, ihr Konto zu löschen',
'SHOP_CONFIG_CSVSEPARATOR' => 'CSV-Trennzeichen beim Im- und Export',
'SHOP_CONFIG_CSVFIELDENCLOSER' => 'Zeichen, um CSV-Daten beim Im/Export einzufassen',
'SHOP_CONFIG_DISABLEARTDUBLICATES' => 'Wenn Artikel kopiert werden: Kopierten Artikel <b>nicht</b> auf "Aktiv" setzen',
Expand Down Expand Up @@ -1740,6 +1741,7 @@
'SHOP_OPTIONS_GROUP_INVITATIONS' => 'Einladungen',
'SHOP_OPTIONS_GROUP_SHOP_DOWNLOADABLEARTICLES' => 'Download-Artikel',
'SHOP_OPTIONS_BANK_INFORMATION' => 'Bankinformationen (SEPA)',
'SHOP_OPTIONS_GROUP_ACCOUNT_SETTINGS' => 'Kontoeinstellungen',


'PROMOTION_USERS_SETGROUPS' => 'Zugeordnete Benutzergruppen',
Expand Down
2 changes: 2 additions & 0 deletions source/Application/views/admin/en/lang.php
Expand Up @@ -1052,6 +1052,7 @@
'SHOP_MAIN_VATNUMBER' => 'Sales Tax ID',
'SHOP_MAIN_TAXNUMBER' => 'Tax ID',
'SHOP_MAIN_PRODUCTIVE' => 'Productive Mode',
'SHOP_CONFIG_ALLOW_USERS_TO_DELETE_THEIR_ACCOUNT' => 'Allow shop users to delete their account',
'SHOP_CONFIG_CSVSEPARATOR' => 'CSV Separation Char for Im/Export',
'SHOP_CONFIG_CSVFIELDENCLOSER' => 'CSV-Encloser for Im/Export',
'SHOP_CONFIG_DISABLEARTDUBLICATES' => 'When Products are copied: Do not set copied Product to active',
Expand Down Expand Up @@ -1746,6 +1747,7 @@
'SHOP_OPTIONS_GROUP_INVITATIONS' => 'Invitations',
'SHOP_OPTIONS_GROUP_SHOP_DOWNLOADABLEARTICLES' => 'Downloadable products',
'SHOP_OPTIONS_BANK_INFORMATION' => 'Bank account information (SEPA)',
'SHOP_OPTIONS_GROUP_ACCOUNT_SETTINGS' => 'Account settings',

'PROMOTION_USERS_SETGROUPS' => 'Assigned User Groups',
'PROMOTION_LIST_ALL' => 'All',
Expand Down
19 changes: 19 additions & 0 deletions source/Application/views/admin/tpl/shop_config.tpl
Expand Up @@ -1152,6 +1152,25 @@ function editThis(sID)
</dl>
</div>
</div>
<div class="groupExp">
<div>
<a href="#" onclick="_groupExp(this);return false;" class="rc"><b>[{oxmultilang ident="SHOP_OPTIONS_GROUP_ACCOUNT_SETTINGS"}]</b></a>
<dl>
<dt>
<input type=hidden name=confbools[allowUsersToDeleteTheirAccount] value=false>
<input
type=checkbox
name=confbools[allowUsersToDeleteTheirAccount]
value=true [{if ($confbools.allowUsersToDeleteTheirAccount)}]checked[{/if}] [{$readonly}]
>
</dt>
<dd>
[{oxmultilang ident="SHOP_CONFIG_ALLOW_USERS_TO_DELETE_THEIR_ACCOUNT"}]
</dd>
<div class="spacer"></div>
</dl>
</div>
</div>
[{/block}]

<br>
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Application/Model/UserTest.php
Expand Up @@ -6,6 +6,9 @@
namespace OxidEsales\EshopCommunity\Tests\Unit\Application\Model;

use oxEmailHelper;
use OxidEsales\Eshop\Application\Model\RecommendationList;
use OxidEsales\Eshop\Application\Model\Review;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\EshopCommunity\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\UtilsObject;
use \oxnewssubscribed;
Expand Down Expand Up @@ -1233,6 +1236,19 @@ public function testDelete()
$oRemark->oxremark__oxtype = new oxField('r');
$oRemark->save();

$recommendationList = oxNew(RecommendationList::class);
$recommendationList->setId("_testRecommendationList");
$recommendationList->oxrecommlists__oxuserid = new Field($sUserId);
$recommendationList->oxrecommlists__oxshopid = new Field(1);
$recommendationList->oxrecommlists__oxtitle = new Field("Test title");
$recommendationList->save();

$review = oxNew(Review::class);
$review->setId("_testReview");
$review->oxreviews__oxuserid = new Field($sUserId);
$review->oxreviews__oxtext = new Field("Supergood");
$review->save();

$oUser = oxNew('oxUser');
$oUser->load($sUserId);
$bSuccess = $oUser->delete();
Expand All @@ -1243,6 +1259,8 @@ public function testDelete()
'oxaddress' => 'oxuserid',
'oxuserbaskets' => 'oxuserid',
'oxnewssubscribed' => 'oxuserid',
'oxrecommlists' => 'oxuserid',
'oxreviews' => 'oxuserid',
'oxobject2delivery' => 'oxobjectid',
'oxobject2discount' => 'oxobjectid',
'oxobject2group' => 'oxobjectid',
Expand Down

0 comments on commit 49ace58

Please sign in to comment.