Skip to content

Commit 25e5c9c

Browse files
authored
Migrate Publisher.isBlocked uses before removing the field. (#8450)
1 parent 51cdca8 commit 25e5c9c

24 files changed

+62
-93
lines changed

app/lib/admin/actions/moderate_publisher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ can't be updated, administrators must not be able to update publisher options.
3636
'publisherId must be given',
3737
);
3838

39-
final publisher = await publisherBackend.getPublisher(publisherId!);
39+
final publisher = await publisherBackend.lookupPublisher(publisherId!);
4040
InvalidInputException.check(
4141
publisher != null, 'Unable to locate publisher.');
4242

app/lib/admin/actions/moderate_user.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The active web sessions of the user will be expired.
105105
final publishers =
106106
await publisherBackend.listPublishersForUser(user.userId);
107107
for (final e in publishers.publishers!) {
108-
final p = await publisherBackend.getPublisher(e.publisherId);
108+
final p = await publisherBackend.lookupPublisher(e.publisherId);
109109
if (p == null) {
110110
continue;
111111
}

app/lib/admin/actions/publisher_info.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Loads and displays the publisher information.
2222
'`publisher` must be given',
2323
);
2424

25-
final p = await publisherBackend.getPublisher(publisherId!);
25+
final p = await publisherBackend.lookupPublisher(publisherId!);
2626
if (p == null) {
2727
throw NotFoundException.resource(publisherId);
2828
}

app/lib/admin/actions/publisher_members_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Get information about a publisher and list all its members.
1818
final publisherId = options['publisher'] ??
1919
(throw InvalidInputException('Missing --publisher argument.'));
2020

21-
final publisher = await publisherBackend.getPublisher(publisherId);
21+
final publisher = await publisherBackend.lookupPublisher(publisherId);
2222
if (publisher == null) {
2323
throw NotFoundException.resource(publisherId);
2424
}

app/lib/admin/tools/package_publisher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Future<String> executeSetPackagePublisher(List<String> args) async {
2727
}
2828

2929
final package = (await packageBackend.lookupPackage(packageName))!;
30-
final publisher = await publisherBackend.getPublisher(publisherId);
30+
final publisher = await publisherBackend.lookupPublisher(publisherId);
3131
if (publisher == null) {
3232
return 'No such publisher.';
3333
}

app/lib/frontend/handlers/account.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Future<AccountPublisherOptions> accountPublisherOptionsHandler(
251251
shelf.Request request, String publisherId) async {
252252
checkPublisherIdParam(publisherId);
253253
final user = await requireAuthenticatedWebUser();
254-
final publisher = await publisherBackend.getPublisher(publisherId);
254+
final publisher = await publisherBackend.getListedPublisher(publisherId);
255255
if (publisher == null) {
256256
throw NotFoundException.resource('publisher "$publisherId"');
257257
}

app/lib/frontend/handlers/publisher.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Future<shelf.Response> publisherPackagesPageHandler(
8282
}
8383
}
8484

85-
final publisher = await publisherBackend.getPublisher(publisherId);
85+
final publisher = await publisherBackend.lookupPublisher(publisherId);
8686
if (publisher == null) {
8787
// We may introduce search for publishers (e.g. somebody just mistyped a
8888
// domain name), but now we just have a formatted error page.
@@ -146,7 +146,7 @@ Future<shelf.Response> publisherPackagesPageHandler(
146146
/// Handles requests for `GET /publishers/<publisherId>/admin`.
147147
Future<shelf.Response> publisherAdminPageHandler(
148148
shelf.Request request, String publisherId) async {
149-
final publisher = await publisherBackend.getPublisher(publisherId);
149+
final publisher = await publisherBackend.getListedPublisher(publisherId);
150150
if (publisher == null) {
151151
// We may introduce search for publishers (e.g. somebody just mistyped a
152152
// domain name), but now we just have a formatted error page.
@@ -174,7 +174,7 @@ Future<shelf.Response> publisherAdminPageHandler(
174174
/// Handles requests for `GET /publishers/<publisherId>/activity-log`.
175175
Future<shelf.Response> publisherActivityLogPageHandler(
176176
shelf.Request request, String publisherId) async {
177-
final publisher = await publisherBackend.getPublisher(publisherId);
177+
final publisher = await publisherBackend.getListedPublisher(publisherId);
178178
if (publisher == null) {
179179
// We may introduce search for publishers (e.g. somebody just mistyped a
180180
// domain name), but now we just have a formatted error page.

app/lib/frontend/handlers/report.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Future<void> verifyModerationSubjectExists(ModerationSubject? subject) async {
105105

106106
final publisherId = subject?.publisherId;
107107
if (publisherId != null) {
108-
final p = await publisherBackend.getPublisher(publisherId);
108+
final p = await publisherBackend.lookupPublisher(publisherId);
109109
if (p == null) {
110110
throw NotFoundException('Publisher "$publisherId" does not exist.');
111111
}
@@ -223,7 +223,7 @@ Future<Message> processReportPageHandler(
223223
final pkg = await packageBackend.lookupPackage(subject.package!);
224224
isSubjectOwner = await packageBackend.isPackageAdmin(pkg!, user.userId);
225225
} else if (subject.isPublisher) {
226-
final p = await publisherBackend.getPublisher(subject.publisherId!);
226+
final p = await publisherBackend.lookupPublisher(subject.publisherId!);
227227
isSubjectOwner = await publisherBackend.isMemberAdmin(p!, user.userId);
228228
}
229229
}

app/lib/package/backend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ class PackageBackend {
675675
return p.containsUploader(userId);
676676
} else {
677677
final publisherId = p.publisherId!;
678-
final publisher = await publisherBackend.getPublisher(publisherId);
678+
final publisher = await publisherBackend.getListedPublisher(publisherId);
679679
if (publisher == null) {
680680
return false;
681681
}

app/lib/publisher/backend.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,18 @@ class PublisherBackend {
5858
return visible!;
5959
}
6060

61-
/// Loads a publisher. Returns `null` if it does not exists, or is blocked (not visible).
62-
Future<Publisher?> getPublisher(String publisherId) async {
61+
/// Loads a [Publisher] entity or `null` if there is no such entity.
62+
Future<Publisher?> lookupPublisher(String publisherId) async {
6363
checkPublisherIdParam(publisherId);
6464
final pKey = _db.emptyKey.append(Publisher, id: publisherId);
65-
final p = await _db.lookupOrNull<Publisher>(pKey);
66-
if (p != null && p.isBlocked) {
67-
return null;
68-
}
69-
return p;
65+
return await _db.lookupOrNull<Publisher>(pKey);
66+
}
67+
68+
/// Loads a [Publisher] entity or `null` if there is no such entity,
69+
/// or if the entity is not listed / visible.
70+
Future<Publisher?> getListedPublisher(String publisherId) async {
71+
final p = await lookupPublisher(publisherId);
72+
return p == null || p.isUnlisted ? null : p;
7073
}
7174

7275
/// List publishers (in no specific order, it will be listed by their
@@ -114,7 +117,7 @@ class PublisherBackend {
114117
publishers.sort((a, b) => a.publisherId.compareTo(b.publisherId));
115118
return PublisherPage(
116119
publishers: publishers
117-
.where((p) => !p.isBlocked)
120+
.where((p) => p.isVisible)
118121
.map((p) => PublisherSummary(
119122
publisherId: p.publisherId,
120123
created: p.created!,
@@ -134,7 +137,6 @@ class PublisherBackend {
134137

135138
/// Whether the User [userId] has admin permissions on the publisher.
136139
Future<bool> isMemberAdmin(Publisher publisher, String? userId) async {
137-
if (publisher.isBlocked) return false;
138140
if (publisher.isModerated) return false;
139141
if (userId == null) return false;
140142
final member = await getPublisherMember(publisher, userId);
@@ -250,7 +252,7 @@ class PublisherBackend {
250252
/// Gets the publisher data
251253
Future<api.PublisherInfo> getPublisherInfo(String publisherId) async {
252254
checkPublisherIdParam(publisherId);
253-
final p = await getPublisher(publisherId);
255+
final p = await getListedPublisher(publisherId);
254256
if (p == null) {
255257
throw NotFoundException('Publisher $publisherId does not exists.');
256258
}
@@ -598,13 +600,13 @@ Future<Publisher> requirePublisherAdmin(
598600
String? publisherId, String userId) async {
599601
ArgumentError.checkNotNull(userId, 'userId');
600602
ArgumentError.checkNotNull(publisherId, 'publisherId');
601-
final p = await publisherBackend.getPublisher(publisherId!);
602-
if (p == null) {
603-
throw NotFoundException('Publisher $publisherId does not exists.');
604-
}
605-
if (p.isModerated) {
603+
final p = await publisherBackend.lookupPublisher(publisherId!);
604+
if (p != null && p.isModerated) {
606605
throw ModeratedException.publisher(publisherId);
607606
}
607+
if (p == null || p.isUnlisted) {
608+
throw NotFoundException('Publisher $publisherId does not exists.');
609+
}
608610

609611
final member = await publisherBackend._db
610612
.lookupOrNull<PublisherMember>(p.key.append(PublisherMember, id: userId));

0 commit comments

Comments
 (0)