Skip to content

Commit 63992f7

Browse files
authored
Admin actions for minimal package, version and publisher info. (#8000)
1 parent 5e3c32a commit 63992f7

File tree

7 files changed

+235
-0
lines changed

7 files changed

+235
-0
lines changed

app/lib/admin/actions/actions.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ import 'moderation_case_info.dart';
1717
import 'moderation_case_list.dart';
1818
import 'moderation_case_resolve.dart';
1919
import 'moderation_case_update.dart';
20+
import 'package_info.dart';
21+
import 'package_version_info.dart';
2022
import 'package_version_retraction.dart';
2123
import 'publisher_block.dart';
2224
import 'publisher_create.dart';
2325
import 'publisher_delete.dart';
26+
import 'publisher_info.dart';
2427
import 'publisher_members_list.dart';
2528
import 'publisher_package_remove.dart';
2629
import 'task_bump_priority.dart';
@@ -94,10 +97,13 @@ final class AdminAction {
9497
moderationCaseList,
9598
moderationCaseResolve,
9699
moderationCaseUpdate,
100+
packageInfo,
101+
packageVersionInfo,
97102
packageVersionRetraction,
98103
publisherBlock,
99104
publisherCreate,
100105
publisherDelete,
106+
publisherInfo,
101107
publisherMembersList,
102108
publisherPackageRemove,
103109
taskBumpPriority,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub_dev/package/backend.dart';
6+
7+
import 'actions.dart';
8+
9+
final packageInfo = AdminAction(
10+
name: 'package-info',
11+
summary: 'Gets the package information.',
12+
description: '''
13+
Loads and displays the package information.
14+
''',
15+
options: {
16+
'package': 'The package to be loaded.',
17+
},
18+
invoke: (options) async {
19+
final package = options['package'];
20+
InvalidInputException.check(
21+
package != null && package.isNotEmpty,
22+
'`package` must be given',
23+
);
24+
25+
final p = await packageBackend.lookupPackage(package!);
26+
if (p == null) {
27+
throw NotFoundException.resource(package);
28+
}
29+
30+
return {
31+
'package': {
32+
'name': p.name,
33+
'created': p.created?.toIso8601String(),
34+
'publisherId': p.publisherId,
35+
'latestVersion': p.latestVersion,
36+
'isModerated': p.isModerated,
37+
if (p.moderatedAt != null)
38+
'moderatedAt': p.moderatedAt?.toIso8601String(),
39+
},
40+
};
41+
},
42+
);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub_dev/package/backend.dart';
6+
7+
import 'actions.dart';
8+
9+
final packageVersionInfo = AdminAction(
10+
name: 'package-version-info',
11+
summary: 'Gets the package version information.',
12+
description: '''
13+
Loads and displays the package version information.
14+
''',
15+
options: {
16+
'package': 'The package to be loaded.',
17+
'version': 'The version to be loaded.',
18+
},
19+
invoke: (options) async {
20+
final package = options['package'];
21+
InvalidInputException.check(
22+
package != null && package.isNotEmpty,
23+
'`package` must be given',
24+
);
25+
26+
final version = options['version'];
27+
InvalidInputException.check(
28+
version != null && version.isNotEmpty,
29+
'`version` must be given',
30+
);
31+
32+
final pv = await packageBackend.lookupPackageVersion(package!, version!);
33+
if (pv == null) {
34+
throw NotFoundException.resource('$package/$version');
35+
}
36+
37+
return {
38+
'package-version': {
39+
'package': pv.package,
40+
'version': pv.version,
41+
'created': pv.created?.toIso8601String(),
42+
'isModerated': pv.isModerated,
43+
if (pv.moderatedAt != null)
44+
'moderatedAt': pv.moderatedAt?.toIso8601String(),
45+
},
46+
};
47+
},
48+
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub_dev/publisher/backend.dart';
6+
7+
import 'actions.dart';
8+
9+
final publisherInfo = AdminAction(
10+
name: 'publisher-info',
11+
summary: 'Gets the publisher information.',
12+
description: '''
13+
Loads and displays the publisher information.
14+
''',
15+
options: {
16+
'publisher': 'The publisherId to be loaded.',
17+
},
18+
invoke: (options) async {
19+
final publisherId = options['publisher'];
20+
InvalidInputException.check(
21+
publisherId != null && publisherId.isNotEmpty,
22+
'`publisher` must be given',
23+
);
24+
25+
final p = await publisherBackend.getPublisher(publisherId!);
26+
if (p == null) {
27+
throw NotFoundException.resource(publisherId);
28+
}
29+
30+
return {
31+
'publisher': {
32+
'publisherId': p.publisherId,
33+
'created': p.created?.toIso8601String(),
34+
'contactEmail': p.contactEmail,
35+
'isModerated': p.isModerated,
36+
if (p.moderatedAt != null)
37+
'moderatedAt': p.moderatedAt?.toIso8601String(),
38+
},
39+
};
40+
},
41+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:_pub_shared/data/admin_api.dart';
6+
import 'package:test/test.dart';
7+
8+
import '../shared/test_models.dart';
9+
import '../shared/test_services.dart';
10+
11+
void main() {
12+
// TODO: move package-related tests from api_actions_test.dart
13+
group('package admin actions', () {
14+
testWithProfile('info request', fn: () async {
15+
final client = createPubApiClient(authToken: siteAdminToken);
16+
final rs = await client.adminInvokeAction(
17+
'package-info',
18+
AdminInvokeActionArguments(arguments: {
19+
'package': 'oxygen',
20+
}),
21+
);
22+
expect(rs.output, {
23+
'package': {
24+
'name': 'oxygen',
25+
'created': isNotEmpty,
26+
'publisherId': null,
27+
'latestVersion': '1.2.0',
28+
'isModerated': false,
29+
}
30+
});
31+
});
32+
});
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:_pub_shared/data/admin_api.dart';
6+
import 'package:test/test.dart';
7+
8+
import '../shared/test_models.dart';
9+
import '../shared/test_services.dart';
10+
11+
void main() {
12+
// TODO: move package-version-related tests from api_actions_test.dart
13+
group('package version admin actions', () {
14+
testWithProfile('info request', fn: () async {
15+
final client = createPubApiClient(authToken: siteAdminToken);
16+
final rs = await client.adminInvokeAction(
17+
'package-version-info',
18+
AdminInvokeActionArguments(arguments: {
19+
'package': 'oxygen',
20+
'version': '1.2.0',
21+
}),
22+
);
23+
expect(rs.output, {
24+
'package-version': {
25+
'package': 'oxygen',
26+
'version': '1.2.0',
27+
'created': isNotEmpty,
28+
'isModerated': false,
29+
}
30+
});
31+
});
32+
});
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:_pub_shared/data/admin_api.dart';
6+
import 'package:test/test.dart';
7+
8+
import '../shared/test_models.dart';
9+
import '../shared/test_services.dart';
10+
11+
void main() {
12+
// TODO: move publisher-related tests from api_actions_test.dart
13+
group('publisher admin actions', () {
14+
testWithProfile('info request', fn: () async {
15+
final client = createPubApiClient(authToken: siteAdminToken);
16+
final rs = await client.adminInvokeAction(
17+
'publisher-info',
18+
AdminInvokeActionArguments(arguments: {
19+
'publisher': 'example.com',
20+
}),
21+
);
22+
expect(rs.output, {
23+
'publisher': {
24+
'publisherId': 'example.com',
25+
'created': isNotEmpty,
26+
'contactEmail': 'admin@pub.dev',
27+
'isModerated': false
28+
},
29+
});
30+
});
31+
});
32+
}

0 commit comments

Comments
 (0)