Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-nullable isModerated flags #7558

Merged
merged 1 commit into from
Mar 14, 2024
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
4 changes: 2 additions & 2 deletions app/lib/account/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class User extends db.ExpandoModel<String> {

/// `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()
Expand All @@ -69,7 +69,7 @@ class User extends db.ExpandoModel<String> {
isModerated = false;
}

late final isVisible = !isBlocked && !(isModerated ?? false);
late final isVisible = !isBlocked && !isModerated;
late final isNotVisible = !isVisible;
}

Expand Down
8 changes: 4 additions & 4 deletions app/lib/package/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Package extends db.ExpandoModel<String> {

/// `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()
Expand Down Expand Up @@ -202,13 +202,13 @@ class Package extends db.ExpandoModel<String> {

// 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 &&
Expand Down Expand Up @@ -599,7 +599,7 @@ class PackageVersion extends db.ExpandoModel<String> {

/// `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()
Expand Down
2 changes: 1 addition & 1 deletion app/lib/publisher/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Publisher extends db.ExpandoModel<String> {

/// `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()
Expand Down
9 changes: 3 additions & 6 deletions app/lib/shared/integrity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -911,16 +911,13 @@ class _PublisherAttributes {
Stream<String> _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.';
}
}
3 changes: 1 addition & 2 deletions app/lib/tool/maintenance/update_public_bucket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Future<PublicBucketUpdateStat> 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);
Expand Down
Loading