Skip to content

Commit

Permalink
Rate limit check done at the time of creating the record (except for …
Browse files Browse the repository at this point in the history
…package publishing). (#7594)
  • Loading branch information
isoos authored Mar 27, 2024
1 parent 7232d49 commit 58b2f0a
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 122 deletions.
54 changes: 27 additions & 27 deletions app/lib/account/consent_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ConsentBackend {
email: uploaderEmail,
kind: ConsentKind.packageUploader,
args: [packageName],
auditLogRecord: AuditLogRecord.uploaderInvited(
auditLogRecord: await AuditLogRecord.uploaderInvited(
agent: agent,
package: packageName,
uploaderEmail: uploaderEmail,
Expand All @@ -180,7 +180,7 @@ class ConsentBackend {
email: contactEmail,
kind: ConsentKind.publisherContact,
args: [publisherId, contactEmail],
auditLogRecord: AuditLogRecord.publisherContactInvited(
auditLogRecord: await AuditLogRecord.publisherContactInvited(
user: user, publisherId: publisherId, contactEmail: contactEmail),
createdBySiteAdmin: false,
);
Expand All @@ -199,7 +199,7 @@ class ConsentBackend {
email: invitedUserEmail,
kind: ConsentKind.publisherMember,
args: [publisherId],
auditLogRecord: AuditLogRecord.publisherMemberInvited(
auditLogRecord: await AuditLogRecord.publisherMemberInvited(
agent: authenticatedAgent,
publisherId: publisherId,
memberEmail: invitedUserEmail,
Expand Down Expand Up @@ -345,26 +345,26 @@ class _PackageUploaderAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final packageName = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.uploaderInviteRejected(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.uploaderInviteRejected(
fromUserId: consent.fromUserId!,
package: packageName,
uploaderEmail: user?.email ?? consent.email!,
userId: user?.userId,
),
]);
));
});
}

@override
Future<void> onExpire(Consent consent) async {
final packageName = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.uploaderInviteExpired(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.uploaderInviteExpired(
fromUserId: consent.fromUserId!,
package: packageName,
uploaderEmail: consent.email!,
),
]);
));
});
}

@override
Expand Down Expand Up @@ -411,27 +411,27 @@ class _PublisherContactAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final publisherId = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.publisherContactInviteRejected(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.publisherContactInviteRejected(
fromUserId: consent.fromUserId!,
publisherId: publisherId,
contactEmail: consent.email!,
userEmail: user?.email,
userId: user?.userId,
),
]);
));
});
}

@override
Future<void> onExpire(Consent consent) async {
final publisherId = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.publisherContactInviteExpired(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.publisherContactInviteExpired(
fromUserId: consent.fromUserId!,
publisherId: publisherId,
contactEmail: consent.email!,
),
]);
));
});
}

@override
Expand Down Expand Up @@ -491,26 +491,26 @@ class _PublisherMemberAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final publisherId = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.publisherMemberInviteRejected(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.publisherMemberInviteRejected(
fromUserId: consent.fromUserId!,
publisherId: publisherId,
memberEmail: user?.email ?? consent.email!,
userId: user?.userId,
),
]);
));
});
}

@override
Future<void> onExpire(Consent consent) async {
final publisherId = consent.args![0];
await dbService.commit(inserts: [
AuditLogRecord.publisherMemberInviteExpired(
await withRetryTransaction(dbService, (tx) async {
tx.insert(await AuditLogRecord.publisherMemberInviteExpired(
fromUserId: consent.fromUserId!,
publisherId: publisherId,
memberEmail: consent.email!,
),
]);
));
});
}

@override
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/create_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This should generally only be done with PM approval as it skips actual domain ve
..created = now
..updated = now
..role = PublisherMemberRole.admin,
AuditLogRecord.publisherCreated(
await AuditLogRecord.publisherCreated(
user: user,
publisherId: publisherId,
),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/remove_package_from_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If the publisher has no members, the package will end up without uploaders.
pkg.updated = clock.now().toUtc();
tx.insert(pkg);
tx.insert(
AuditLogRecord.packageRemovedFromPublisher(
await AuditLogRecord.packageRemovedFromPublisher(
package: packageName,
fromPublisherId: currentPublisherId,
),
Expand Down
4 changes: 2 additions & 2 deletions app/lib/admin/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class AdminBackend {
final r = p.uploaders!.remove(uploaderUser.userId);
if (r) {
removed = true;
tx.insert(AuditLogRecord.uploaderRemoved(
tx.insert(await AuditLogRecord.uploaderRemoved(
agent: authenticatedUser,
package: packageName,
uploaderUser: uploaderUser,
Expand All @@ -658,7 +658,7 @@ class AdminBackend {
if (removed) {
if (p.uploaders!.isEmpty) {
p.isDiscontinued = true;
tx.insert(AuditLogRecord.packageOptionsUpdated(
tx.insert(await AuditLogRecord.packageOptionsUpdated(
agent: authenticatedUser,
package: packageName,
publisherId: p.publisherId,
Expand Down
Loading

0 comments on commit 58b2f0a

Please sign in to comment.