Merge pull request #1862 from sbwalker/dev
moduledefinition settings and host settings
This commit is contained in:
commit
d093c03d92
|
@ -1,4 +1,5 @@
|
|||
using Oqtane.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -128,6 +129,19 @@ namespace Oqtane.Services
|
|||
/// <returns></returns>
|
||||
Task UpdateFolderSettingsAsync(Dictionary<string, string> folderSettings, int folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a key-value dictionary of all tenant settings
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, string>> GetHostSettingsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Updates a host setting
|
||||
/// </summary>
|
||||
/// <param name="hostSettings"></param>
|
||||
/// <returns></returns>
|
||||
Task UpdateHostSettingsAsync(Dictionary<string, string> hostSettings);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a key-value dictionary of all settings for the given entityName
|
||||
/// </summary>
|
||||
|
@ -150,7 +164,7 @@ namespace Oqtane.Services
|
|||
/// </summary>
|
||||
/// <param name="settingId"></param>
|
||||
/// <returns></returns>
|
||||
Task<Setting> GetSettingAsync(int settingId);
|
||||
Task<Setting> GetSettingAsync(string entityName, int settingId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -172,7 +186,7 @@ namespace Oqtane.Services
|
|||
/// </summary>
|
||||
/// <param name="settingId"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteSettingAsync(int settingId);
|
||||
Task DeleteSettingAsync(string entityName, int settingId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the given settingName (key) from the given key-value dictionary
|
||||
|
@ -195,5 +209,13 @@ namespace Oqtane.Services
|
|||
Dictionary<string, string> SetSetting(Dictionary<string, string> settings, string settingName, string settingValue, bool isPublic);
|
||||
|
||||
Dictionary<string, string> MergeSettings(Dictionary<string, string> settings1, Dictionary<string, string> settings2);
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("GetSettingAsync(int settingId) is deprecated. Use GetSettingAsync(string entityName, int settingId) instead.", false)]
|
||||
Task<Setting> GetSettingAsync(int settingId);
|
||||
|
||||
[Obsolete("DeleteSettingAsync(int settingId) is deprecated. Use DeleteSettingAsync(string entityName, int settingId) instead.", false)]
|
||||
Task DeleteSettingAsync(int settingId);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Oqtane.Services
|
|||
}
|
||||
|
||||
private string Apiurl => CreateApiUrl("Setting", _siteState.Alias);
|
||||
|
||||
public async Task<Dictionary<string, string>> GetTenantSettingsAsync()
|
||||
{
|
||||
return await GetSettingsAsync(EntityNames.Tenant, -1);
|
||||
|
@ -101,6 +102,16 @@ namespace Oqtane.Services
|
|||
await UpdateSettingsAsync(folderSettings, EntityNames.Folder, folderId);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> GetHostSettingsAsync()
|
||||
{
|
||||
return await GetSettingsAsync(EntityNames.Host, -1);
|
||||
}
|
||||
|
||||
public async Task UpdateHostSettingsAsync(Dictionary<string, string> hostSettings)
|
||||
{
|
||||
await UpdateSettingsAsync(hostSettings, EntityNames.Host, -1);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> GetSettingsAsync(string entityName, int entityId)
|
||||
{
|
||||
var dictionary = new Dictionary<string, string>();
|
||||
|
@ -154,9 +165,9 @@ namespace Oqtane.Services
|
|||
}
|
||||
|
||||
|
||||
public async Task<Setting> GetSettingAsync(int settingId)
|
||||
public async Task<Setting> GetSettingAsync(string entityName, int settingId)
|
||||
{
|
||||
return await GetJsonAsync<Setting>($"{Apiurl}/{settingId}");
|
||||
return await GetJsonAsync<Setting>($"{Apiurl}/{settingId}/{entityName}");
|
||||
}
|
||||
|
||||
public async Task<Setting> AddSettingAsync(Setting setting)
|
||||
|
@ -169,9 +180,9 @@ namespace Oqtane.Services
|
|||
return await PutJsonAsync<Setting>($"{Apiurl}/{setting.SettingId}", setting);
|
||||
}
|
||||
|
||||
public async Task DeleteSettingAsync(int settingId)
|
||||
public async Task DeleteSettingAsync(string entityName, int settingId)
|
||||
{
|
||||
await DeleteAsync($"{Apiurl}/{settingId}");
|
||||
await DeleteAsync($"{Apiurl}/{settingId}/{entityName}");
|
||||
}
|
||||
|
||||
|
||||
|
@ -230,5 +241,19 @@ namespace Oqtane.Services
|
|||
}
|
||||
return settings1;
|
||||
}
|
||||
|
||||
[Obsolete("GetSettingAsync(int settingId) is deprecated. Use GetSettingAsync(string entityName, int settingId) instead.", false)]
|
||||
public async Task<Setting> GetSettingAsync(int settingId)
|
||||
{
|
||||
return await GetJsonAsync<Setting>($"{Apiurl}/{settingId}/tenant");
|
||||
}
|
||||
|
||||
[Obsolete("DeleteSettingAsync(int settingId) is deprecated. Use DeleteSettingAsync(string entityName, int settingId) instead.", false)]
|
||||
public async Task DeleteSettingAsync(int settingId)
|
||||
{
|
||||
await DeleteAsync($"{Apiurl}/{settingId}/tenant");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,11 +52,11 @@ namespace Oqtane.Controllers
|
|||
return settings;
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
public Setting Get(int id)
|
||||
// GET api/<controller>/5/xxx
|
||||
[HttpGet("{id}/{entityName}")]
|
||||
public Setting Get(int id, string entityName)
|
||||
{
|
||||
Setting setting = _settings.GetSetting(id);
|
||||
Setting setting = _settings.GetSetting(entityName, id);
|
||||
if (IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.View))
|
||||
{
|
||||
if (setting.EntityName == EntityNames.Site && !User.IsInRole(RoleNames.Admin) && !setting.IsPublic)
|
||||
|
@ -111,14 +111,14 @@ namespace Oqtane.Controllers
|
|||
return setting;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
// DELETE api/<controller>/5/xxx
|
||||
[HttpDelete("{id}/{entityName}")]
|
||||
public void Delete(string entityName, int id)
|
||||
{
|
||||
Setting setting = _settings.GetSetting(id);
|
||||
Setting setting = _settings.GetSetting(entityName, id);
|
||||
if (IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit))
|
||||
{
|
||||
_settings.DeleteSetting(id);
|
||||
_settings.DeleteSetting(setting.EntityName, id);
|
||||
AddSyncEvent(setting.EntityName);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Setting Deleted {Setting}", setting);
|
||||
}
|
||||
|
@ -140,6 +140,8 @@ namespace Oqtane.Controllers
|
|||
switch (entityName)
|
||||
{
|
||||
case EntityNames.Tenant:
|
||||
case EntityNames.ModuleDefinition:
|
||||
case EntityNames.Host:
|
||||
authorized = User.IsInRole(RoleNames.Host);
|
||||
break;
|
||||
case EntityNames.Site:
|
||||
|
@ -154,9 +156,6 @@ namespace Oqtane.Controllers
|
|||
break;
|
||||
case EntityNames.Page:
|
||||
case EntityNames.Module:
|
||||
case EntityNames.ModuleDefinition:
|
||||
authorized = User.IsInRole(RoleNames.Host);
|
||||
break;
|
||||
case EntityNames.Folder:
|
||||
authorized = _userPermissions.IsAuthorized(User, entityName, entityId, permissionName);
|
||||
break;
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace Oqtane.Repository
|
|||
public virtual DbSet<ModuleDefinition> ModuleDefinition { get; set; }
|
||||
public virtual DbSet<Job> Job { get; set; }
|
||||
public virtual DbSet<JobLog> JobLog { get; set; }
|
||||
public virtual DbSet<Setting> Setting { get; set; }
|
||||
|
||||
public override int SaveChanges()
|
||||
{
|
||||
|
|
|
@ -18,7 +18,6 @@ namespace Oqtane.Repository
|
|||
public virtual DbSet<Page> Page { get; set; }
|
||||
public virtual DbSet<PageModule> PageModule { get; set; }
|
||||
public virtual DbSet<Module> Module { get; set; }
|
||||
public virtual DbSet<ModuleDefinition> ModuleDefinition { get; set; }
|
||||
public virtual DbSet<User> User { get; set; }
|
||||
public virtual DbSet<Profile> Profile { get; set; }
|
||||
public virtual DbSet<Role> Role { get; set; }
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Oqtane.Repository
|
|||
IEnumerable<Setting> GetSettings(string entityName, int entityId);
|
||||
Setting AddSetting(Setting setting);
|
||||
Setting UpdateSetting(Setting setting);
|
||||
Setting GetSetting(int settingId);
|
||||
void DeleteSetting(int settingId);
|
||||
Setting GetSetting(string entityName, int settingId);
|
||||
void DeleteSetting(string entityName, int settingId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,53 +2,100 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public class SettingRepository : ISettingRepository
|
||||
{
|
||||
private TenantDBContext _db;
|
||||
private TenantDBContext _tenant;
|
||||
private MasterDBContext _master;
|
||||
|
||||
public SettingRepository(TenantDBContext context)
|
||||
public SettingRepository(TenantDBContext tenant, MasterDBContext master)
|
||||
{
|
||||
_db = context;
|
||||
_tenant = tenant;
|
||||
_master = master;
|
||||
}
|
||||
|
||||
public IEnumerable<Setting> GetSettings(string entityName)
|
||||
{
|
||||
return _db.Setting.Where(item => item.EntityName == entityName);
|
||||
if (IsMaster(entityName))
|
||||
{
|
||||
return _master.Setting.Where(item => item.EntityName == entityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _tenant.Setting.Where(item => item.EntityName == entityName);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Setting> GetSettings(string entityName, int entityId)
|
||||
{
|
||||
return _db.Setting.Where(item => item.EntityName == entityName)
|
||||
.Where(item => item.EntityId == entityId);
|
||||
var settings = GetSettings(entityName);
|
||||
return settings.Where(item => item.EntityId == entityId);
|
||||
}
|
||||
|
||||
public Setting AddSetting(Setting setting)
|
||||
{
|
||||
_db.Setting.Add(setting);
|
||||
_db.SaveChanges();
|
||||
if (IsMaster(setting.EntityName))
|
||||
{
|
||||
_master.Setting.Add(setting);
|
||||
_master.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
_tenant.Setting.Add(setting);
|
||||
_tenant.SaveChanges();
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
public Setting UpdateSetting(Setting setting)
|
||||
{
|
||||
_db.Entry(setting).State = EntityState.Modified;
|
||||
_db.SaveChanges();
|
||||
if (IsMaster(setting.EntityName))
|
||||
{
|
||||
_master.Entry(setting).State = EntityState.Modified;
|
||||
_master.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
_tenant.Entry(setting).State = EntityState.Modified;
|
||||
_tenant.SaveChanges();
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
public Setting GetSetting(int settingId)
|
||||
public Setting GetSetting(string entityName, int settingId)
|
||||
{
|
||||
return _db.Setting.Find(settingId);
|
||||
if (IsMaster(entityName))
|
||||
{
|
||||
return _master.Setting.Find(settingId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _tenant.Setting.Find(settingId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSetting(int settingId)
|
||||
public void DeleteSetting(string entityName, int settingId)
|
||||
{
|
||||
Setting setting = _db.Setting.Find(settingId);
|
||||
_db.Setting.Remove(setting);
|
||||
_db.SaveChanges();
|
||||
if (IsMaster(entityName))
|
||||
{
|
||||
Setting setting = _master.Setting.Find(settingId);
|
||||
_master.Setting.Remove(setting);
|
||||
_master.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
Setting setting = _tenant.Setting.Find(settingId);
|
||||
_tenant.Setting.Remove(setting);
|
||||
_tenant.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsMaster(string EntityName)
|
||||
{
|
||||
return (EntityName == EntityNames.ModuleDefinition || EntityName == EntityNames.Host);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,6 @@ namespace Oqtane.Shared
|
|||
public const string Folder = "Folder";
|
||||
public const string User = "User";
|
||||
public const string Visitor = "Visitor";
|
||||
public const string Host = "Host";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user