From 2999ddeb130206b20c7c7e237f8dc249b25be69e Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Thu, 14 Mar 2024 15:14:56 +0100 Subject: [PATCH] non-nullable isModerated flags --- app/lib/account/models.dart | 4 ++-- app/lib/package/models.dart | 8 ++++---- app/lib/publisher/models.dart | 2 +- app/lib/shared/integrity.dart | 9 +++------ app/lib/tool/maintenance/update_public_bucket.dart | 3 +-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/lib/account/models.dart b/app/lib/account/models.dart index 5405c63762..fba559e886 100644 --- a/app/lib/account/models.dart +++ b/app/lib/account/models.dart @@ -56,7 +56,7 @@ class User extends db.ExpandoModel { /// `true` if user was moderated (pending moderation or deletion). @db.BoolProperty(required: true) - bool? isModerated; + bool isModerated = false; /// The timestamp when the user was moderated. @db.DateTimeProperty() @@ -69,7 +69,7 @@ class User extends db.ExpandoModel { isModerated = false; } - late final isVisible = !isBlocked && !(isModerated ?? false); + late final isVisible = !isBlocked && !isModerated; late final isNotVisible = !isVisible; } diff --git a/app/lib/package/models.dart b/app/lib/package/models.dart index e4ef78da5d..27f148d1e6 100644 --- a/app/lib/package/models.dart +++ b/app/lib/package/models.dart @@ -139,7 +139,7 @@ class Package extends db.ExpandoModel { /// `true` if package was moderated (pending moderation or deletion). @db.BoolProperty(required: true) - bool? isModerated; + bool isModerated = false; /// The timestamp when the package was moderated. @db.DateTimeProperty() @@ -202,13 +202,13 @@ class Package extends db.ExpandoModel { // Convenience Fields: - bool get isVisible => !isBlocked && !(isModerated ?? false); + bool get isVisible => !isBlocked && !isModerated; bool get isNotVisible => !isVisible; bool get isIncludedInRobots { final now = clock.now(); return isVisible && - !(isModerated ?? false) && + !isModerated && !isDiscontinued && !isUnlisted && now.difference(created!) > robotsVisibilityMinAge && @@ -599,7 +599,7 @@ class PackageVersion extends db.ExpandoModel { /// `true` if package version was moderated (pending moderation or deletion). @db.BoolProperty(required: true) - bool? isModerated; + bool isModerated = false; /// The timestamp when the package version was moderated. @db.DateTimeProperty() diff --git a/app/lib/publisher/models.dart b/app/lib/publisher/models.dart index e16fb1923c..0c5173411e 100644 --- a/app/lib/publisher/models.dart +++ b/app/lib/publisher/models.dart @@ -66,7 +66,7 @@ class Publisher extends db.ExpandoModel { /// `true` if publisher was moderated (pending moderation or deletion). @db.BoolProperty(required: true) - bool? isModerated; + bool isModerated = false; /// The timestamp when the publisher was moderated. @db.DateTimeProperty() diff --git a/app/lib/shared/integrity.dart b/app/lib/shared/integrity.dart index 0b5f3e1b52..49e6cf903c 100644 --- a/app/lib/shared/integrity.dart +++ b/app/lib/shared/integrity.dart @@ -911,16 +911,13 @@ class _PublisherAttributes { Stream _checkModeratedFlags({ required String kind, required String id, - required bool? isModerated, + required bool isModerated, required DateTime? moderatedAt, }) async* { - if (isModerated == null) { - yield '$kind "$id" has an `isModerated` property which is null.'; - } - if ((isModerated ?? false) && moderatedAt == null) { + if (isModerated && moderatedAt == null) { yield '$kind "$id" has `isModerated = true` but `moderatedAt` is null.'; } - if (!(isModerated ?? false) && moderatedAt != null) { + if (!isModerated && moderatedAt != null) { yield '$kind "$id" has `isModerated = false` but `moderatedAt` is not null.'; } } diff --git a/app/lib/tool/maintenance/update_public_bucket.dart b/app/lib/tool/maintenance/update_public_bucket.dart index 7ee2810f3d..51232d89ee 100644 --- a/app/lib/tool/maintenance/update_public_bucket.dart +++ b/app/lib/tool/maintenance/update_public_bucket.dart @@ -57,8 +57,7 @@ Future updatePublicArchiveBucket({ if (lastPackage?.name != pv.package) { lastPackage = await packageBackend.lookupPackage(pv.package); } - final isModerated = - (lastPackage!.isModerated ?? false) || (pv.isModerated ?? false); + final isModerated = lastPackage!.isModerated || pv.isModerated; final objectName = tarballObjectName(pv.package, pv.version!); final publicInfo = await publicBucket.tryInfo(objectName);