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.
Migrate delete-publisher to action framework (dart-lang#7360)
- Loading branch information
Showing
7 changed files
with
93 additions
and
79 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,60 @@ | ||
// 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/actions/actions.dart'; | ||
import 'package:pub_dev/package/models.dart'; | ||
import 'package:pub_dev/publisher/models.dart'; | ||
import 'package:pub_dev/shared/datastore.dart'; | ||
|
||
final deletePublisher = AdminAction( | ||
name: 'delete-publisher', | ||
options: { | ||
'publisher': 'name of publisher to delete', | ||
}, | ||
summary: 'Deletes publisher <publisher>.', | ||
description: ''' | ||
Deletes publisher <publisher>. | ||
The publisher must have no packages. If not the operation will fail. | ||
All member-info will be lost. | ||
The publisher can be regenerated later (no tombstoning). | ||
''', | ||
invoke: (args) async { | ||
final publisherId = args['publisher']; | ||
if (publisherId == null) { | ||
throw InvalidInputException('Missing `publisher` argument'); | ||
} | ||
|
||
final packagesQuery = dbService.query<Package>() | ||
..filter('publisherId =', publisherId); | ||
final packages = await packagesQuery.run().toList(); | ||
if (packages.isNotEmpty) { | ||
throw NotAcceptableException( | ||
'Publisher "$publisherId" cannot be deleted, as it has package(s): ' | ||
'${packages.map((e) => e.name!).join(', ')}.'); | ||
} | ||
|
||
int? memberCount; | ||
await withRetryTransaction(dbService, (tx) async { | ||
final key = dbService.emptyKey.append(Publisher, id: publisherId); | ||
final publisher = await tx.lookupOrNull<Publisher>(key); | ||
final membersQuery = tx.query<PublisherMember>(key); | ||
final members = await membersQuery.run().toList(); | ||
memberCount = members.length; | ||
if (publisher != null) { | ||
tx.delete(key); | ||
} | ||
for (final m in members) { | ||
tx.delete(m.key); | ||
} | ||
}); | ||
|
||
return { | ||
'message': 'Publisher and all members deleted.', | ||
'publisherId': publisherId, | ||
'members-count': memberCount, | ||
}; | ||
}); |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
// 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 'dart:convert'; | ||
|
||
import 'package:_pub_shared/data/admin_api.dart'; | ||
import 'package:clock/clock.dart'; | ||
import 'package:pub_dev/account/backend.dart'; | ||
|
@@ -53,7 +51,7 @@ void main() { | |
'create-publisher', | ||
AdminInvokeActionArguments(arguments: { | ||
'publisher': 'other.com', | ||
'member-email': '[email protected]' | ||
'member-email': '[email protected]', | ||
}), | ||
); | ||
expect(rs1.output, { | ||
|
@@ -79,15 +77,13 @@ void main() { | |
}); | ||
final p1 = await publisherBackend.getPublisher('other.com'); | ||
expect(p1, isNotNull); | ||
// TODO(sigurdm): Migrate delete-publisher to be an Action. | ||
final rs2 = await client.adminExecuteTool( | ||
'delete-publisher', | ||
Uri(pathSegments: [ | ||
'--publisher', | ||
'other.com', | ||
]).toString(), | ||
); | ||
expect(utf8.decode(rs2), 'Publisher and 1 member(s) deleted.'); | ||
final rs2 = await client.adminInvokeAction('delete-publisher', | ||
AdminInvokeActionArguments(arguments: {'publisher': 'other.com'})); | ||
expect(rs2.output, { | ||
'message': 'Publisher and all members deleted.', | ||
'publisherId': 'other.com', | ||
'members-count': 1, | ||
}); | ||
final p2 = await publisherBackend.getPublisher('other.com'); | ||
expect(p2, isNull); | ||
}); | ||
|
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