Skip to content

Commit

Permalink
Merge pull request #103 from ainize-team/feature/yoojin/rule_update
Browse files Browse the repository at this point in the history
Admin can use own service without balance check.
  • Loading branch information
yoojinko authored Feb 29, 2024
2 parents 95941aa + 78eda1d commit a4b6c48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`,
value: {
".rule": {
write: "data === null && util.isNumber(newData) && getValue(`/transfer/` + $userAddress + `/` + getValue(`/apps/" + `${appName}` + "/billingConfig/depositAddress`) + `/` + $transferKey + `/value`) === newData"
write:
"data === null && util.isNumber(newData) && " +
"getValue(`/transfer/` + $userAddress + `/` + getValue(`/apps/" + `${appName}` + "/billingConfig/depositAddress`) + `/` + $transferKey + `/value`) === newData"
},
},
},
Expand All @@ -51,7 +53,10 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
ref: `${rootRef}/balance/$userAddress/history/$timestamp`,
value: {
".rule": {
write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isNumber(newData.amount) && (newData.type === 'DEPOSIT' || newData.type === 'USAGE')"
write:
"util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && " +
"util.isDict(newData) && util.isNumber(newData.amount) && " +
"(newData.type === 'DEPOSIT' || newData.type === 'USAGE')",
},
},
},
Expand All @@ -60,9 +65,10 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
value: {
".rule": {
write:
"auth.addr === $userAddress && " +
"util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true || " +
"(auth.addr === $userAddress && " +
"(getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`) === 0 || " +
"(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`)))"
"(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`))))",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export default class Internal {

async handleRequest(req: Request, cost: number, status: RESPONSE_STATUS, responseData: string) {
const { requesterAddress, requestKey, appName } = this.getDataFromServiceRequest(req);
const ops:SetOperation[] = [];
const ops: SetOperation[] = [];
const responseOp = getResponseOp(appName, requesterAddress, requestKey, status, responseData, cost);
ops.push(responseOp);
if(cost > 0) {
if (cost > 0) {
const changeBalanceOp = getChangeBalanceOp(appName, requesterAddress, 'DEC_VALUE', cost);
const writeHistoryOp = getWriteHistoryOp(appName, requesterAddress, HISTORY_TYPE.USAGE, cost, requestKey);
ops.push(changeBalanceOp);
Expand Down

0 comments on commit a4b6c48

Please sign in to comment.