Skip to content

Commit

Permalink
restrictAccountWhenStorageLimitReached
Browse files Browse the repository at this point in the history
  • Loading branch information
redsolver committed Aug 26, 2023
1 parent 79c4df3 commit 7933613
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/service/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class AccountsService {
}
}

bool get restrictAccountWhenStorageLimitReached =>
config['restrictAccountWhenStorageLimitReached'] ?? true;

Future<void> init(Alfred app) async {
alwaysAllowedScopes = config['alwaysAllowedScopes']?.cast<String>() ??
defaultAlwaysAllowedScopes;
Expand Down Expand Up @@ -368,13 +371,27 @@ class AccountsService {

final stats = await getStatsForAccount(auth.account!.id);

final tier = tiers[auth.account!.tier]!;

final bool quotaExceeded =
stats['total']['usedStorage'] > tier['storageLimit'];

bool isRestricted = auth.account!.isRestricted;

if (quotaExceeded && !isRestricted) {
if (restrictAccountWhenStorageLimitReached) {
await setRestrictedStatus(auth.account!.id, true);
isRestricted = true;
}
}

return {
"email": auth.account!.email,
"createdAt": auth.account!.createdAt,
"quotaExceeded": false,
"quotaExceeded": quotaExceeded,
"emailConfirmed": false,
"isRestricted": auth.account!.isRestricted,
"tier": tiers[auth.account!.tier],
"isRestricted": isRestricted,
"tier": tier,
"stats": stats,
};
});
Expand Down

0 comments on commit 7933613

Please sign in to comment.