This commit is contained in:
2022-12-27 00:51:21 +00:00
parent 9b77da02a0
commit c5d1350b6b
3 changed files with 135 additions and 3 deletions

View File

@@ -555,6 +555,61 @@ export default {
loading: false loading: false
}); });
} }
},
async erase() {
const vm = this;
try {
if (this.dbIsEmpty != true) {
let dialogResult = await window.$gz.dialog.confirmGeneric(
"AdminEraseDatabaseWarning",
"dire"
);
if (dialogResult == false) {
return;
}
dialogResult = await window.$gz.dialog.confirmGeneric(
"AdminEraseDatabaseLastWarning",
"dire"
);
if (dialogResult == false) {
return;
}
}
//call erase
window.$gz.erasingDatabase = true; //suspend notify polling
await window.$gz.api.upsert(
API_BASE_URL + "/permanently-erase-all-data",
"I bloody understand"
);
vm.$router.push("/login");
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
}
},
async import() {
const vm = this;
try {
if (this.dbIsEmpty != true) {
let dialogResult = await window.$gz.dialog.confirmGeneric(
"Import",
"warning"
);
if (dialogResult == false) {
return;
}
}
//call erase
window.$gz.erasingDatabase = true; //suspend notify polling
await window.$gz.api.upsert(API_BASE_URL + "/import-rockfish");
vm.$router.push("/login");
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
}
} }
} }
}; };
@@ -572,6 +627,12 @@ async function clickHandler(menuItem) {
case "save": case "save":
m.vm.submit(); m.vm.submit();
break; break;
case "erase":
m.vm.erase();
break;
case "import-rockfish":
m.vm.import();
break;
default: default:
window.$gz.eventBus.$emit( window.$gz.eventBus.$emit(
"notify-warning", "notify-warning",
@@ -608,6 +669,20 @@ function generateMenu(vm) {
}); });
} }
menuOptions.menuItems.push({ divider: true, inset: false }); menuOptions.menuItems.push({ divider: true, inset: false });
menuOptions.menuItems.push({
title: "AdminEraseDatabase",
icon: "$sockiSkullCrossbones",
key: FORM_KEY + ":erase",
vm: vm
});
menuOptions.menuItems.push({
title: "Import",
icon: "$sockiFileImport",
key: FORM_KEY + ":import-rockfish",
vm: vm
});
menuOptions.menuItems.push({ divider: true, inset: false });
menuOptions.menuItems.push({ divider: true, inset: false });
window.$gz.eventBus.$emit("menu-change", menuOptions); window.$gz.eventBus.$emit("menu-change", menuOptions);
} }
@@ -680,7 +755,10 @@ async function fetchTranslatedText() {
"AddressCountry", "AddressCountry",
"AddressPostal", "AddressPostal",
"AddressLatitude", "AddressLatitude",
"AddressLongitude" "AddressLongitude",
"AdminEraseDatabaseWarning",
"AdminEraseDatabase",
"AdminEraseDatabaseLastWarning"
]); ]);
} }
</script> </script>

View File

@@ -121,6 +121,49 @@ namespace Sockeye.Api.Controllers
return Ok(ApiOkResponse.Response(ret)); return Ok(ApiOkResponse.Response(ret));
} }
[HttpPost("permanently-erase-all-data")]
public async Task<IActionResult> RemoveAllData([FromBody] string acceptCode)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
long UserId = UserIdFromContext.Id(HttpContext.Items);
//SuperUser only and must have accept code
if (string.IsNullOrWhiteSpace(acceptCode) || acceptCode.ToLowerInvariant() != "i bloody understand")
return StatusCode(403, new ApiNotAuthorizedResponse());
//empty the db
await Sockeye.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, SockType.Global, SockEvent.EraseAllData), ct);
return NoContent();
}
/// <summary>
/// import data from rockfish that isn't already present
/// </summary>
/// <returns>No content</returns>
[HttpPost("import-rockfish")]
public async Task<IActionResult> ImportRockfish([FromBody] Customer newObject, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
GlobalBizSettingsBiz biz = GlobalBizSettingsBiz.GetBiz(ct, HttpContext);
await biz.ImportRockfish();
return NoContent();
}

View File

@@ -112,6 +112,17 @@ namespace Sockeye.Biz
//IMPORT FROM ROCKFISH
public async Task ImportRockfish()
{
//connect to rockfish
//in the correct order retrieve every object and if it's not already present in sockeye, import it
//this should be callable any time and it will just update so it can be test live in sync / parallel until ready to switch over
await Task.CompletedTask;
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
}//eoc }//eoc