Skip to content

Commit

Permalink
[PLA-1696] Remove scopes for rules in service classes. (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
v16Studios authored Mar 26, 2024
1 parent b93b2d7 commit cf0b5e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/Services/Database/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function insert(array $data): bool
*/
public function attributeExistsInCollection(string $collectionId, string $key): bool
{
return Attribute::with('collection')
return Attribute::withoutGlobalScopes()->with('collection')
->whereRelation('collection', 'collection_chain_id', $collectionId)
->where('key', '=', $key)
->exists();
Expand All @@ -61,7 +61,7 @@ public function accountExistsInCollection(string $collectionId, string $account)
{
$accountWallet = $this->walletService->firstOrStore(['public_key' => SS58Address::getPublicKey($account)]);

return CollectionAccount::with('collection')
return CollectionAccount::withoutGlobalScopes()->with('collection')
->whereRelation('collection', 'collection_chain_id', $collectionId)
->where('wallet_id', '=', $accountWallet->id)
->exists();
Expand All @@ -77,7 +77,7 @@ public function approvalExistsInCollection(
): bool {
$operatorWallet = $this->walletService->firstOrStore(['public_key' => SS58Address::getPublicKey($operator)]);

$collectionAccount = CollectionAccount::with(['collection', 'wallet'])
$collectionAccount = CollectionAccount::withoutGlobalScopes()->with(['collection', 'wallet'])
->whereRelation('collection', 'collection_chain_id', $collectionId)
->when(
$hasAccountForDaemon,
Expand All @@ -89,7 +89,7 @@ public function approvalExistsInCollection(
return false;
}

return CollectionAccountApproval::with(['account', 'wallet'])
return CollectionAccountApproval::withoutGlobalScopes()->with(['account', 'wallet'])
->whereBelongsTo($collectionAccount, 'account')
->whereBelongsTo($operatorWallet, 'wallet')
->exists();
Expand Down
30 changes: 15 additions & 15 deletions src/Services/Database/TokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function updateOrStore(array $keys, array $data): Model
public function tokenBalanceForAccount(string $collectionId, string $tokenId, ?string $address = null): string
{
$publicKey = !empty($address) ? SS58Address::getPublicKey($address) : Account::daemon()->public_key;
if (!($accountWallet = Wallet::firstWhere(['public_key' => $publicKey]))
|| !($collection = Collection::firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
if (!($accountWallet = Wallet::withoutGlobalScopes()->firstWhere(['public_key' => $publicKey]))
|| !($collection = Collection::withoutGlobalScopes()->firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::withoutGlobalScopes()->firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
) {
return '0';
}

$tokenAccount = TokenAccount::whereCollectionId($collection->id)
$tokenAccount = TokenAccount::withoutGlobalScopes()->whereCollectionId($collection->id)
->whereTokenId($token->id)
->whereWalletId($accountWallet->id)
->first();
Expand All @@ -74,13 +74,13 @@ public function tokenBalanceForAccount(string $collectionId, string $tokenId, ?s
public function accountExistsInToken(string $collectionId, string $tokenId, string $account): bool
{
$accountWallet = $this->walletService->firstOrStore(['public_key' => SS58Address::getPublicKey($account)]);
if (!($collection = Collection::firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
if (!($collection = Collection::withoutGlobalScopes()->firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::withoutGlobalScopes()->firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
) {
return false;
}

return TokenAccount::whereCollectionId($collection->id)
return TokenAccount::withoutGlobalScopes()->whereCollectionId($collection->id)
->whereTokenId($token->id)
->whereWalletId($accountWallet->id)
->exists();
Expand All @@ -91,13 +91,13 @@ public function accountExistsInToken(string $collectionId, string $tokenId, stri
*/
public function attributeExistsInToken(string $collectionId, string $tokenId, string $key): bool
{
if (!($collection = Collection::firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
if (!($collection = Collection::withoutGlobalScopes()->firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::withoutGlobalScopes()->firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
) {
return false;
}

return Attribute::whereCollectionId($collection->id)
return Attribute::withoutGlobalScopes()->whereCollectionId($collection->id)
->whereTokenId($token->id)
->where('key', '=', $key)
->exists();
Expand All @@ -119,13 +119,13 @@ public function tokenExistsInCollection(string $tokenId, $collectionId)
public function approvalExistsInToken(string $collectionId, string $tokenId, string $operator): bool
{
$operatorWallet = $this->walletService->firstOrStore(['public_key' => SS58Address::getPublicKey($operator)]);
if (!($collection = Collection::firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
if (!($collection = Collection::withoutGlobalScopes()->firstWhere(['collection_chain_id' => $collectionId]))
|| !($token = Token::withoutGlobalScopes()->firstWhere(['token_chain_id' => $tokenId, 'collection_id' => $collection->id]))
) {
return false;
}

$tokenAccount = TokenAccount::whereCollectionId($collection->id)
$tokenAccount = TokenAccount::withoutGlobalScopes()->whereCollectionId($collection->id)
->whereTokenId($token->id)
->where('wallet_id', '=', Account::daemon()->id)
->first();
Expand All @@ -134,7 +134,7 @@ public function approvalExistsInToken(string $collectionId, string $tokenId, str
return false;
}

return TokenAccountApproval::where('token_account_id', $tokenAccount->id)
return TokenAccountApproval::withoutGlobalScopes()->where('token_account_id', $tokenAccount->id)
->where('wallet_id', $operatorWallet->id)
->exists();
}
Expand Down Expand Up @@ -168,6 +168,6 @@ public function getTokensFromCollection($collectionId, ?array $tokenIds = null,
*/
protected function inCollection($collectionId): Builder
{
return Token::with('collection')->whereRelation('collection', 'collection_chain_id', $collectionId);
return Token::withoutGlobalScopes()->with('collection')->whereRelation('collection', 'collection_chain_id', $collectionId);
}
}
2 changes: 1 addition & 1 deletion src/Services/Database/WalletService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function firstOrStore(array $key, $data = []): Model
*/
public function accountExistsInWallet(string $account): bool
{
return Wallet::where(['public_key' => SS58Address::getPublicKey($account)])->exists();
return Wallet::withoutGlobalScopes()->where(['public_key' => SS58Address::getPublicKey($account)])->exists();
}

/**
Expand Down

0 comments on commit cf0b5e7

Please sign in to comment.