Fix up network editing

This commit is contained in:
Pavel Djundik 2019-11-02 20:45:00 +02:00
parent 8fa42c5c48
commit c8b22b2df3
8 changed files with 64 additions and 49 deletions

View file

@ -12,9 +12,7 @@
Edit {{ defaults.name }}
</template>
<template v-else>
<template v-if="config.public"
>The Lounge -
</template>
<template v-if="config.public">The Lounge - </template>
Connect
<template v-if="!config.displayNetwork">
<template v-if="config.lockNetwork">

View file

@ -34,6 +34,7 @@ export default {
},
methods: {
setNetworkData() {
socket.emit("network:get", this.$route.params.uuid);
this.networkData = this.$root.findNetwork(this.$route.params.uuid);
},
handleSubmit(data) {

View file

@ -1,8 +1,7 @@
"use strict";
const $ = require("jquery");
const socket = require("../socket");
const {vueApp, initChannel, findChannel} = require("../vue");
const {vueApp, initChannel, findChannel, findNetwork} = require("../vue");
socket.on("network", function(data) {
const network = data.networks[0];
@ -13,10 +12,6 @@ socket.on("network", function(data) {
vueApp.networks.push(network);
vueApp.switchToChannel(network.channels[0]);
$("#connect")
.find(".btn")
.prop("disabled", false);
});
socket.on("network:options", function(data) {
@ -50,7 +45,13 @@ socket.on("channel:state", function(data) {
});
socket.on("network:info", function(data) {
vueApp.$store.commit("currentNetworkConfig", data.defaults);
vueApp.$store.commit("activeWindow", "NetworkEdit");
vueApp.activeChannel = null;
const network = findNetwork(data.uuid);
if (!network) {
return;
}
for (const key in data) {
vueApp.$set(network, key, data[key]);
}
});

View file

@ -198,6 +198,10 @@ function findChannel(id) {
return vueApp.findChannel(id);
}
function findNetwork(uuid) {
return vueApp.findNetwork(uuid);
}
function initChannel(channel) {
channel.pendingMessage = "";
channel.inputHistoryPosition = 0;
@ -221,6 +225,7 @@ function getActiveWindowComponent() {
module.exports = {
vueApp,
findChannel,
findNetwork,
initChannel,
getActiveWindowComponent,
};

View file

@ -10,21 +10,19 @@ const Helper = require("../helper");
module.exports = Network;
/**
* @type {Object} List of keys which should not be sent to the client.
* @type {Object} List of keys which should be sent to the client by default.
*/
const filteredFromClient = {
awayMessage: true,
chanCache: true,
highlightRegex: true,
irc: true,
password: true,
ignoreList: true,
keepNick: true,
const fieldsForClient = {
uuid: true,
name: true,
nick: true,
serverOptions: true,
};
function Network(attr) {
_.defaults(this, attr, {
name: "",
nick: "",
host: "",
port: 6667,
tls: false,
@ -294,7 +292,7 @@ Network.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) {
newNetwork[prop] = this[prop].map((channel) =>
channel.getFilteredClone(lastActiveChannel, lastMessage)
);
} else if (!filteredFromClient[prop]) {
} else if (fieldsForClient[prop]) {
// Some properties that are not useful for the client are skipped
newNetwork[prop] = this[prop];
}
@ -352,6 +350,32 @@ Network.prototype.addChannel = function(newChan) {
return index;
};
Network.prototype.exportForEdit = function() {
let fieldsToReturn;
if (Helper.config.displayNetwork) {
// Return fields required to edit a network
fieldsToReturn = [
"uuid",
"nick",
"name",
"host",
"port",
"tls",
"rejectUnauthorized",
"password",
"username",
"realname",
"commands",
];
} else {
// Same fields as in getClientConfiguration when network is hidden
fieldsToReturn = ["name", "nick", "username", "password", "realname"];
}
return _.pick(this, fieldsToReturn);
};
Network.prototype.export = function() {
const network = _.pick(this, [
"uuid",

View file

@ -399,7 +399,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
return;
}
socket.emit("network:info", getClientConfiguration(network.export()));
socket.emit("network:info", network.exportForEdit());
});
socket.on("network:edit", (data) => {
@ -657,7 +657,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
}
}
function getClientConfiguration(network) {
function getClientConfiguration() {
const config = _.pick(Helper.config, [
"public",
"lockNetwork",
@ -670,10 +670,10 @@ function getClientConfiguration(network) {
config.ldapEnabled = Helper.config.ldap.enable;
if (config.displayNetwork) {
config.defaults = _.clone(network || Helper.config.defaults);
config.defaults = _.clone(Helper.config.defaults);
} else {
// Only send defaults that are visible on the client
config.defaults = _.pick(network || Helper.config.defaults, [
config.defaults = _.pick(Helper.config.defaults, [
"name",
"nick",
"username",
@ -683,13 +683,11 @@ function getClientConfiguration(network) {
]);
}
if (!network) {
config.version = pkg.version;
config.gitCommit = Helper.getGitCommit();
config.themes = themes.getAll();
config.defaultTheme = Helper.config.theme;
config.defaults.nick = Helper.getDefaultNick();
}
if (Uploader) {
config.fileUploadMaxFileSize = Uploader.getMaxFileSize();

View file

@ -227,21 +227,7 @@ describe("Network", function() {
expect(clone)
.to.be.an("object")
.that.has.all.keys(
"channels",
"commands",
"host",
"name",
"port",
"realname",
"serverOptions",
"status",
"tls",
"userDisconnected",
"rejectUnauthorized",
"uuid",
"username"
);
.that.has.all.keys("channels", "status", "nick", "name", "serverOptions", "uuid");
expect(clone.status)
.to.be.an("object")

View file

@ -91,10 +91,12 @@ describe("Server", function() {
client.on("network", (data) => {
expect(data.networks).to.be.an("array");
expect(data.networks).to.have.lengthOf(1);
expect(data.networks[0].realname).to.equal("The Lounge Test");
expect(data.networks[0].nick).to.equal("test-user");
expect(data.networks[0].name).to.equal("Test Network");
expect(data.networks[0].channels).to.have.lengthOf(3);
expect(data.networks[0].channels[0].name).to.equal("Test Network");
expect(data.networks[0].channels[1].name).to.equal("#thelounge");
expect(data.networks[0].channels[2].name).to.equal("#spam");
done();
});
});