Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions app/lib/admin/actions/moderate_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ Note: the action may take a longer time to complete as the public archive bucket
final note = options['note'];

final refCase =
await adminBackend.loadAndVerifyModerationCaseForAdminAction(
caseId,
status: ModerationStatus.pending,
);
await adminBackend.loadAndVerifyModerationCaseForAdminAction(caseId);

final p = await packageBackend.lookupPackage(package!);
if (p == null) {
Expand Down
5 changes: 1 addition & 4 deletions app/lib/admin/actions/moderate_package_versions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ Set the moderated flag on a package version (updating the flag and the timestamp
final note = options['note'];

final refCase =
await adminBackend.loadAndVerifyModerationCaseForAdminAction(
caseId,
status: ModerationStatus.pending,
);
await adminBackend.loadAndVerifyModerationCaseForAdminAction(caseId);

final p = await packageBackend.lookupPackage(package!);
if (p == null) {
Expand Down
5 changes: 1 addition & 4 deletions app/lib/admin/actions/moderate_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ can't be updated, administrators must not be able to update publisher options.
final note = options['note'];

final refCase =
await adminBackend.loadAndVerifyModerationCaseForAdminAction(
caseId,
status: ModerationStatus.pending,
);
await adminBackend.loadAndVerifyModerationCaseForAdminAction(caseId);

Publisher? publisher2;
if (valueToSet != null) {
Expand Down
6 changes: 1 addition & 5 deletions app/lib/admin/actions/moderate_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import '../../publisher/backend.dart';
import '../../shared/datastore.dart';

import '../backend.dart';
import '../models.dart';

import 'actions.dart';

Expand Down Expand Up @@ -49,10 +48,7 @@ The active web sessions of the user will be expired.
final note = options['note'];

final refCase =
await adminBackend.loadAndVerifyModerationCaseForAdminAction(
caseId,
status: ModerationStatus.pending,
);
await adminBackend.loadAndVerifyModerationCaseForAdminAction(caseId);

User? user;
if (looksLikeUserId(userIdOrEmail!)) {
Expand Down
11 changes: 3 additions & 8 deletions app/lib/admin/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,13 @@ class AdminBackend {
dbService.emptyKey.append(ModerationCase, id: caseId));
}

/// Returns a valid [ModerationCase] if it exists and [status] is matching.
/// Returns a valid [ModerationCase] if it exists.
/// Returns `null` if [caseId] is `none`.
///
/// Throws exceptions otherwise.
Future<ModerationCase?> loadAndVerifyModerationCaseForAdminAction(
String? caseId, {
required String? status,
}) async {
String? caseId,
) async {
InvalidInputException.check(
caseId != null && caseId.isNotEmpty,
'case must be given',
Expand All @@ -769,10 +768,6 @@ class AdminBackend {
if (refCase == null) {
throw NotFoundException.resource(caseId);
}
if (status != null && refCase.status != status) {
throw InvalidInputException(
'ModerationCase.status ("${refCase.status}") != "$status".');
}
return refCase;
}

Expand Down
16 changes: 0 additions & 16 deletions app/test/admin/moderate_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,22 +398,6 @@ void main() {
},
);

testWithProfile('status already closed', fn: () async {
final mc = await _report('oxygen');
await dbService.commit(inserts: [
mc
..resolved = clock.now()
..status = ModerationStatus.noAction
]);

await expectApiException(
_moderate('oxygen', state: true, caseId: mc.caseId),
code: 'InvalidInput',
status: 400,
message: 'ModerationCase.status ("no-action") != "pending".',
);
});

testWithProfile(
'cleanup deletes datastore entities and canonical archive file',
expectedLogMessages: [
Expand Down
16 changes: 0 additions & 16 deletions app/test/admin/moderate_publisher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,6 @@ void main() {
expect(docs3!.where((d) => d.package == 'neon'), isNotEmpty);
});

testWithProfile('status already closed', fn: () async {
final mc = await _report('example.com');
await dbService.commit(inserts: [
mc
..resolved = clock.now()
..status = ModerationStatus.noAction
]);

await expectApiException(
_moderate('example.com', state: true, caseId: mc.caseId),
code: 'InvalidInput',
status: 400,
message: 'ModerationCase.status ("no-action") != "pending".',
);
});

testWithProfile('cleanup deletes datastore entities and abandons packages',
fn: () async {
// moderate and cleanup
Expand Down