diff --git a/packages/cli/src/commands/addBlockRules.ts b/packages/cli/src/commands/addBlockRules.ts index a21e668a2..88d1ad78a 100644 --- a/packages/cli/src/commands/addBlockRules.ts +++ b/packages/cli/src/commands/addBlockRules.ts @@ -79,6 +79,7 @@ export default ( await tasks.clientTaskManager.addUserBlockRules( argv.users as unknown as string[], argv.hardBlock as boolean, + argv.global as boolean, argv.dapp as unknown as string, ); } diff --git a/packages/provider/src/tasks/client/clientTasks.ts b/packages/provider/src/tasks/client/clientTasks.ts index 08c7ad4a4..e0200e70f 100644 --- a/packages/provider/src/tasks/client/clientTasks.ts +++ b/packages/provider/src/tasks/client/clientTasks.ts @@ -233,7 +233,8 @@ export class ClientTaskManager { async addUserBlockRules( userAccounts: string[], hardBlock: boolean, - dappAccount: string, + global: boolean, + dappAccount?: string, ): Promise { validateAddress(dappAccount, false, 42); const rules: UserAccountBlockRule[] = userAccounts.map((userAccount) => { @@ -242,8 +243,7 @@ export class ClientTaskManager { dappAccount, userAccount, type: BlockRuleType.userAccount, - // TODO don't store global on these - global: false, + global, hardBlock, }; }); diff --git a/packages/types-database/src/types/provider.ts b/packages/types-database/src/types/provider.ts index 8f01da490..4404ded18 100644 --- a/packages/types-database/src/types/provider.ts +++ b/packages/types-database/src/types/provider.ts @@ -59,13 +59,16 @@ export type IUserDataSlim = Pick; export type ClientRecord = IUserDataSlim & Document; -const ONE_WEEK = 60 * 60 * 24 * 7; +const ONE_DAY = 60 * 60 * 24; +const ONE_WEEK = ONE_DAY * 7; const ONE_MONTH = ONE_WEEK * 4; export const ClientRecordSchema = new Schema({ account: String, settings: UserSettingsSchema, }); +// Set an index on the account field, ascending +ClientRecordSchema.index({ account: 1 }); export enum StoredStatusNames { notStored = "notStored", @@ -193,7 +196,7 @@ export const PoWCaptchaRecordSchema = new Schema( ); // Set an index on the captchaId field, ascending -PoWCaptchaRecordSchema.index({ captchaId: 1 }); +PoWCaptchaRecordSchema.index({ challenge: 1 }); export const UserCommitmentRecordSchema = new Schema({ userAccount: { type: String, required: true }, @@ -331,10 +334,13 @@ export type Session = { export type SessionRecord = mongoose.Document & Session; -export const SessionRecordSchema = new Schema({ - sessionId: { type: String, required: true, unique: true }, - createdAt: { type: Date, required: true }, -}); +export const SessionRecordSchema = new Schema( + { + sessionId: { type: String, required: true, unique: true }, + createdAt: { type: Date, required: true }, + }, + { expireAfterSeconds: ONE_DAY }, +); type BlockRule = { global: boolean; @@ -353,7 +359,7 @@ export interface IPAddressBlockRule extends BlockRule { } export interface UserAccountBlockRule extends BlockRule { - dappAccount: string; + dappAccount?: string; userAccount: string; } @@ -375,16 +381,18 @@ export const IPBlockRuleRecordSchema = new Schema({ }); IPBlockRuleRecordSchema.index({ ip: 1 }, { unique: true }); +IPBlockRuleRecordSchema.index({ ip: 1, dappAccount: 1 }, { unique: true }); export const UserAccountBlockRuleSchema = new Schema({ - dappAccount: { type: String, required: true }, + dappAccount: { type: String, required: false }, userAccount: { type: String, required: true }, global: { type: Boolean, required: true }, hardBlock: { type: Boolean, required: false }, type: { type: String, enum: BlockRuleType, required: true }, }); +UserAccountBlockRuleSchema.index({ userAccount: 1 }, { unique: true }); UserAccountBlockRuleSchema.index( { dappAccount: 1, userAccount: 1 }, { unique: true },