قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 15:07:44 +00:00

* Add token expiry warning email notification to scheduler * Add token expiry warning email notification to scheduler * add logic for -1 disable notification' * Fix spelling mistake * Fix some bugs around rendering the email * Update version * Refactor rotation code to use a standardised naming convention with new code * PHPStan * PHPCS fix * add test, not finished * finish off implementing test * Fix regression test failure * Update config to disable feature when set to 0 * update text to make more sense * Update token logic to more accurately determine when tokens are created * Update broken UI test * Add support for custom auth token expire date in UI and API (#23340) * Add support for custom auth token expire date in UI and API * Apply initial review feedback - require token expire date to be in future - refactor and simplify controller logic - remove unsude model method params - always display expire column in the list of tokens - pass default expiration to help text * Update config name to match emails-related work * Update UI test screenshot where expire date column is always visible * Update UI test screenshot with new global config options * Move initial expire date calculation to back-end * Use mock date for tests * Update UI tests * Update UI test screenshots * Update UI test screenshots * Move logic to override Tests.now to the Date class * Remove unused use statement * Update UI test screenshots * Tweak Date logic around Tests.now * Fix datepicker visibility * Add UI test for token expiration date picker * Fix 'label for a missing id' accessibility issue * Use custom fixture not to impact other tests * Fix CS * Fix fixture namespacing and use correct fixture in tests * Uncomment code commented out when debugging * Ensure initial date is set correctly for the date picker * Test config change to a different token expire interval * Update screenshot after config wording change * Remove unused function * Build vue components * Update expected screenshots * Remove obsolete comments * Allow numeric strings in Tests.now * Accept only values representing dates over 1990-01-01 in Tests.now * set date correctly for tests --------- Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: sgiehl <stefan@matomo.org> --------- Co-authored-by: Nathan Gavin <nathangavin987@gmail.com> Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: sgiehl <stefan@matomo.org>
164 خطوط
4.9 KiB
PHP
164 خطوط
4.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Matomo - free/libre analytics platform
|
|
*
|
|
* @link https://matomo.org
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
|
*/
|
|
|
|
namespace Piwik\Plugins\UsersManager\tests\Fixtures;
|
|
|
|
use Piwik\Date;
|
|
use Piwik\Plugins\UsersManager\API;
|
|
use Piwik\Plugins\UsersManager\Model;
|
|
use Piwik\Plugins\UsersManager\UserUpdater;
|
|
use Piwik\Tests\Framework\Fixture;
|
|
|
|
/**
|
|
* Generates tracker testing data for our APITest
|
|
*
|
|
* This Simple fixture adds one website and tracks one visit with couple pageviews and an ecommerce conversion
|
|
*/
|
|
class ManyUsers extends Fixture
|
|
{
|
|
public const SITE_COUNT = 100;
|
|
public const USER_COUNT = 100;
|
|
|
|
public $dateTime = '2013-01-23 01:23:45';
|
|
public $idSite = 1;
|
|
public $siteCopyCount;
|
|
public $userCopyCount;
|
|
public $addTextSuffixes;
|
|
public $users = [];
|
|
|
|
public $baseUsers = [
|
|
'login1' => ['superuser' => 1],
|
|
'login2' => ['view' => [3, 5], 'admin' => [1, 2, 6]],
|
|
'login3' => ['view' => [], 'admin' => []], // no access to any site
|
|
'login4' => ['view' => [6], 'admin' => []], // only access to one with view
|
|
'login5' => ['view' => [], 'admin' => [3]], // only access to one with admin
|
|
'login6' => ['view' => [], 'admin' => [6, 3]], // access to a couple of sites with admin
|
|
'login7' => ['view' => [2, 1, 6, 3], 'admin' => []], // access to a couple of sites with view
|
|
'login8' => ['view' => [4, 7], 'admin' => [2, 5]], // access to a couple of sites with admin and view
|
|
'login9' => ['view' => [5, 6], 'admin' => [8, 9]],
|
|
'login10' => ['superuser' => 1]
|
|
];
|
|
|
|
public $pendingUser = [
|
|
'login' => '000pendingUser1',
|
|
'email' => 'pendinguser1light@example.com'
|
|
];
|
|
|
|
public $pendingUser2 = [
|
|
'login' => 'zzzpendingUser2',
|
|
'email' => 'zpendinguser2light@example.com'
|
|
];
|
|
|
|
public $baseSites = [
|
|
'sleep',
|
|
'escapesequence',
|
|
'hunter',
|
|
'transistor',
|
|
'wicket',
|
|
'relentless',
|
|
'scarecrow',
|
|
'nova',
|
|
'resilience',
|
|
'tricks',
|
|
];
|
|
|
|
public $textAdditions = [
|
|
'life',
|
|
'light',
|
|
'flight',
|
|
'conchords',
|
|
];
|
|
|
|
public function __construct(
|
|
$userCopyCount = self::USER_COUNT,
|
|
$siteCopyCount = self::SITE_COUNT,
|
|
$addTextSuffixes = true
|
|
) {
|
|
$this->userCopyCount = $userCopyCount;
|
|
$this->siteCopyCount = $siteCopyCount;
|
|
$this->addTextSuffixes = $addTextSuffixes;
|
|
}
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpWebsite();
|
|
$this->setUpUsers();
|
|
}
|
|
|
|
public function tearDown(): void
|
|
{
|
|
// empty
|
|
}
|
|
|
|
private function setUpWebsite()
|
|
{
|
|
for ($i = 0; $i < self::SITE_COUNT; $i++) {
|
|
$siteName = $this->baseSites[$i % count($this->baseSites)];
|
|
if ($i != 0) {
|
|
$siteName .= $i;
|
|
}
|
|
Fixture::createWebsite('2010-01-01 00:00:00', $ecommerce = 0, $siteName);
|
|
}
|
|
}
|
|
|
|
protected function setUpUsers()
|
|
{
|
|
$totalUserCount = 0;
|
|
|
|
$model = new Model();
|
|
$api = API::getInstance();
|
|
|
|
// add a pending invite user
|
|
$api->inviteUser($this->pendingUser['login'], $this->pendingUser['email'], 1);
|
|
|
|
for ($i = 0; $i != $this->userCopyCount; ++$i) {
|
|
$addToEmail = $i % 2 == 0;
|
|
|
|
foreach ($this->baseUsers as $baseLogin => $permissions) {
|
|
++$totalUserCount;
|
|
|
|
$textAddition = $this->textAdditions[$totalUserCount % count($this->textAdditions)];
|
|
|
|
$login = $this->addTextSuffixes ? ($i . $baseLogin) : $baseLogin;
|
|
if ($this->addTextSuffixes && !$addToEmail) {
|
|
$login .= $textAddition;
|
|
}
|
|
|
|
$email = $login . '@example.com';
|
|
if ($this->addTextSuffixes && $addToEmail) {
|
|
$email = $login . $textAddition . '@example.com';
|
|
}
|
|
|
|
$api->addUser($login, 'password', $email);
|
|
|
|
foreach ($permissions as $access => $idSites) {
|
|
if (empty($idSites)) {
|
|
continue;
|
|
}
|
|
|
|
if ($access == 'superuser') {
|
|
$userUpdater = new UserUpdater();
|
|
$userUpdater->setSuperUserAccessWithoutCurrentPassword($login, true);
|
|
} else {
|
|
$api->setUserAccess($login, $access, $idSites);
|
|
}
|
|
}
|
|
|
|
$tokenAuth = $model->generateRandomTokenAuth();
|
|
$model->addTokenAuth($login, $tokenAuth, 'many users test', Date::now()->getDatetime());
|
|
$this->users[$login]['token'] = $tokenAuth;
|
|
}
|
|
}
|
|
|
|
//add admin view pending user
|
|
$api->inviteUser($this->pendingUser2['login'], $this->pendingUser2['email'], 1);
|
|
$model->updateUserFields($this->pendingUser2['login'], ['invited_by' => 'login2']);
|
|
}
|
|
}
|