<commit_before>const path = require('path');
const Field = require(path.resolve('electron/easy/field'));
const Form = require(path.resolve('electron/easy/form'));
const Util = require(path.resolve('electron/easy/util'));
const ValidationResult = require(path.resolve('electron/easy/validation_result'));

const Store = require('electron-store');
var db = new Store({name: 'app-settings'});

const requiredSettings = ["Institution Domain"];

module.exports = class AppSetting {
    constructor(name, value) {
        this.id = Util.uuid4();
        this.name = name;
        this.value = value;
    }
    objectType() {
        return 'AppSetting';
    }
    validate() {
        var result = new ValidationResult();
        if (Util.isEmpty(this.id)) {
            result.errors["id"] = "Id cannot be empty";
        }
        if (Util.isEmpty(this.name)) {
            result.errors["name"] = "Name cannot be empty";
        }
        return result
    }
    toForm() {
        var form = new Form('appSettingForm');
        form.fields['id'] = new Field('appSettingId', 'id', 'id', this.id);
        form.fields['name'] = new Field('appSettingName', 'name', 'Name', this.name);
        form.fields['value'] = new Field('appSettingValue', 'value', 'Value', this.value);
        return form
    }
    static fromForm() {
        var name = $('#appSettingName').val().trim();
        var value = $('#appSettingValue').val().trim();
        var setting = new AppSetting(name, value);
        setting.id = $('#appSettingId').val().trim();
        return setting
    }
    isRequired() {
        for (var name of requiredSettings) {
            if (this.name == name) {
                return true;
            }
        }
        return false;
    }
    save() {
        return db.set(this.id, this);
    }
    static findByName(name) {
        for (var key in db.store) {
            var setting = db.store[key];
            if (setting.name == name) {
                return setting;
            }
        }<commit_msg>Restrict editing of required app settings<commit_after>const path = require('path');
const Field = require(path.resolve('electron/easy/field'));
const Form = require(path.resolve('electron/easy/form'));
const Util = require(path.resolve('electron/easy/util'));
const ValidationResult = require(path.resolve('electron/easy/validation_result'));

const Store = require('electron-store');
var db = new Store({name: 'app-settings'});

const requiredSettings = ["Institution Domain"];

module.exports = class AppSetting {
    constructor(name, value) {
        this.id = Util.uuid4();
        this.name = name;
        this.value = value;
    }
    objectType() {
        return 'AppSetting';
    }
    validate() {
        var result = new ValidationResult();
        if (Util.isEmpty(this.id)) {
            result.errors["id"] = "Id cannot be empty";
        }
        if (Util.isEmpty(this.name)) {
            result.errors["name"] = "Name cannot be empty";
        }
        return result
    }
    toForm() {
        var form = new Form('appSettingForm');
        form.fields['id'] = new Field('appSettingId', 'id', 'id', this.id);
        form.fields['name'] = new Field('appSettingName', 'name', 'Name', this.name);
        if (this.isRequired()) {
            form.fields['name'].attrs['disabled'] = true;
            form.fields['name'].help = "Set this to the value of your organization's internet domain. This is a required setting. You cannot delete it. You can only change its value."
        }
        form.fields['value'] = new Field('appSettingValue', 'value', 'Value', this.value);
        return form
    }
    static fromForm() {
        var name = $('#appSettingName').val().trim();
        var value = $('#appSettingValue').val().trim();
        var setting = new AppSetting(name, value);
        setting.id = $('#appSettingId').val().trim();
        return setting
    }
    isRequired() {
        for (var name of requiredSettings) {
            if (this.name == name) {
                return true;
            }
        }
        return false;
    }
    save() {
        return db.set(this.id, this);
    }
    static findByName(name) {
        for (var key in db.store) {
            var setting = db.store[key];
            if (setting.name == name) {
                return setting;
            }
        }
{'fraction_non_alphanumeric': 0.1510692113129455, 'fraction_numerical': 0.0004598758335249483, 'mean_word_length': 2.27313769751693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1049089', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1200, 'n_words': 312}