This commit is contained in:
109
server/AyaNova/biz/GlobalOpsNotificationSettingsBiz.cs
Normal file
109
server/AyaNova/biz/GlobalOpsNotificationSettingsBiz.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using AyaNova.Util;
|
||||||
|
using AyaNova.Api.ControllerHelpers;
|
||||||
|
using AyaNova.Models;
|
||||||
|
|
||||||
|
namespace AyaNova.Biz
|
||||||
|
{
|
||||||
|
|
||||||
|
internal class GlobalOpsNotificationSettingsBiz : BizObject
|
||||||
|
{
|
||||||
|
|
||||||
|
internal GlobalOpsNotificationSettingsBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
|
{
|
||||||
|
ct = dbcontext;
|
||||||
|
UserId = currentUserId;
|
||||||
|
UserTranslationId = userTranslationId;
|
||||||
|
CurrentUserRoles = UserRoles;
|
||||||
|
BizType = AyaType.Backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static GlobalOpsNotificationSettingsBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||||
|
{
|
||||||
|
if (httpContext != null)
|
||||||
|
return new GlobalOpsNotificationSettingsBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||||
|
else
|
||||||
|
return new GlobalOpsNotificationSettingsBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// GET
|
||||||
|
|
||||||
|
//Get one
|
||||||
|
internal async Task<GlobalOpsNotificationSettings> GetAsync(bool logTheGetEvent = true)
|
||||||
|
{
|
||||||
|
//first try to fetch from db
|
||||||
|
var ret = await ct.GlobalOpsNotificationSettings.SingleOrDefaultAsync(m => m.Id == 1);
|
||||||
|
if (logTheGetEvent && ret != null)
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Retrieved), ct);
|
||||||
|
//expected to exists because it's created on boot if not present
|
||||||
|
if (ret == null)
|
||||||
|
throw new System.Exception("GlobalOpsNotificationSettings::GetAsync -> Settings object not found in database!!");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//UPDATE
|
||||||
|
//
|
||||||
|
|
||||||
|
//put
|
||||||
|
internal async Task<GlobalOpsNotificationSettings> PutAsync(GlobalOpsNotificationSettings putObject)
|
||||||
|
{
|
||||||
|
var dbObject = await ct.GlobalOpsNotificationSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
||||||
|
if (dbObject == null)
|
||||||
|
throw new System.Exception("GlobalOpsNotificationSettings::PutAsync -> Settings object not found in database!!");
|
||||||
|
|
||||||
|
CopyObject.Copy(putObject, dbObject, "Id");
|
||||||
|
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
|
||||||
|
Validate(dbObject);
|
||||||
|
if (HasErrors)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
||||||
|
//Update the static copy for the server
|
||||||
|
ServerGlobalOpsSettingsCache.Notify = dbObject;
|
||||||
|
|
||||||
|
return dbObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//VALIDATION
|
||||||
|
//
|
||||||
|
|
||||||
|
//Can save or update?
|
||||||
|
private void Validate(GlobalOpsNotificationSettings inObj)
|
||||||
|
{
|
||||||
|
|
||||||
|
//currently nothing to validate
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
|
||||||
|
|
||||||
|
}//eons
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ namespace AyaNova.Models
|
|||||||
public virtual DbSet<Widget> Widget { get; set; }
|
public virtual DbSet<Widget> Widget { get; set; }
|
||||||
public virtual DbSet<GlobalBizSettings> GlobalBizSettings { get; set; }
|
public virtual DbSet<GlobalBizSettings> GlobalBizSettings { get; set; }
|
||||||
public virtual DbSet<GlobalOpsBackupSettings> GlobalOpsBackupSettings { get; set; }
|
public virtual DbSet<GlobalOpsBackupSettings> GlobalOpsBackupSettings { get; set; }
|
||||||
|
public virtual DbSet<GlobalOpsNotificationSettings> GlobalOpsNotificationSettings { get; set; }
|
||||||
public virtual DbSet<Event> Event { get; set; }
|
public virtual DbSet<Event> Event { get; set; }
|
||||||
public virtual DbSet<SearchDictionary> SearchDictionary { get; set; }
|
public virtual DbSet<SearchDictionary> SearchDictionary { get; set; }
|
||||||
public virtual DbSet<SearchKey> SearchKey { get; set; }
|
public virtual DbSet<SearchKey> SearchKey { get; set; }
|
||||||
|
|||||||
@@ -14,10 +14,17 @@ namespace AyaNova.Models
|
|||||||
public NotifyMailSecurity ConnectionSecurity { get; set; }
|
public NotifyMailSecurity ConnectionSecurity { get; set; }
|
||||||
public int SmtpServerPort { get; set; }
|
public int SmtpServerPort { get; set; }
|
||||||
public string NotifyFromAddress { get; set; }
|
public string NotifyFromAddress { get; set; }
|
||||||
|
|
||||||
public GlobalOpsNotificationSettings()
|
public GlobalOpsNotificationSettings()
|
||||||
{
|
{
|
||||||
Active = true;
|
Active = true;
|
||||||
|
Id = 1;
|
||||||
|
SmtpServerAddress="mail.example.com";
|
||||||
|
SmtpAccount="notifydeliverfromaccount@example.com";
|
||||||
|
SmtpPassword="examplepassword";
|
||||||
|
ConnectionSecurity= NotifyMailSecurity.SSLTLS;
|
||||||
|
SmtpServerPort=587;
|
||||||
|
NotifyFromAddress="noreply@example.com";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace AyaNova.Util
|
|||||||
internal static bool BOOTING { get; set; }
|
internal static bool BOOTING { get; set; }
|
||||||
|
|
||||||
internal static GlobalOpsBackupSettings Backup { get; set; }
|
internal static GlobalOpsBackupSettings Backup { get; set; }
|
||||||
|
internal static GlobalOpsNotificationSettings Notify {get;set;}
|
||||||
internal static DateTime NextBackup { get; set; }
|
internal static DateTime NextBackup { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populate and / or create the settings
|
/// Populate and / or create the settings
|
||||||
@@ -32,6 +33,13 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
NextBackup = FileUtil.MostRecentAutomatedBackupFileDate();
|
NextBackup = FileUtil.MostRecentAutomatedBackupFileDate();
|
||||||
SetNextBackup();
|
SetNextBackup();
|
||||||
|
|
||||||
|
|
||||||
|
Notify=ct.GlobalOpsNotificationSettings.FirstOrDefault(z=>z.Id==1);
|
||||||
|
if(Notify==null)
|
||||||
|
{
|
||||||
|
Notify=new GlobalOpsNotificationSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetNextBackup()
|
internal static void SetNextBackup()
|
||||||
|
|||||||
Reference in New Issue
Block a user