Skip to content

Commit

Permalink
Merge pull request #2103 from akto-api-security/hotfix/fix_usage_refe…
Browse files Browse the repository at this point in the history
…rsh_API

use current account instead of any account
  • Loading branch information
Ark2307 authored Feb 15, 2025
2 parents 23aa363 + 1d9d46e commit 066e334
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.akto.dto.type.SingleTypeInfo;
import com.akto.dao.billing.OrganizationsDao;
import com.akto.dao.context.Context;
import com.akto.dto.User;
import com.akto.log.LoggerMaker;
import com.akto.log.LoggerMaker.LogDb;
import com.akto.util.DashboardMode;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class UsageAction extends UserAction {

public static final HashSet<String> freeDomainsSet = new HashSet<>(Arrays.asList(freeDomains));

private static final LoggerMaker loggerMaker = new LoggerMaker(UsageAction.class);
private static final LoggerMaker loggerMaker = new LoggerMaker(UsageAction.class, LogDb.DASHBOARD);

String customerId;
String planId;
Expand Down Expand Up @@ -124,23 +123,25 @@ public String getCustomerStiggDetails() {
return SUCCESS.toUpperCase();
}

public String refreshUsageData(){
User sUser = getSUser();
int anyAccountId = Integer.parseInt(sUser.findAnyAccountId());
public String refreshUsageData() {
int currentAccountId = Context.accountId.get();

Organization organization = OrganizationsDao.instance.findOne(
Filters.in(Organization.ACCOUNTS, anyAccountId));
Filters.in(Organization.ACCOUNTS, currentAccountId));

if(organization == null){
addActionError("Organization not found");
return ERROR.toUpperCase();
}

loggerMaker.infoAndAddToDb("Calculating usage for organization: " + organization.getId() + " adminEmail: "
+ organization.getAdminEmail(), LogDb.DASHBOARD);

// calculation may take time, so we do it in a separate thread to avoid timeout.
executorService.schedule(new Runnable() {
public void run() {

OrgUtils.getSiblingAccounts(anyAccountId).forEach(account -> {
OrgUtils.getSiblingAccounts(currentAccountId).forEach(account -> {
loggerMaker.infoAndAddToDb("Calculating usage for account: " + account.getId(),
LogDb.DASHBOARD);
Context.accountId.set(account.getId());
Expand Down

0 comments on commit 066e334

Please sign in to comment.