From d5bebd400cba47ab20e619654f0f0a5222294216 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 19 Jun 2018 12:54:49 +0200 Subject: [PATCH] Added new guest user --- Step.Database/Controllers/UsersController.cs | 9 +++++---- Step.Database/DatabaseContext.cs | 4 +++- Step.Database/Migrations/Configuration.cs | 2 +- Step.NC/NcHandler.cs | 6 ++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Step.Database/Controllers/UsersController.cs b/Step.Database/Controllers/UsersController.cs index da653e85..0c9bf4f3 100644 --- a/Step.Database/Controllers/UsersController.cs +++ b/Step.Database/Controllers/UsersController.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Web.Helpers; using static Step.Config.ServerConfig; +using static Step.Model.Constants; namespace Step.Database.Controllers { @@ -105,15 +106,15 @@ namespace Step.Database.Controllers return user; } - public void CreateCmsDefaultUserIfNotExists(int machineId) + public void CreateCmsDefaultUserIfNotExists(int machineId, string username, string password, string name, string lastname, CultureInfo info, ROLE_IDS roleId) { // Find if there is a cms standard user - UserModel user = FindByUsername("cms"); + UserModel user = FindByUsername(username); if (user == null) { // If not exist add new user user = dbCtx.Users.Add( - CreateUserModel("cms", "cms", "cms", "cms", new CultureInfo("it")) + CreateUserModel(username, password, name, lastname, info) ); // Commit changes @@ -125,7 +126,7 @@ namespace Step.Database.Controllers MachineUserModel machineUser = machinesUsersController.FindByUserId(machineId, user.UserId); if (machineUser == null) - machinesUsersController.Create(machineId, user.UserId, 1); + machinesUsersController.Create(machineId, user.UserId, (int)roleId); } } diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs index 52129988..dc26869a 100644 --- a/Step.Database/DatabaseContext.cs +++ b/Step.Database/DatabaseContext.cs @@ -6,6 +6,7 @@ using Step.Model.DatabaseModels; using System; using System.Data.Entity; using System.Data.Entity.Migrations; +using System.Globalization; using System.IO; using System.Linq; using static Step.Config.ServerConfig; @@ -141,7 +142,8 @@ namespace Step.Database using (UsersController usersController = new UsersController()) { // Create default CMS user - usersController.CreateCmsDefaultUserIfNotExists(MachineConfig.MachineId); + usersController.CreateCmsDefaultUserIfNotExists(MachineConfig.MachineId, "cms", "cms", "cms", "cms", new CultureInfo("it"), ROLE_IDS.CMS_SERVICE_ONLY); + usersController.CreateCmsDefaultUserIfNotExists(MachineConfig.MachineId, "guest", "guest", "guest", "guest", new CultureInfo("it"), ROLE_IDS.GUEST); } } else diff --git a/Step.Database/Migrations/Configuration.cs b/Step.Database/Migrations/Configuration.cs index 15cf4205..6102b87a 100644 --- a/Step.Database/Migrations/Configuration.cs +++ b/Step.Database/Migrations/Configuration.cs @@ -21,7 +21,7 @@ namespace Step.Database.Migrations context.Roles.AddOrUpdate( new RoleModel() { RoleId = (int)ROLE_IDS.CMS_SERVICE_ONLY, Level = 100, Name = "cmsServiceOnly" }, new RoleModel() { RoleId = (int)ROLE_IDS.ADMIN, Level = 10, Name = "Admin" }, - new RoleModel() { RoleId = (int)ROLE_IDS.GUEST, Level = 0, Name = "Guest" } + new RoleModel() { RoleId = (int)ROLE_IDS.GUEST, Level = 1, Name = "Guest" } ); context.FunctionsAccess.AddOrUpdate( diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 8c2191f4..2276ff1b 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -559,12 +559,18 @@ namespace Step.NC break; // DEADLINE <= NOW if (currMaintenance.Deadline <= DateTime.Now) + { + maintenancesController.UpdateLastExpirationDate(currMaintenance.MaintenanceId, currMaintenance.Deadline); + currMaintenance.LastExpirationDate = currMaintenance.Deadline; + // Add item to return list expiredMaintenance.Add(new DTOExpiredMaintenanceModel() { Id = currMaintenance.MaintenanceId, ExpirationDate = currMaintenance.Deadline }); + } + } break;