Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with saving general settings not using tempSettingsStruct and using store values instead #1131

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions photon-client/src/components/settings/NetworkingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,31 @@ const settingsHaveChanged = (): boolean => {
a.shouldManage !== b.shouldManage ||
a.shouldPublishProto !== b.shouldPublishProto ||
a.canManage !== b.canManage ||
a.networkManagerIface !== b.networkManagerIface ||
a.networkManagerInterface !== b.networkManagerInterface ||
a.setStaticCommand !== b.setStaticCommand ||
a.setDHCPcommand !== b.setDHCPcommand
a.setDHCPCommand !== b.setDHCPCommand
);
};

const saveGeneralSettings = () => {
const changingStaticIp = useSettingsStore().network.connectionType === NetworkConnectionType.Static;

//
const payload = {
connectionType: tempSettingsStruct.value.connectionType,
hostname: tempSettingsStruct.value.hostname,
networkManagerInterface: tempSettingsStruct.value.networkManagerInterface || "",
ntServerAddress: tempSettingsStruct.value.ntServerAddress,
runNTServer: tempSettingsStruct.value.runNTServer,
setDHCPCommand: tempSettingsStruct.value.setDHCPCommand || "",
setStaticCommand: tempSettingsStruct.value.setStaticCommand || "",
shouldManage: tempSettingsStruct.value.shouldManage,
shouldPublishProto: tempSettingsStruct.value.shouldPublishProto,
staticIp: tempSettingsStruct.value.staticIp
};

useSettingsStore()
.saveGeneralSettings()
.updateGeneralSettings(payload)
.then((response) => {
useStateStore().showSnackbarMessage({
message: response.data.text || response.data,
Expand Down Expand Up @@ -110,8 +124,8 @@ const saveGeneralSettings = () => {
};

const currentNetworkInterfaceIndex = computed<number>({
get: () => useSettingsStore().networkInterfaceNames.indexOf(useSettingsStore().network.networkManagerIface || ""),
set: (v) => (tempSettingsStruct.value.networkManagerIface = useSettingsStore().networkInterfaceNames[v])
get: () => useSettingsStore().networkInterfaceNames.indexOf(useSettingsStore().network.networkManagerInterface || ""),
set: (v) => (tempSettingsStruct.value.networkManagerInterface = useSettingsStore().networkInterfaceNames[v])
});

watchEffect(() => {
Expand Down
14 changes: 1 addition & 13 deletions photon-client/src/stores/settings/GeneralSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,7 @@ export const useSettingsStore = defineStore("settings", {
this.network = data.networkSettings;
this.currentFieldLayout = data.atfl;
},
saveGeneralSettings() {
const payload: Required<ConfigurableNetworkSettings> = {
connectionType: this.network.connectionType,
hostname: this.network.hostname,
networkManagerIface: this.network.networkManagerIface || "",
ntServerAddress: this.network.ntServerAddress,
runNTServer: this.network.runNTServer,
setDHCPcommand: this.network.setDHCPcommand || "",
setStaticCommand: this.network.setStaticCommand || "",
shouldManage: this.network.shouldManage,
shouldPublishProto: this.network.shouldPublishProto,
staticIp: this.network.staticIp
};
updateGeneralSettings(payload: Required<ConfigurableNetworkSettings>) {
return axios.post("/settings/general", payload);
},
/**
Expand Down
4 changes: 2 additions & 2 deletions photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export interface NetworkSettings {
shouldManage: boolean;
shouldPublishProto: boolean;
canManage: boolean;
networkManagerIface?: string;
networkManagerInterface?: string;
setStaticCommand?: string;
setDHCPcommand?: string;
setDHCPCommand?: string;
networkInterfaceNames: NetworkInterfaceType[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public class NetworkConfig {
@JsonIgnore public static final String NM_IFACE_STRING = "${interface}";
@JsonIgnore public static final String NM_IP_STRING = "${ipaddr}";

public String networkManagerIface;
public String networkManagerInterface;
public String setStaticCommand =
"nmcli con mod ${interface} ipv4.addresses ${ipaddr}/8 ipv4.method \"manual\" ipv6.method \"disabled\"";
public String setDHCPcommand =
public String setDHCPCommand =
"nmcli con mod ${interface} ipv4.method \"auto\" ipv6.method \"disabled\"";

public NetworkConfig() {
if (Platform.isLinux()) {
// Default to the name of the first Ethernet connection. Otherwise, "Wired connection 1" is a
// reasonable guess
this.networkManagerIface =
this.networkManagerInterface =
NetworkUtils.getAllWiredInterfaces().stream()
.map(it -> it.connName)
.findFirst()
Expand All @@ -74,18 +74,18 @@ public NetworkConfig(
@JsonProperty("runNTServer") boolean runNTServer,
@JsonProperty("shouldManage") boolean shouldManage,
@JsonProperty("shouldPublishProto") boolean shouldPublishProto,
@JsonProperty("networkManagerIface") String networkManagerIface,
@JsonProperty("networkManagerInterface") String networkManagerInterface,
@JsonProperty("setStaticCommand") String setStaticCommand,
@JsonProperty("setDHCPcommand") String setDHCPcommand) {
@JsonProperty("setDHCPCommand") String setDHCPCommand) {
srimanachanta marked this conversation as resolved.
Show resolved Hide resolved
this.ntServerAddress = ntServerAddress;
this.connectionType = connectionType;
this.staticIp = staticIp;
this.hostname = hostname;
this.runNTServer = runNTServer;
this.shouldPublishProto = shouldPublishProto;
this.networkManagerIface = networkManagerIface;
this.networkManagerInterface = networkManagerInterface;
this.setStaticCommand = setStaticCommand;
this.setDHCPcommand = setDHCPcommand;
this.setDHCPCommand = setDHCPCommand;
setShouldManage(shouldManage);
}

Expand All @@ -102,12 +102,12 @@ public Map<String, Object> toHashMap() {

@JsonIgnore
public String getPhysicalInterfaceName() {
return NetworkUtils.getNMinfoForConnName(this.networkManagerIface).devName;
return NetworkUtils.getNMinfoForConnName(this.networkManagerInterface).devName;
}

@JsonIgnore
public String getEscapedInterfaceName() {
return "\"" + networkManagerIface + "\"";
return "\"" + networkManagerInterface + "\"";
}

@JsonIgnore
Expand Down Expand Up @@ -137,12 +137,12 @@ public String toString() {
+ hostname
+ ", runNTServer="
+ runNTServer
+ ", networkManagerIface="
+ networkManagerIface
+ ", networkManagerInterface="
+ networkManagerInterface
+ ", setStaticCommand="
+ setStaticCommand
+ ", setDHCPcommand="
+ setDHCPcommand
+ ", setDHCPCommand="
+ setDHCPCommand
+ ", shouldManage="
+ shouldManage
+ "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void initialize(boolean shouldManage) {
try {
// set nmcli back to DHCP, and re-run dhclient -- this ought to grab a new IP address
shell.executeBashCommand(
config.setDHCPcommand.replace(
config.setDHCPCommand.replace(
NetworkConfig.NM_IFACE_STRING, config.getEscapedInterfaceName()));
shell.executeBashCommand("dhclient " + config.getPhysicalInterfaceName(), false);
} catch (Exception e) {
Expand Down