Skip to content
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: 1 addition & 1 deletion app/lib/admin/actions/moderate_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ can't be updated, administrators must not be able to update publisher options.
'publisherId must be given',
);

final publisher = await publisherBackend.getPublisher(publisherId!);
final publisher = await publisherBackend.lookupPublisher(publisherId!);
InvalidInputException.check(
publisher != null, 'Unable to locate publisher.');

Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/moderate_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The active web sessions of the user will be expired.
final publishers =
await publisherBackend.listPublishersForUser(user.userId);
for (final e in publishers.publishers!) {
final p = await publisherBackend.getPublisher(e.publisherId);
final p = await publisherBackend.lookupPublisher(e.publisherId);
if (p == null) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/publisher_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Loads and displays the publisher information.
'`publisher` must be given',
);

final p = await publisherBackend.getPublisher(publisherId!);
final p = await publisherBackend.lookupPublisher(publisherId!);
if (p == null) {
throw NotFoundException.resource(publisherId);
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/publisher_members_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Get information about a publisher and list all its members.
final publisherId = options['publisher'] ??
(throw InvalidInputException('Missing --publisher argument.'));

final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.lookupPublisher(publisherId);
if (publisher == null) {
throw NotFoundException.resource(publisherId);
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/tools/package_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Future<String> executeSetPackagePublisher(List<String> args) async {
}

final package = (await packageBackend.lookupPackage(packageName))!;
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.lookupPublisher(publisherId);
if (publisher == null) {
return 'No such publisher.';
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/frontend/handlers/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Future<AccountPublisherOptions> accountPublisherOptionsHandler(
shelf.Request request, String publisherId) async {
checkPublisherIdParam(publisherId);
final user = await requireAuthenticatedWebUser();
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.getListedPublisher(publisherId);
if (publisher == null) {
throw NotFoundException.resource('publisher "$publisherId"');
}
Expand Down
6 changes: 3 additions & 3 deletions app/lib/frontend/handlers/publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Future<shelf.Response> publisherPackagesPageHandler(
}
}

final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.lookupPublisher(publisherId);
if (publisher == null) {
// We may introduce search for publishers (e.g. somebody just mistyped a
// domain name), but now we just have a formatted error page.
Expand Down Expand Up @@ -146,7 +146,7 @@ Future<shelf.Response> publisherPackagesPageHandler(
/// Handles requests for `GET /publishers/<publisherId>/admin`.
Future<shelf.Response> publisherAdminPageHandler(
shelf.Request request, String publisherId) async {
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.getListedPublisher(publisherId);
if (publisher == null) {
// We may introduce search for publishers (e.g. somebody just mistyped a
// domain name), but now we just have a formatted error page.
Expand Down Expand Up @@ -174,7 +174,7 @@ Future<shelf.Response> publisherAdminPageHandler(
/// Handles requests for `GET /publishers/<publisherId>/activity-log`.
Future<shelf.Response> publisherActivityLogPageHandler(
shelf.Request request, String publisherId) async {
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.getListedPublisher(publisherId);
if (publisher == null) {
// We may introduce search for publishers (e.g. somebody just mistyped a
// domain name), but now we just have a formatted error page.
Expand Down
4 changes: 2 additions & 2 deletions app/lib/frontend/handlers/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Future<void> verifyModerationSubjectExists(ModerationSubject? subject) async {

final publisherId = subject?.publisherId;
if (publisherId != null) {
final p = await publisherBackend.getPublisher(publisherId);
final p = await publisherBackend.lookupPublisher(publisherId);
if (p == null) {
throw NotFoundException('Publisher "$publisherId" does not exist.');
}
Expand Down Expand Up @@ -223,7 +223,7 @@ Future<Message> processReportPageHandler(
final pkg = await packageBackend.lookupPackage(subject.package!);
isSubjectOwner = await packageBackend.isPackageAdmin(pkg!, user.userId);
} else if (subject.isPublisher) {
final p = await publisherBackend.getPublisher(subject.publisherId!);
final p = await publisherBackend.lookupPublisher(subject.publisherId!);
isSubjectOwner = await publisherBackend.isMemberAdmin(p!, user.userId);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class PackageBackend {
return p.containsUploader(userId);
} else {
final publisherId = p.publisherId!;
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.getListedPublisher(publisherId);
if (publisher == null) {
return false;
}
Expand Down
32 changes: 17 additions & 15 deletions app/lib/publisher/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ class PublisherBackend {
return visible!;
}

/// Loads a publisher. Returns `null` if it does not exists, or is blocked (not visible).
Future<Publisher?> getPublisher(String publisherId) async {
/// Loads a [Publisher] entity or `null` if there is no such entity.
Future<Publisher?> lookupPublisher(String publisherId) async {
checkPublisherIdParam(publisherId);
final pKey = _db.emptyKey.append(Publisher, id: publisherId);
final p = await _db.lookupOrNull<Publisher>(pKey);
if (p != null && p.isBlocked) {
return null;
}
return p;
return await _db.lookupOrNull<Publisher>(pKey);
}

/// Loads a [Publisher] entity or `null` if there is no such entity,
/// or if the entity is not listed / visible.
Future<Publisher?> getListedPublisher(String publisherId) async {
final p = await lookupPublisher(publisherId);
return p == null || p.isUnlisted ? null : p;
}

/// List publishers (in no specific order, it will be listed by their
Expand Down Expand Up @@ -114,7 +117,7 @@ class PublisherBackend {
publishers.sort((a, b) => a.publisherId.compareTo(b.publisherId));
return PublisherPage(
publishers: publishers
.where((p) => !p.isBlocked)
.where((p) => p.isVisible)
.map((p) => PublisherSummary(
publisherId: p.publisherId,
created: p.created!,
Expand All @@ -134,7 +137,6 @@ class PublisherBackend {

/// Whether the User [userId] has admin permissions on the publisher.
Future<bool> isMemberAdmin(Publisher publisher, String? userId) async {
if (publisher.isBlocked) return false;
if (publisher.isModerated) return false;
if (userId == null) return false;
final member = await getPublisherMember(publisher, userId);
Expand Down Expand Up @@ -250,7 +252,7 @@ class PublisherBackend {
/// Gets the publisher data
Future<api.PublisherInfo> getPublisherInfo(String publisherId) async {
checkPublisherIdParam(publisherId);
final p = await getPublisher(publisherId);
final p = await getListedPublisher(publisherId);
if (p == null) {
throw NotFoundException('Publisher $publisherId does not exists.');
}
Expand Down Expand Up @@ -598,13 +600,13 @@ Future<Publisher> requirePublisherAdmin(
String? publisherId, String userId) async {
ArgumentError.checkNotNull(userId, 'userId');
ArgumentError.checkNotNull(publisherId, 'publisherId');
final p = await publisherBackend.getPublisher(publisherId!);
if (p == null) {
throw NotFoundException('Publisher $publisherId does not exists.');
}
if (p.isModerated) {
final p = await publisherBackend.lookupPublisher(publisherId!);
if (p != null && p.isModerated) {
throw ModeratedException.publisher(publisherId);
}
if (p == null || p.isUnlisted) {
throw NotFoundException('Publisher $publisherId does not exists.');
}

final member = await publisherBackend._db
.lookupOrNull<PublisherMember>(p.key.append(PublisherMember, id: userId));
Expand Down
3 changes: 1 addition & 2 deletions app/lib/publisher/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Publisher extends db.ExpandoModel<String> {
description = '';
websiteUrl = defaultPublisherWebsite(publisherId);
isAbandoned = false;
isBlocked = false;
isModerated = false;
}

Expand All @@ -100,7 +99,7 @@ class Publisher extends db.ExpandoModel<String> {
bool get hasContactEmail => contactEmail != null && contactEmail!.isNotEmpty;

/// Whether we should not list the publisher page in sitemap or promote it in search engines.
bool get isUnlisted => isBlocked || isAbandoned || isModerated;
bool get isUnlisted => isAbandoned || isModerated;
bool get isVisible => !isUnlisted;

void updateIsModerated({required bool isModerated}) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/integrity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class IntegrityChecker {
publisherAttributes.increaseMemberCount(pm.publisherId);
if (!publisherAttributes.publisherIds.contains(pm.publisherId)) {
// double check actual status to prevent misreports on cache race conditions
final p = await publisherBackend.getPublisher(pm.publisherId);
final p = await publisherBackend.lookupPublisher(pm.publisherId);
if (p == null) {
yield 'PublisherMember "${pm.userId}" references a non-existing `publisherId`: "${pm.publisherId}".';
}
Expand Down
18 changes: 0 additions & 18 deletions app/lib/tool/backfill/backfill_new_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:pub_dev/account/models.dart';
import 'package:pub_dev/package/models.dart';
import 'package:pub_dev/publisher/models.dart';
import 'package:pub_dev/shared/datastore.dart';

final _logger = Logger('backfill_new_fields');
Expand All @@ -26,23 +25,6 @@ Future<void> backfillNewFields() async {
@visibleForTesting
Future<void> migrateIsBlocked() async {
_logger.info('Migrating isBlocked...');
final publisherQuery = dbService.query<Publisher>()
..filter('isBlocked =', true);
await for (final entity in publisherQuery.run()) {
await withRetryTransaction(dbService, (tx) async {
final publisher = await tx.lookupValue<Publisher>(entity.key);
// sanity check
if (!publisher.isBlocked) {
return;
}
publisher
..isModerated = true
..moderatedAt = publisher.moderatedAt ?? clock.now()
..isBlocked = false;
tx.insert(publisher);
});
}

final userQuery = dbService.query<User>()..filter('isBlocked =', true);
await for (final entity in userQuery.run()) {
await withRetryTransaction(dbService, (tx) async {
Expand Down
2 changes: 1 addition & 1 deletion app/test/account/consent_backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Future<void> _expireConsent(String? consentId) async {
Future<void> _removeAdminRole(String publisherId, String email) async {
await withFakeAuthRequestContext(email, () async {
final agent = await requireAuthenticatedWebUser();
final publisher = await publisherBackend.getPublisher(publisherId);
final publisher = await publisherBackend.lookupPublisher(publisherId);
final member =
await publisherBackend.getPublisherMember(publisher!, agent.userId);
member!.role = 'non-admin';
Expand Down
3 changes: 2 additions & 1 deletion app/test/admin/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ void main() {
expect(oxygen.uploaders, []);
expect(oxygen.isDiscontinued, true);

final publisher = await publisherBackend.getPublisher('example.com');
final publisher =
await publisherBackend.lookupPublisher('example.com');
expect(publisher!.contactEmail, isNull);
expect(publisher.isAbandoned, isTrue);

Expand Down
4 changes: 2 additions & 2 deletions app/test/admin/api_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void main() {

group('create and delete publisher', () {
testWithProfile('publisher has packages', fn: () async {
final p1 = await publisherBackend.getPublisher('example.com');
final p1 = await publisherBackend.lookupPublisher('example.com');
expect(p1, isNotNull);

await expectLater(
Expand All @@ -161,7 +161,7 @@ void main() {
},
)));

final p2 = await publisherBackend.getPublisher('example.com');
final p2 = await publisherBackend.lookupPublisher('example.com');
expect(p2, isNotNull);
});
});
Expand Down
6 changes: 3 additions & 3 deletions app/test/admin/moderate_publisher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void main() {
'before': {'isModerated': false, 'moderatedAt': null},
'after': {'isModerated': true, 'moderatedAt': isNotEmpty},
});
final p2 = await publisherBackend.getPublisher('example.com');
final p2 = await publisherBackend.lookupPublisher('example.com');
expect(p2!.isModerated, isTrue);

final r3 =
Expand All @@ -78,7 +78,7 @@ void main() {
'before': {'isModerated': true, 'moderatedAt': isNotEmpty},
'after': {'isModerated': false, 'moderatedAt': isNull},
});
final p3 = await publisherBackend.getPublisher('example.com');
final p3 = await publisherBackend.lookupPublisher('example.com');
expect(p3!.isModerated, isFalse);
});

Expand Down Expand Up @@ -214,7 +214,7 @@ void main() {
await adminBackend.deleteModeratedSubjects(before: clock.now().toUtc());

// no publisher or member
expect(await publisherBackend.getPublisher('example.com'), isNull);
expect(await publisherBackend.lookupPublisher('example.com'), isNull);
expect(
await publisherBackend.listPublisherMembers('example.com'),
isEmpty,
Expand Down
2 changes: 1 addition & 1 deletion app/test/admin/moderate_user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void main() {
expect(pkg.isDiscontinued, true);

// publisher has no members
final publisher = await publisherBackend.getPublisher('example.com');
final publisher = await publisherBackend.lookupPublisher('example.com');
expect(publisher!.isAbandoned, true);
final members =
await publisherBackend.listPublisherMembers('example.com');
Expand Down
6 changes: 3 additions & 3 deletions app/test/admin/publisher_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {
'creating, listing members and deleting publisher with no packages',
fn: () async {
final client = createPubApiClient(authToken: siteAdminToken);
final p0 = await publisherBackend.getPublisher('other.com');
final p0 = await publisherBackend.lookupPublisher('other.com');
expect(p0, isNull);
final rs1 = await client.adminInvokeAction(
'publisher-create',
Expand Down Expand Up @@ -65,7 +65,7 @@ void main() {
{'email': 'user@pub.dev', 'role': 'admin', 'userId': isA<String>()}
]
});
final p1 = await publisherBackend.getPublisher('other.com');
final p1 = await publisherBackend.lookupPublisher('other.com');
expect(p1, isNotNull);
final rs2 = await client.adminInvokeAction('publisher-delete',
AdminInvokeActionArguments(arguments: {'publisher': 'other.com'}));
Expand All @@ -74,7 +74,7 @@ void main() {
'publisherId': 'other.com',
'members-count': 1,
});
final p2 = await publisherBackend.getPublisher('other.com');
final p2 = await publisherBackend.lookupPublisher('other.com');
expect(p2, isNull);
});

Expand Down
4 changes: 2 additions & 2 deletions app/test/frontend/handlers/publisher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void main() {
);
});

testWithProfile('publisher is blocked', fn: () async {
testWithProfile('publisher is moderated', fn: () async {
final p = await dbService.lookupValue<Publisher>(
dbService.emptyKey.append(Publisher, id: 'example.com'));
p.isBlocked = true;
p.updateIsModerated(isModerated: true);
await dbService.commit(inserts: [p]);
await expectHtmlResponse(
await issueGet('/publishers/example.com/packages'),
Expand Down
12 changes: 8 additions & 4 deletions app/test/frontend/templates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ void main() {
processJobsWithFakeRunners: true,
fn: () async {
final searchForm = SearchForm();
final publisher = (await publisherBackend.getPublisher('example.com'))!;
final publisher =
(await publisherBackend.lookupPublisher('example.com'))!;
final neon = (await scoreCardBackend.getPackageView('neon'))!;
final titanium =
(await scoreCardBackend.getPackageView('flutter_titanium'))!;
Expand Down Expand Up @@ -577,7 +578,8 @@ void main() {
processJobsWithFakeRunners: true,
fn: () async {
final searchForm = SearchForm();
final publisher = (await publisherBackend.getPublisher('example.com'))!;
final publisher =
(await publisherBackend.lookupPublisher('example.com'))!;
final neon = (await scoreCardBackend.getPackageView('neon'))!;
final titanium =
(await scoreCardBackend.getPackageView('flutter_titanium'))!;
Expand Down Expand Up @@ -609,7 +611,8 @@ void main() {
'publisher admin page',
processJobsWithFakeRunners: true,
fn: () async {
final publisher = (await publisherBackend.getPublisher('example.com'))!;
final publisher =
(await publisherBackend.lookupPublisher('example.com'))!;
final members =
await publisherBackend.listPublisherMembers('example.com');
final html = renderPublisherAdminPage(
Expand All @@ -635,7 +638,8 @@ void main() {
'publisher activity log page',
processJobsWithFakeRunners: true,
fn: () async {
final publisher = (await publisherBackend.getPublisher('example.com'))!;
final publisher =
(await publisherBackend.lookupPublisher('example.com'))!;
final activities =
await auditBackend.listRecordsForPublisher('example.com');
expect(activities.records, isNotEmpty);
Expand Down
Loading
Loading