<commit_before>/* Adding (and later removing) collaborators to/from projects. */

import { PostgreSQL } from "./types";

import { callback2 } from "../smc-util/async-utils";

export async function project_has_network_access(
  db: PostgreSQL,
  project_id: string
): Promise<boolean> {
  let x;
  try {
    x = await callback2(db.get_project, {
      project_id,
      columns: ["users", "settings"]
    });
  } catch (err) {
    // error probably means there is no such project or project_id is badly formatted.
    return false;
  }
  if (x.settings != null && x.settings.network) {
    return true;
  }
  if (x.users != null) {
    for (let account_id in x.users) {
      if (x.users[account_id] != null && x.users[account_id].network) {
        return true;
      }
    }
  }
  return false;
}<commit_msg>fix code to detect whether project has internet access<commit_after>/* Adding (and later removing) collaborators to/from projects. */

import { PostgreSQL } from "./types";

import { callback2 } from "../smc-util/async-utils";

export async function project_has_network_access(
  db: PostgreSQL,
  project_id: string
): Promise<boolean> {
  let x;
  try {
    x = await callback2(db.get_project, {
      project_id,
      columns: ["users", "settings"]
    });
  } catch (err) {
    // error probably means there is no such project or project_id is badly formatted.
    return false;
  }
  if (x.settings != null && x.settings.network) {
    return true;
  }
  if (x.users != null) {
    for (let account_id in x.users) {
      if (
        x.users[account_id] != null &&
        x.users[account_id].upgrades != null &&
        x.users[account_id].upgrades.network
      ) {
        return true;
      }
    }
  }
  return false;
}
{'fraction_non_alphanumeric': 0.12931034482758622, 'fraction_numerical': 0.0022988505747126436, 'mean_word_length': 2.704255319148936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2220220', 'n_tokens_mistral': 563, 'n_tokens_neox': 555, 'n_words': 158}