displayConditionOk static method

bool displayConditionOk(
  1. Map<String, bool> packagesConditions,
  2. DisplayConditionsModel conditions,
  3. PrivilegeLevel privilegedLevel,
  4. bool isOwner,
  5. bool? isBlocked,
  6. bool isLoggedIn,
)

Implementation

static bool displayConditionOk(
    Map<String, bool> packagesConditions,
    DisplayConditionsModel conditions,
    PrivilegeLevel privilegedLevel,
    bool isOwner,
    bool? isBlocked,
    bool isLoggedIn) {
  var privilegeLevelRequiredIndex = conditions.privilegeLevelRequired ==
              null ||
          conditions.privilegeLevelRequired == PrivilegeLevelRequired.unknown
      ? PrivilegeLevelRequired.noPrivilegeRequired.index
      : conditions.privilegeLevelRequired!.index;

  if (privilegedLevel.index < privilegeLevelRequiredIndex) {
    return false;
  }

//    if (conditions == null) return true;

  var packageCondition = conditions.packageCondition;
  if (packageCondition != null) {
    var packageConditionValue = packagesConditions[packageCondition];
    if ((packageConditionValue != null) && (!packageConditionValue)) {
      return false;
    }
  }

  if (conditions.conditionOverride != null) {
    switch (conditions.conditionOverride) {
      case ConditionOverride.exactPrivilege:
        if (privilegedLevel.index != privilegeLevelRequiredIndex) {
          return false;
        }
        break;
      case ConditionOverride.inclusiveForBlockedMembers:
        if ((isBlocked != null) && (isBlocked)) return true;
        break;
      case ConditionOverride.exclusiveForBlockedMember:
        if ((isBlocked != null) && (isBlocked)) return true;
        break;
      case ConditionOverride.unknown:
        break;
      case null:
        break;
    }
  }

  if ((isBlocked != null) && (isBlocked)) return false;

  return true;
}