Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin action to list moderation cases. #7799

Merged
merged 1 commit into from
Jun 12, 2024
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
2 changes: 2 additions & 0 deletions app/lib/admin/actions/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'create_moderation_case.dart';
import 'create_publisher.dart';
import 'delete_moderation_case.dart';
import 'delete_publisher.dart';
import 'list_moderation_cases.dart';
import 'merge_moderated_package_into_existing.dart';
import 'moderate_package.dart';
import 'moderate_package_versions.dart';
Expand Down Expand Up @@ -81,6 +82,7 @@ final class AdminAction {
createPublisher,
deleteModerationCase,
deletePublisher,
listModerationCases,
mergeModeratedPackageIntoExisting,
moderatePackage,
moderatePackageVersion,
Expand Down
39 changes: 39 additions & 0 deletions app/lib/admin/actions/list_moderation_cases.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:pub_dev/admin/models.dart';
import 'package:pub_dev/shared/datastore.dart';

import 'actions.dart';

final listModerationCases = AdminAction(
name: 'list-moderation-cases',
summary: 'List the currently active (or resolved) ModerationCase entities.',
description: '''
List the ModerationCase entities with filter options.
''',
options: {
'sort': 'Sort by the given attribute: `opened` (default), `resolved`.',
},
invoke: (options) async {
final sort = options['sort'] ?? 'opened';
final query = dbService.query<ModerationCase>()..limit(20);

switch (sort) {
case 'opened':
query.order('-opened');
break;
case 'resolved':
query.order('-resolved');
break;
default:
throw InvalidInputException('invalid sort value');
}

final list = await query.run().toList();
return {
'cases': list.map((e) => e.toDebugInfo()).toList(),
};
},
);
10 changes: 10 additions & 0 deletions app/test/admin/moderation_case_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ void main() {
'appealedCaseId': null,
'actionLog': {'entries': []}
});

final list = await api.adminInvokeAction(
'list-moderation-cases',
AdminInvokeActionArguments(arguments: {}),
);
expect(list.output, {
'cases': [
rs.output,
],
});
});

testWithProfile('no case parameter', fn: () async {
Expand Down
Loading