Combine displayNetwork into lockNetwork

This commit is contained in:
Pavel Djundik 2020-03-31 20:03:40 +03:00
parent 8a281bacd8
commit 6ee71779d1
8 changed files with 11 additions and 53 deletions

View File

@ -11,12 +11,10 @@
</template> </template>
<template v-else> <template v-else>
Connect Connect
<template v-if="!config.displayNetwork && config.lockNetwork"> <template v-if="config.lockNetwork">to {{ defaults.name }}</template>
to {{ defaults.name }}
</template>
</template> </template>
</h1> </h1>
<template v-if="config.displayNetwork"> <template v-if="!config.lockNetwork">
<h2>Network settings</h2> <h2>Network settings</h2>
<div class="connect-row"> <div class="connect-row">
<label for="connect:name">Name</label> <label for="connect:name">Name</label>
@ -39,7 +37,6 @@
aria-label="Server address" aria-label="Server address"
maxlength="255" maxlength="255"
required required
:disabled="config.lockNetwork ? true : false"
/> />
<span id="connect:portseparator">:</span> <span id="connect:portseparator">:</span>
<input <input
@ -52,7 +49,6 @@
name="port" name="port"
:value="defaults.port" :value="defaults.port"
aria-label="Server port" aria-label="Server port"
:disabled="config.lockNetwork ? true : false"
/> />
</div> </div>
</div> </div>
@ -81,9 +77,7 @@
type="checkbox" type="checkbox"
name="tls" name="tls"
:checked="defaults.tls ? true : false" :checked="defaults.tls ? true : false"
:disabled=" :disabled="defaults.hasSTSPolicy ? true : false"
config.lockNetwork || defaults.hasSTSPolicy ? true : false
"
@change="onSecureChanged" @change="onSecureChanged"
/> />
Use secure connection (TLS) Use secure connection (TLS)
@ -99,7 +93,6 @@
type="checkbox" type="checkbox"
name="rejectUnauthorized" name="rejectUnauthorized"
:checked="defaults.rejectUnauthorized ? true : false" :checked="defaults.rejectUnauthorized ? true : false"
:disabled="config.lockNetwork ? true : false"
/> />
Only allow trusted certificates Only allow trusted certificates
</label> </label>
@ -164,7 +157,7 @@
</template> </template>
<template v-if="$store.state.serverConfiguration.public"> <template v-if="$store.state.serverConfiguration.public">
<template v-if="!config.displayNetwork"> <template v-if="config.lockNetwork">
<div class="connect-row"> <div class="connect-row">
<label></label> <label></label>
<div class="input-wrap"> <div class="input-wrap">

View File

@ -59,16 +59,11 @@ export default {
// When the network is locked, URL overrides should not affect disabled fields // When the network is locked, URL overrides should not affect disabled fields
if ( if (
this.$store.state.serverConfiguration.lockNetwork && this.$store.state.serverConfiguration.lockNetwork &&
["host", "port", "tls", "rejectUnauthorized"].includes(key) ["name", "host", "port", "tls", "rejectUnauthorized"].includes(key)
) { ) {
continue; continue;
} }
// When the network is not displayed, its name in the UI is not customizable
if (!this.$store.state.serverConfiguration.displayNetwork && key === "name") {
continue;
}
if (key === "join") { if (key === "join") {
value = value value = value
.split(",") .split(",")

View File

@ -238,25 +238,11 @@ module.exports = {
join: "#thelounge", join: "#thelounge",
}, },
// ### `displayNetwork`
//
// When set to `false`, network fields will not be shown in the "Connect"
// window.
//
// Note that even though users cannot access and set these fields, they can
// still connect to other networks using the `/connect` command. See the
// `lockNetwork` setting to restrict users from connecting to other networks.
//
// This value is set to `true` by default.
displayNetwork: true,
// ### `lockNetwork` // ### `lockNetwork`
// //
// When set to `true`, users will not be able to modify host, port and TLS // When set to `true`, users will not be able to modify host, port and TLS
// settings and will be limited to the configured network. // settings and will be limited to the configured network.
// // These fields will also be hidden from the UI.
// It is often useful to use it with `displayNetwork` when setting The
// Lounge as a public web client for a specific IRC network.
// //
// This value is set to `false` by default. // This value is set to `false` by default.
lockNetwork: false, lockNetwork: false,

View File

@ -227,7 +227,7 @@ Client.prototype.connect = function (args, isStartup = false) {
const network = new Network({ const network = new Network({
uuid: args.uuid, uuid: args.uuid,
name: String( name: String(
args.name || (Helper.config.displayNetwork ? "" : Helper.config.defaults.name) || "" args.name || (Helper.config.lockNetwork ? Helper.config.defaults.name : "") || ""
), ),
host: String(args.host || ""), host: String(args.host || ""),
port: parseInt(args.port, 10), port: parseInt(args.port, 10),

View File

@ -125,16 +125,6 @@ function setHome(newPath) {
mergeConfig(this.config, userConfig); mergeConfig(this.config, userConfig);
} }
if (!this.config.displayNetwork && !this.config.lockNetwork) {
this.config.lockNetwork = true;
log.warn(
`${colors.bold("displayNetwork")} and ${colors.bold(
"lockNetwork"
)} are false, setting ${colors.bold("lockNetwork")} to true.`
);
}
if (this.config.fileUpload.baseUrl) { if (this.config.fileUpload.baseUrl) {
try { try {
new URL("test/file.png", this.config.fileUpload.baseUrl); new URL("test/file.png", this.config.fileUpload.baseUrl);

View File

@ -120,6 +120,7 @@ Network.prototype.validate = function (client) {
return false; return false;
} }
this.name = Helper.config.defaults.name;
this.host = Helper.config.defaults.host; this.host = Helper.config.defaults.host;
this.port = Helper.config.defaults.port; this.port = Helper.config.defaults.port;
this.tls = Helper.config.defaults.tls; this.tls = Helper.config.defaults.tls;
@ -436,7 +437,7 @@ Network.prototype.exportForEdit = function () {
"commands", "commands",
]; ];
if (Helper.config.displayNetwork) { if (!Helper.config.lockNetwork) {
fieldsToReturn.push("host"); fieldsToReturn.push("host");
fieldsToReturn.push("port"); fieldsToReturn.push("port");
fieldsToReturn.push("tls"); fieldsToReturn.push("tls");

View File

@ -706,18 +706,12 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
} }
function getClientConfiguration() { function getClientConfiguration() {
const config = _.pick(Helper.config, [ const config = _.pick(Helper.config, ["public", "lockNetwork", "useHexIp", "prefetch"]);
"public",
"lockNetwork",
"displayNetwork",
"useHexIp",
"prefetch",
]);
config.fileUpload = Helper.config.fileUpload.enable; config.fileUpload = Helper.config.fileUpload.enable;
config.ldapEnabled = Helper.config.ldap.enable; config.ldapEnabled = Helper.config.ldap.enable;
if (config.displayNetwork) { if (!config.lockNetwork) {
config.defaults = _.clone(Helper.config.defaults); config.defaults = _.clone(Helper.config.defaults);
} else { } else {
// Only send defaults that are visible on the client // Only send defaults that are visible on the client

View File

@ -113,7 +113,6 @@ describe("Server", function () {
expect(data.defaultTheme).to.equal("default"); expect(data.defaultTheme).to.equal("default");
expect(data.themes).to.be.an("array"); expect(data.themes).to.be.an("array");
expect(data.lockNetwork).to.equal(false); expect(data.lockNetwork).to.equal(false);
expect(data.displayNetwork).to.equal(true);
expect(data.useHexIp).to.equal(false); expect(data.useHexIp).to.equal(false);
done(); done();