Skip to content

Commit

Permalink
add toogle on Policies page (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: Sandeepa Singh <[email protected]>
  • Loading branch information
sandeepasingh116 and Sandeepa Singh authored Dec 19, 2022
1 parent b311334 commit 203a27a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@
}
},
"pagePolicies": {
"acfUploadEnablement": "Unauthenticated ACF upload enablement",
"acfUploadEnablementDescription": "Allow unauthenticated users to upload ACFs.",
"hostTpm": "Host TPM",
"hostTpmDescription": "Enable to ensure the system only boots when the TPM is functional.",
"hostUsb": "Host USB enablement",
Expand Down
46 changes: 46 additions & 0 deletions src/store/modules/SecurityAndAccess/PoliciesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import i18n from '@/i18n';
const PoliciesStore = {
namespaced: true,
state: {
acfUploadEnablement: false,
sshProtocolEnabled: false,
ipmiProtocolEnabled: false,
rtadEnabled: 'Disabled',
Expand All @@ -14,6 +15,7 @@ const PoliciesStore = {
hostUsbEnabled: 'Enabled',
},
getters: {
acfUploadEnablement: (state) => state.acfUploadEnablement,
sshProtocolEnabled: (state) => state.sshProtocolEnabled,
ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled,
rtadEnabled: (state) => state.rtadEnabled,
Expand All @@ -25,6 +27,8 @@ const PoliciesStore = {
hostUsbEnabled: (state) => state.hostUsbEnabled,
},
mutations: {
setAcfUploadEnablement: (state, acfUploadEnablement) =>
(state.acfUploadEnablement = acfUploadEnablement),
setSshProtocolEnabled: (state, sshProtocolEnabled) =>
(state.sshProtocolEnabled = sshProtocolEnabled),
setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) =>
Expand Down Expand Up @@ -65,6 +69,17 @@ const PoliciesStore = {
})
.catch((error) => console.log(error));
},
async getUnauthenticatedACFUploadEnablement({ commit }) {
return await api
.get('/redfish/v1/AccountService/Accounts/service')
.then((response) => {
commit(
'setAcfUploadEnablement',
response?.data?.Oem?.IBM?.ACF?.AllowUnauthACFUpload
);
})
.catch((error) => console.log(error));
},
async getBiosStatus({ commit }) {
return await api
.get('/redfish/v1/Systems/system/Bios')
Expand Down Expand Up @@ -143,6 +158,37 @@ const PoliciesStore = {
);
});
},
async saveUnauthenticatedACFUploadEnablement(
{ commit },
updatedAcfUploadEnablement
) {
commit('setAcfUploadEnablement', updatedAcfUploadEnablement);
const oem = {
Oem: {
IBM: {
ACF: {
AllowUnauthACFUpload: updatedAcfUploadEnablement,
},
},
},
};
return await api
.patch('/redfish/v1/AccountService/Accounts/service', oem)
.then(() => {
return i18n.t('pagePolicies.toast.successNetworkPolicyUpdate', {
policy: i18n.t('pagePolicies.acfUploadEnablement'),
});
})
.catch((error) => {
console.log(error);
commit('setAcfUploadEnablement', !updatedAcfUploadEnablement);
throw new Error(
i18n.t('pagePolicies.toast.errorNetworkPolicyUpdate', {
policy: i18n.t('pagePolicies.acfUploadEnablement'),
})
);
});
},
async saveIpmiProtocolState({ commit }, protocolEnabled) {
commit('setIpmiProtocolEnabled', protocolEnabled);
const ipmi = {
Expand Down
41 changes: 41 additions & 0 deletions src/views/SecurityAndAccess/Policies/Policies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,31 @@
</b-form-checkbox>
</b-col>
</b-row>
<b-row v-if="isAdminUser || isServiceUser" class="section-divider">
<b-col class="d-flex align-items-center justify-content-between">
<dl class="mt-3 mr-3 w-75">
<dt>{{ $t('pagePolicies.acfUploadEnablement') }}</dt>
<dd>
{{ $t('pagePolicies.acfUploadEnablementDescription') }}
</dd>
</dl>
<b-form-checkbox
id="unauthenticatedACFUploadEnablementSwitch"
v-model="unauthenticatedACFUploadEnablementState"
data-test-id="policies-toggle-unauthenticatedACFUploadEnablement"
switch
@change="changeUnauthenticatedACFUploadEnablement"
>
<span class="sr-only">
{{ $t('pagePolicies.usbFirmwareUpdatePolicy') }}
</span>
<span v-if="unauthenticatedACFUploadEnablementState">
{{ $t('global.status.enabled') }}
</span>
<span v-else>{{ $t('global.status.disabled') }}</span>
</b-form-checkbox>
</b-col>
</b-row>
</b-col>
</b-row>
</b-container>
Expand Down Expand Up @@ -316,13 +341,23 @@ export default {
return newValue;
},
},
unauthenticatedACFUploadEnablementState: {
get() {
return this.$store.getters['policies/acfUploadEnablement'];
},
set(newValue) {
return newValue;
},
},
},
created() {
this.startLoader();
Promise.all([
this.$store.dispatch('policies/getBiosStatus'),
this.$store.dispatch('policies/getNetworkProtocolStatus'),
this.$store.dispatch('policies/getUsbFirmwareUpdatePolicyEnabled'),
this.$store.dispatch('policies/getUnauthenticatedACFUploadEnablement'),
this.$store.dispatch('policies/getTpmPolicy'),
this.$store.dispatch('userManagement/getUsers'),
this.checkForUserData(),
Expand Down Expand Up @@ -379,6 +414,12 @@ export default {
.then((message) => this.successToast(message))
.catch(({ message }) => this.errorToast(message));
},
changeUnauthenticatedACFUploadEnablement(state) {
this.$store
.dispatch('policies/saveUnauthenticatedACFUploadEnablement', state)
.then((message) => this.successToast(message))
.catch(({ message }) => this.errorToast(message));
},
checkForUserData() {
if (!this.currentUser) {
this.$store.dispatch('userManagement/getUsers');
Expand Down

0 comments on commit 203a27a

Please sign in to comment.