diff --git a/devdocs/todo.txt b/devdocs/todo.txt index b7667add..f66333cf 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -5,21 +5,6 @@ choco upgrade chocolatey todo: ip address logged in container mode is the local server as I guess it comes from NGINX is there a way to capture this or...? -todo: AYANOVA_SERVER_TEST_MODE Is this a thing anymore? I think I need to remove it as an environment variable and all the startup code to go with it -todo: AYANOVA_PERMANENTLY_ERASE_DATABASE does more than that, also resets dbid, should this option name be changed to something more dire - it sounds just like the option in ayaNova to erase all data but those are two different things - "permanently" is redundant as well. -todo: permanently erase db startup thing, should it really exist? - It will zap the dbid so a user might expect to just use their old license but it wont' fetch again - we could issue a new key to replace with the new dbid and also issue a revoke key for the old dbid so that - there can be no fraudulent use this way. - I guess it's a rare situation and if the option to delete is there people will surely fuck up and use it unintentionally? - or maybe not -todo: could be a presentation issue but erasing the database and "permanently" erasing the db do two different things completely - Maybe change the biz object erase to empty or remove all data or something along those lines - If it requires too much explanation then it's probably mis-identified as to what it does - - todo: docs, change all named references to the Manager / manager / admin / adminstrator account to "SuperUser" todo: add alternate, backup domain to be checked for license key if primary can't be reached diff --git a/server/AyaNova/Controllers/LicenseController.cs b/server/AyaNova/Controllers/LicenseController.cs index c4f8824b..cee9e406 100644 --- a/server/AyaNova/Controllers/LicenseController.cs +++ b/server/AyaNova/Controllers/LicenseController.cs @@ -265,7 +265,7 @@ namespace AyaNova.Api.Controllers //empty the db - await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log); + await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, Guid.Empty); //Log await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct); diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index 28d3e2c2..9cc2ccd2 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -306,7 +306,7 @@ namespace AyaNova.Util // Erase all user entered data from the db // This is called by seeder for trial seeding purposes // and by v8 migrate and by license controller when erasing db - internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log) + internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log, Guid jobIdToKeep) { _log.LogInformation("Erasing Database \"{0}\"", _dbName); @@ -321,12 +321,6 @@ namespace AyaNova.Util { await conn.OpenAsync(); - //### DELIBERATELY IGNORED - //Some data is deliberately not deleted for now: - //Reports - //Logos - - //prepare to delete by removing foreign keys using (var cmd = new Npgsql.NpgsqlCommand()) { @@ -350,48 +344,31 @@ namespace AyaNova.Util cmd.CommandText = "update apurchaseorderitem set workorderitempartrequestid=null;"; await cmd.ExecuteNonQueryAsync(); - cmd.CommandText = "update aglobalbizsettings set " - + "webaddress =null, phone1 =null, phone2 =null, emailaddress =null, postaddress =null, postcity =null, postregion =null, postcountry =null, postcode =null, " - + "address =null, city =null, region =null, country =null, latitude=null, longitude =null, " - + "filtercasesensitive = FALSE, " - + "useinventory = TRUE, " - + "allowscheduleconflicts = TRUE, " - + "workordercompletebyage = '00:00:00', " - + "workordertraveldefaultminutes = 0, " - + "worklaborscheduledefaultminutes = 0, " - + "signaturetitle =null, " - + "signatureheader =null, " - + "signaturefooter =null, " - + "customerservicerequestinfotext =null, " - + "customerallowcsr = FALSE, customerallowcsrintags ='{}', " - + "customerallowcreateunit = FALSE, customerallowcreateunitintags ='{}', " - + "customerallowviewwo = FALSE, customerallowviewwointags ='{}', " - + "customerworkorderreport1tags ='{}', customerworkorderreport2tags ='{}', " - + "customerworkorderreport3tags ='{}', customerworkorderreport4tags ='{}', customerworkorderreport5tags ='{}', " - + "customerallowwowiki = FALSE, customerallowwowikiintags ='{}', " - + "customerallowwoattachments = FALSE, customerallowwoattachmentsintags ='{}', " - + "customerallowusersettings = FALSE, customerallowusersettingsintags ='{}', " - + "customerallownotifyserviceimminent = FALSE, customerallownotifyserviceimminentintags ='{}', " - + "customerallownotifycsraccepted = FALSE, customerallownotifycsracceptedintags ='{}', " - + "customerallownotifycsrrejected = FALSE, customerallownotifycsrrejectedintags ='{}', " - + "customerallownotifywocreated = FALSE, customerallownotifywocreatedintags ='{}', " - + "customerallownotifywocompleted = FALSE, customerallownotifywocompletedintags ='{}', " - + "taxpartpurchaseid=null,taxpartsaleid=null,taxratesaleid=null, " - + "customerdefaultworkorderreportid=null, customertagworkorderreport1id=null, customertagworkorderreport2id=null, " - + "customertagworkorderreport3id=null, customertagworkorderreport4id=null, customertagworkorderreport5id=null "; - await cmd.ExecuteNonQueryAsync(); - //reset global settings cache taxes - ServerGlobalBizSettings.Cache.TaxPartPurchaseId = null; - ServerGlobalBizSettings.Cache.TaxPartSaleId = null; - ServerGlobalBizSettings.Cache.TaxRateSaleId = null; - cmd.CommandText = "update aworkorderitem set fromcsrid=null;"; await cmd.ExecuteNonQueryAsync(); - //aglobalopsbackupsettings just keep as is which is the safe option + if (jobIdToKeep != Guid.Empty) + { + //delete from aopsjoblog where jobid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f'; + //delete from aopsjob where gid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f'; + cmd.CommandText = $"delete from aopsjoblog where jobid <> '{jobIdToKeep}'"; + await cmd.ExecuteNonQueryAsync(); + cmd.CommandText = $"delete from aopsjob where gid <> '{jobIdToKeep}'"; + await cmd.ExecuteNonQueryAsync(); + } - cmd.CommandText = "update aglobalopsnotificationsettings set smtpdeliveryactive=false, smtpserveraddress=null,smtpaccount=null,smtppassword=null,connectionsecurity=0, smtpserverport=null,notifyfromaddress=null,ayanovaserverurl=null;"; - await cmd.ExecuteNonQueryAsync(); + + //DELIBERATELY NOT ERASED: + //NOTE: these tables commented below are deliberately not affected as it's assumed for a **COMPLETE** erase users will erase manually or use the config setting to completely drop the database + //For anything less than that it's assumed users are testing things out and want to keep these tables but erase the biz data + //aglobalopsbackupsettings + //aglobalopsnotificationsettings + //aglobalbizsettings + //alogo + //areport + + //await EraseTableAsync("aopsjoblog", conn, true); + // await EraseTableAsync("aopsjob", conn, true); } @@ -509,7 +486,7 @@ namespace AyaNova.Util await EraseTableAsync("aservicerate", conn); await EraseTableAsync("atravelrate", conn); - await EraseTableAsync("ataxcode", conn); + //await EraseTableAsync("ataxcode", conn); await EraseTableAsync("aquotestatus", conn); @@ -522,12 +499,7 @@ namespace AyaNova.Util await EraseTableAsync("ametricdd", conn, true); await EraseTableAsync("adashboardview", conn); - await EraseTableAsync("aopsjoblog", conn, true); - await EraseTableAsync("aopsjob", conn, true); - await EraseTableAsync("alogo", conn); - - await EraseTableAsync("areport", conn); - await Biz.PrimeData.PrimeReportTemplates(); + // await EraseTableAsync("XXXXX", conn); diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index e2d6dfbd..3205e0b0 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -104,7 +104,7 @@ namespace AyaNova.Util ServerBootConfig.SEEDING = true; //Erase all the data except for the license, schema and the SuperUser - await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log); + await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, JobId); //Event log erase and seeding using (var ct = ServiceProviderProvider.DBContext) {