mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Remove minecraft_access_keys table and all related code
This commit is contained in:
		| @@ -46,7 +46,6 @@ use const common\LATEST_RULES_VERSION; | ||||
|  * @property-read OauthClient[] $oauthClients | ||||
|  * @property-read UsernameHistory[] $usernameHistory | ||||
|  * @property-read AccountSession[] $sessions | ||||
|  * @property-read MinecraftAccessKey[] $minecraftAccessKeys | ||||
|  * | ||||
|  * Behaviors: | ||||
|  * @mixin TimestampBehavior | ||||
| @@ -121,10 +120,6 @@ class Account extends ActiveRecord { | ||||
|         return $this->hasMany(AccountSession::class, ['account_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public function getMinecraftAccessKeys(): ActiveQuery { | ||||
|         return $this->hasMany(MinecraftAccessKey::class, ['account_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public function hasMojangUsernameCollision(): bool { | ||||
|         return MojangUsername::find() | ||||
|             ->andWhere(['username' => $this->username]) | ||||
|   | ||||
| @@ -1,63 +0,0 @@ | ||||
| <?php | ||||
| namespace common\models; | ||||
|  | ||||
| use common\behaviors\PrimaryKeyValueBehavior; | ||||
| use Ramsey\Uuid\Uuid; | ||||
| use yii\behaviors\TimestampBehavior; | ||||
| use yii\db\ActiveRecord; | ||||
|  | ||||
| /** | ||||
|  * This is a temporary class where all the logic of the authserver.ely.by service. | ||||
|  * Since the login and password were allowed there, and the format of storage of the issued tokens was different, | ||||
|  * we need to keep the legacy logic and structure under it for the period until we finally migrate. | ||||
|  * | ||||
|  * Fields: | ||||
|  * @property string  $access_token | ||||
|  * @property string  $client_token | ||||
|  * @property integer $account_id | ||||
|  * @property integer $created_at | ||||
|  * @property integer $updated_at | ||||
|  * | ||||
|  * Relations: | ||||
|  * @property Account $account | ||||
|  * | ||||
|  * Behaviors: | ||||
|  * @mixin TimestampBehavior | ||||
|  * @mixin PrimaryKeyValueBehavior | ||||
|  * | ||||
|  * @deprecated This table is no longer used to store authorization information in Minecraft. | ||||
|  * In time it will be empty (see the cleanup console command) and when it does, this model, | ||||
|  * the table in the database and everything related to the old logic can be removed. | ||||
|  */ | ||||
| class MinecraftAccessKey extends ActiveRecord { | ||||
|  | ||||
|     public const LIFETIME = 172800; // Ключ актуален в течение 2 дней | ||||
|  | ||||
|     public static function tableName(): string { | ||||
|         return '{{%minecraft_access_keys}}'; | ||||
|     } | ||||
|  | ||||
|     public function behaviors(): array { | ||||
|         return [ | ||||
|             [ | ||||
|                 'class' => TimestampBehavior::class, | ||||
|             ], | ||||
|             [ | ||||
|                 'class' => PrimaryKeyValueBehavior::class, | ||||
|                 'value' => function() { | ||||
|                     return Uuid::uuid4()->toString(); | ||||
|                 }, | ||||
|             ], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function getAccount(): AccountQuery { | ||||
|         /** @noinspection PhpIncompatibleReturnTypeInspection */ | ||||
|         return $this->hasOne(Account::class, ['id' => 'account_id']); | ||||
|     } | ||||
|  | ||||
|     public function isExpired(): bool { | ||||
|         return time() > $this->updated_at + self::LIFETIME; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -47,11 +47,6 @@ final class ClearAccountSessions implements RetryableJobInterface { | ||||
|             $authSession->delete(); | ||||
|         } | ||||
|  | ||||
|         /** @var \common\models\MinecraftAccessKey $key */ | ||||
|         foreach ($account->getMinecraftAccessKeys()->each(100, Yii::$app->unbufferedDb) as $key) { | ||||
|             $key->delete(); | ||||
|         } | ||||
|  | ||||
|         /** @var \common\models\OauthSession $oauthSession */ | ||||
|         foreach ($account->getOauthSessions()->each(100, Yii::$app->unbufferedDb) as $oauthSession) { | ||||
|             $oauthSession->delete(); | ||||
|   | ||||
| @@ -56,7 +56,6 @@ class FixtureHelper extends Module { | ||||
|             'legacyOauthAccessTokens' => fixtures\LegacyOauthAccessTokenFixture::class, | ||||
|             'legacyOauthAccessTokensScopes' => fixtures\LegacyOauthAccessTokenScopeFixture::class, | ||||
|             'legacyOauthRefreshTokens' => fixtures\LegacyOauthRefreshTokenFixture::class, | ||||
|             'minecraftAccessKeys' => fixtures\MinecraftAccessKeyFixture::class, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,17 +0,0 @@ | ||||
| <?php | ||||
| namespace common\tests\fixtures; | ||||
|  | ||||
| use common\models\MinecraftAccessKey; | ||||
| use yii\test\ActiveFixture; | ||||
|  | ||||
| class MinecraftAccessKeyFixture extends ActiveFixture { | ||||
|  | ||||
|     public $modelClass = MinecraftAccessKey::class; | ||||
|  | ||||
|     public $dataFile = '@root/common/tests/fixtures/data/minecraft-access-keys.php'; | ||||
|  | ||||
|     public $depends = [ | ||||
|         AccountFixture::class, | ||||
|     ]; | ||||
|  | ||||
| } | ||||
| @@ -1,31 +0,0 @@ | ||||
| <?php | ||||
| return [ | ||||
|     'admin-token' => [ | ||||
|         'access_token' => 'e7bb6648-2183-4981-9b86-eba5e7f87b42', | ||||
|         'client_token' => '6f380440-0c05-47bd-b7c6-d011f1b5308f', | ||||
|         'account_id' => 1, | ||||
|         'created_at' => time() - 10, | ||||
|         'updated_at' => time() - 10, | ||||
|     ], | ||||
|     'expired-token' => [ | ||||
|         'access_token' => '6042634a-a1e2-4aed-866c-c661fe4e63e2', | ||||
|         'client_token' => '47fb164a-2332-42c1-8bad-549e67bb210c', | ||||
|         'account_id' => 1, | ||||
|         'created_at' => 1472423530, | ||||
|         'updated_at' => 1472423530, | ||||
|     ], | ||||
|     'banned-token' => [ | ||||
|         'access_token' => '918ecb41-616c-40ee-a7d2-0b0ef0d0d732', | ||||
|         'client_token' => '6042634a-a1e2-4aed-866c-c661fe4e63e2', | ||||
|         'account_id' => 10, | ||||
|         'created_at' => time() - 10, | ||||
|         'updated_at' => time() - 10, | ||||
|     ], | ||||
|     'deleted-token' => [ | ||||
|         'access_token' => '239ba889-7020-4383-8d99-cd8c8aab4a2f', | ||||
|         'client_token' => '47443658-4ff8-45e7-b33e-dc8915ab6421', | ||||
|         'account_id' => 15, | ||||
|         'created_at' => time() - 10, | ||||
|         'updated_at' => time() - 10, | ||||
|     ], | ||||
| ]; | ||||
| @@ -17,7 +17,6 @@ class ClearAccountSessionsTest extends TestCase { | ||||
|         return [ | ||||
|             'accounts' => fixtures\AccountFixture::class, | ||||
|             'oauthSessions' => fixtures\OauthSessionFixture::class, | ||||
|             'minecraftAccessKeys' => fixtures\MinecraftAccessKeyFixture::class, | ||||
|             'authSessions' => fixtures\AccountSessionFixture::class, | ||||
|         ]; | ||||
|     } | ||||
| @@ -28,7 +27,6 @@ class ClearAccountSessionsTest extends TestCase { | ||||
|         $task = new ClearAccountSessions($bannedAccount->id); | ||||
|         $task->execute($this->createMock(Queue::class)); | ||||
|         $this->assertEmpty($bannedAccount->sessions); | ||||
|         $this->assertEmpty($bannedAccount->minecraftAccessKeys); | ||||
|         $this->assertEmpty($bannedAccount->oauthSessions); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -19,7 +19,6 @@ class DeleteAccountTest extends TestCase { | ||||
|             'accounts' => fixtures\AccountFixture::class, | ||||
|             'authSessions' => fixtures\AccountSessionFixture::class, | ||||
|             'emailActivations' => fixtures\EmailActivationFixture::class, | ||||
|             'minecraftAccessKeys' => fixtures\MinecraftAccessKeyFixture::class, | ||||
|             'usernamesHistory' => fixtures\UsernameHistoryFixture::class, | ||||
|             'oauthClients' => fixtures\OauthClientFixture::class, | ||||
|             'oauthSessions' => fixtures\OauthSessionFixture::class, | ||||
| @@ -37,7 +36,6 @@ class DeleteAccountTest extends TestCase { | ||||
|         $task->execute($this->createMock(Queue::class)); | ||||
|         $this->assertEmpty($account->emailActivations); | ||||
|         $this->assertEmpty($account->sessions); | ||||
|         $this->assertEmpty($account->minecraftAccessKeys); | ||||
|         $this->assertEmpty($account->oauthSessions); | ||||
|         $this->assertEmpty($account->usernameHistory); | ||||
|         $this->assertEmpty($account->oauthClients); | ||||
| @@ -57,7 +55,6 @@ class DeleteAccountTest extends TestCase { | ||||
|         $task->execute($this->createMock(Queue::class)); | ||||
|         $this->assertNotEmpty($account->emailActivations); | ||||
|         $this->assertNotEmpty($account->sessions); | ||||
|         $this->assertNotEmpty($account->minecraftAccessKeys); | ||||
|         $this->assertNotEmpty($account->oauthSessions); | ||||
|         $this->assertNotEmpty($account->usernameHistory); | ||||
|         $this->assertNotEmpty($account->oauthClients); | ||||
| @@ -80,7 +77,6 @@ class DeleteAccountTest extends TestCase { | ||||
|         $task->execute($this->createMock(Queue::class)); | ||||
|         $this->assertNotEmpty($account->emailActivations); | ||||
|         $this->assertNotEmpty($account->sessions); | ||||
|         $this->assertNotEmpty($account->minecraftAccessKeys); | ||||
|         $this->assertNotEmpty($account->oauthSessions); | ||||
|         $this->assertNotEmpty($account->usernameHistory); | ||||
|         $this->assertNotEmpty($account->oauthClients); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user