forked from dart-lang/pub-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin actions for minimal package, version and publisher info. (dart-…
- Loading branch information
Showing
7 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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/package/backend.dart'; | ||
|
||
import 'actions.dart'; | ||
|
||
final packageInfo = AdminAction( | ||
name: 'package-info', | ||
summary: 'Gets the package information.', | ||
description: ''' | ||
Loads and displays the package information. | ||
''', | ||
options: { | ||
'package': 'The package to be loaded.', | ||
}, | ||
invoke: (options) async { | ||
final package = options['package']; | ||
InvalidInputException.check( | ||
package != null && package.isNotEmpty, | ||
'`package` must be given', | ||
); | ||
|
||
final p = await packageBackend.lookupPackage(package!); | ||
if (p == null) { | ||
throw NotFoundException.resource(package); | ||
} | ||
|
||
return { | ||
'package': { | ||
'name': p.name, | ||
'created': p.created?.toIso8601String(), | ||
'publisherId': p.publisherId, | ||
'latestVersion': p.latestVersion, | ||
'isModerated': p.isModerated, | ||
if (p.moderatedAt != null) | ||
'moderatedAt': p.moderatedAt?.toIso8601String(), | ||
}, | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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/package/backend.dart'; | ||
|
||
import 'actions.dart'; | ||
|
||
final packageVersionInfo = AdminAction( | ||
name: 'package-version-info', | ||
summary: 'Gets the package version information.', | ||
description: ''' | ||
Loads and displays the package version information. | ||
''', | ||
options: { | ||
'package': 'The package to be loaded.', | ||
'version': 'The version to be loaded.', | ||
}, | ||
invoke: (options) async { | ||
final package = options['package']; | ||
InvalidInputException.check( | ||
package != null && package.isNotEmpty, | ||
'`package` must be given', | ||
); | ||
|
||
final version = options['version']; | ||
InvalidInputException.check( | ||
version != null && version.isNotEmpty, | ||
'`version` must be given', | ||
); | ||
|
||
final pv = await packageBackend.lookupPackageVersion(package!, version!); | ||
if (pv == null) { | ||
throw NotFoundException.resource('$package/$version'); | ||
} | ||
|
||
return { | ||
'package-version': { | ||
'package': pv.package, | ||
'version': pv.version, | ||
'created': pv.created?.toIso8601String(), | ||
'isModerated': pv.isModerated, | ||
if (pv.moderatedAt != null) | ||
'moderatedAt': pv.moderatedAt?.toIso8601String(), | ||
}, | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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/publisher/backend.dart'; | ||
|
||
import 'actions.dart'; | ||
|
||
final publisherInfo = AdminAction( | ||
name: 'publisher-info', | ||
summary: 'Gets the publisher information.', | ||
description: ''' | ||
Loads and displays the publisher information. | ||
''', | ||
options: { | ||
'publisher': 'The publisherId to be loaded.', | ||
}, | ||
invoke: (options) async { | ||
final publisherId = options['publisher']; | ||
InvalidInputException.check( | ||
publisherId != null && publisherId.isNotEmpty, | ||
'`publisher` must be given', | ||
); | ||
|
||
final p = await publisherBackend.getPublisher(publisherId!); | ||
if (p == null) { | ||
throw NotFoundException.resource(publisherId); | ||
} | ||
|
||
return { | ||
'publisher': { | ||
'publisherId': p.publisherId, | ||
'created': p.created?.toIso8601String(), | ||
'contactEmail': p.contactEmail, | ||
'isModerated': p.isModerated, | ||
if (p.moderatedAt != null) | ||
'moderatedAt': p.moderatedAt?.toIso8601String(), | ||
}, | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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_shared/data/admin_api.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../shared/test_models.dart'; | ||
import '../shared/test_services.dart'; | ||
|
||
void main() { | ||
// TODO: move package-related tests from api_actions_test.dart | ||
group('package admin actions', () { | ||
testWithProfile('info request', fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
final rs = await client.adminInvokeAction( | ||
'package-info', | ||
AdminInvokeActionArguments(arguments: { | ||
'package': 'oxygen', | ||
}), | ||
); | ||
expect(rs.output, { | ||
'package': { | ||
'name': 'oxygen', | ||
'created': isNotEmpty, | ||
'publisherId': null, | ||
'latestVersion': '1.2.0', | ||
'isModerated': false, | ||
} | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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_shared/data/admin_api.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../shared/test_models.dart'; | ||
import '../shared/test_services.dart'; | ||
|
||
void main() { | ||
// TODO: move package-version-related tests from api_actions_test.dart | ||
group('package version admin actions', () { | ||
testWithProfile('info request', fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
final rs = await client.adminInvokeAction( | ||
'package-version-info', | ||
AdminInvokeActionArguments(arguments: { | ||
'package': 'oxygen', | ||
'version': '1.2.0', | ||
}), | ||
); | ||
expect(rs.output, { | ||
'package-version': { | ||
'package': 'oxygen', | ||
'version': '1.2.0', | ||
'created': isNotEmpty, | ||
'isModerated': false, | ||
} | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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_shared/data/admin_api.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../shared/test_models.dart'; | ||
import '../shared/test_services.dart'; | ||
|
||
void main() { | ||
// TODO: move publisher-related tests from api_actions_test.dart | ||
group('publisher admin actions', () { | ||
testWithProfile('info request', fn: () async { | ||
final client = createPubApiClient(authToken: siteAdminToken); | ||
final rs = await client.adminInvokeAction( | ||
'publisher-info', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'example.com', | ||
}), | ||
); | ||
expect(rs.output, { | ||
'publisher': { | ||
'publisherId': 'example.com', | ||
'created': isNotEmpty, | ||
'contactEmail': '[email protected]', | ||
'isModerated': false | ||
}, | ||
}); | ||
}); | ||
}); | ||
} |