This commit is contained in:
2021-09-22 17:23:05 +00:00
parent f912ba547a
commit 8512819a2d
8 changed files with 47 additions and 47 deletions

View File

@@ -14,13 +14,13 @@ namespace AyaNova.Api.Controllers
{
[ApiController]
[ApiVersion("8.0")]
[Route("api/v{version:apiVersion}/form-setting")]
[Route("api/v{version:apiVersion}/form-user-options")]
[Produces("application/json")]
[Authorize]
public class FormSettingController : ControllerBase
public class FormUserOptionsController : ControllerBase
{
private readonly AyContext ct;
private readonly ILogger<FormSettingController> log;
private readonly ILogger<FormUserOptionsController> log;
private readonly ApiServerState serverState;
/// <summary>
@@ -29,7 +29,7 @@ namespace AyaNova.Api.Controllers
/// <param name="dbcontext"></param>
/// <param name="logger"></param>
/// <param name="apiServerState"></param>
public FormSettingController(AyContext dbcontext, ILogger<FormSettingController> logger, ApiServerState apiServerState)
public FormUserOptionsController(AyContext dbcontext, ILogger<FormUserOptionsController> logger, ApiServerState apiServerState)
{
ct = dbcontext;
log = logger;
@@ -37,40 +37,40 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Create FormSetting
/// Create FormUserOptions
/// </summary>
/// <param name="newObject"></param>
/// <param name="apiVersion">From route path</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> PostFormSetting([FromBody] FormSetting newObject, ApiVersion apiVersion)
public async Task<IActionResult> PostFormUserOptions([FromBody] FormUserOptions newObject, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
FormSetting o = await biz.CreateAsync(newObject);
FormUserOptions o = await biz.CreateAsync(newObject);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction(nameof(FormSettingController.GetFormSetting), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
return CreatedAtAction(nameof(FormUserOptionsController.GetFormUserOptions), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}
/// <summary>
/// Get FormSetting
/// Get FormUserOptions
/// </summary>
/// <param name="formKey"></param>
/// <returns>FormSetting</returns>
/// <returns>FormUserOptions</returns>
[HttpGet("{formKey}")]
public async Task<IActionResult> GetFormSetting([FromRoute] string formKey)
public async Task<IActionResult> GetFormUserOptions([FromRoute] string formKey)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
@@ -81,18 +81,18 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Update FormSetting
/// Update FormUserOptions
/// </summary>
/// <param name="updatedObject"></param>
/// <returns></returns>
[HttpPut]
public async Task<IActionResult> PutFormSetting([FromBody] FormSetting updatedObject)
public async Task<IActionResult> PutFormUserOptions([FromBody] FormUserOptions updatedObject)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
var o = await biz.PutAsync(updatedObject);
@@ -107,18 +107,18 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Delete FormSetting
/// Delete FormUserOptions
/// </summary>
/// <param name="formKey"></param>
/// <returns>NoContent</returns>
[HttpDelete("{formKey}")]
public async Task<IActionResult> DeleteFormSetting([FromRoute] string formKey)
public async Task<IActionResult> DeleteFormUserOptions([FromRoute] string formKey)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!await biz.DeleteAsync(formKey))

View File

@@ -23,7 +23,7 @@ namespace AyaNova.Biz
NoType = 0,
Global = 1,
FormSetting = 2,
FormUserOptions = 2,
[CoreBizObject,ReportableBizObject]
User = 3,
ServerState = 4,

File diff suppressed because one or more lines are too long

View File

@@ -9,44 +9,44 @@ namespace AyaNova.Biz
//## This class manages personal form settings for users
internal class FormSettingBiz : BizObject
internal class FormUserOptionsBiz : BizObject
{
internal FormSettingBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
internal FormUserOptionsBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
{
ct = dbcontext;
UserId = currentUserId;
UserTranslationId = userTranslationId;
CurrentUserRoles = UserRoles;
BizType = AyaType.FormSetting;
BizType = AyaType.FormUserOptions;
}
internal static FormSettingBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
internal static FormUserOptionsBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
{
if (httpContext != null)
return new FormSettingBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
return new FormUserOptionsBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
else
return new FormSettingBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdmin);
return new FormUserOptionsBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdmin);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//EXISTS
internal async Task<bool> ExistsAsync(long id)
{
return await ct.FormSetting.AnyAsync(z => z.Id == id);
return await ct.FormUserOptions.AnyAsync(z => z.Id == id);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
//
internal async Task<FormSetting> CreateAsync(FormSetting newObject)
internal async Task<FormUserOptions> CreateAsync(FormUserOptions newObject)
{
Validate(newObject, null);
if (HasErrors)
return null;
else
{
newObject.Setting = JsonUtil.CompactJson(newObject.Setting);
await ct.FormSetting.AddAsync(newObject);
newObject.Options = JsonUtil.CompactJson(newObject.Options);
await ct.FormUserOptions.AddAsync(newObject);
await ct.SaveChangesAsync();
return newObject;
}
@@ -57,16 +57,16 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//GET
//
internal async Task<FormSetting> GetAsync(string formKey)
internal async Task<FormUserOptions> GetAsync(string formKey)
{
var ret = await ct.FormSetting.AsNoTracking().SingleOrDefaultAsync(m => m.FormKey == formKey && m.UserId == UserId);
var ret = await ct.FormUserOptions.AsNoTracking().SingleOrDefaultAsync(m => m.FormKey == formKey && m.UserId == UserId);
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE
//
internal async Task<FormSetting> PutAsync(FormSetting putObject)
internal async Task<FormUserOptions> PutAsync(FormUserOptions putObject)
{
var dbObject = await GetAsync(putObject.FormKey);
if (dbObject == null)
@@ -80,7 +80,7 @@ namespace AyaNova.Biz
return null;
}
putObject.Setting = JsonUtil.CompactJson(putObject.Setting);
putObject.Options = JsonUtil.CompactJson(putObject.Options);
Validate(putObject, dbObject);
if (HasErrors) return null;
ct.Replace(dbObject, putObject);
@@ -116,7 +116,7 @@ namespace AyaNova.Biz
ValidateCanDelete(dbObject);
if (HasErrors)
return false;
ct.FormSetting.Remove(dbObject);
ct.FormUserOptions.Remove(dbObject);
await ct.SaveChangesAsync();
await transaction.CommitAsync();
return true;
@@ -129,7 +129,7 @@ namespace AyaNova.Biz
//VALIDATION
//
private void Validate(FormSetting proposedObj, FormSetting currentObj)
private void Validate(FormUserOptions proposedObj, FormUserOptions currentObj)
{
if (proposedObj.UserId != UserId)
{
@@ -137,7 +137,7 @@ namespace AyaNova.Biz
}
}
private void ValidateCanDelete(FormSetting inObj)
private void ValidateCanDelete(FormUserOptions inObj)
{
if (inObj.UserId != UserId)
{

View File

@@ -25,7 +25,7 @@ namespace AyaNova.Models
public virtual DbSet<DataListColumnView> DataListColumnView { get; set; }
public virtual DbSet<Tag> Tag { get; set; }
public virtual DbSet<FormCustom> FormCustom { get; set; }
public virtual DbSet<FormSetting> FormSetting { get; set; }
public virtual DbSet<FormUserOptions> FormUserOptions { get; set; }
public virtual DbSet<PickListTemplate> PickListTemplate { get; set; }
public virtual DbSet<License> License { get; set; }
public virtual DbSet<Memo> Memo { get; set; }

View File

@@ -7,7 +7,7 @@ namespace AyaNova.Models
## NOTE: there is only one formcustom per ayatype, the formkey is the ayatype enum name
This is a *GLOBAL* setting that applies to ALL users
for personal form settings (such as used by schedule form) see FormSetting.cs
for personal form settings (such as used by schedule form) see FormUserOptions.cs
- Like DataFilter, holds a JSON fragment in one field and the form key in another field
- JSON FRAGMENT holds items that differ from stock, Hide not valid for non hideable core fields

View File

@@ -8,7 +8,7 @@ namespace AyaNova.Models
*/
public class FormSetting
public class FormUserOptions
{
public long Id { get; set; }
public uint Concurrency { get; set; }
@@ -16,7 +16,7 @@ namespace AyaNova.Models
[Required, MaxLength(255)]
public string FormKey { get; set; }//max 255 characters ascii set
[Required]
public string Setting { get; set; }//JSON fragment of form customization template, top level is array.
public string Options { get; set; }//JSON fragment of form customization template, top level is array.
[Required]
public long UserId {get;set;}

View File

@@ -368,7 +368,7 @@ BEGIN
case ayatype
when 0 then return 'LT:NoType';
when 1 then return 'LT:Global';
when 2 then return 'FormSetting';
when 2 then return 'FormUserOptions';
when 3 then aytable = 'auser';
when 4 then return 'LT:ServerState';
when 5 then return 'LT:License';
@@ -517,8 +517,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
await ExecQueryAsync("CREATE TABLE atag (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, refcount BIGINT NOT NULL)");
await ExecQueryAsync("CREATE TABLE aformsetting (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "userid BIGINT NOT NULL REFERENCES auser ON DELETE CASCADE, formkey VARCHAR(255) NOT NULL, setting TEXT NOT NULL)");
await ExecQueryAsync("CREATE TABLE aformuseroptions (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "userid BIGINT NOT NULL REFERENCES auser ON DELETE CASCADE, formkey VARCHAR(255) NOT NULL, options TEXT NOT NULL)");
await ExecQueryAsync("CREATE TABLE aformcustom (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "formkey VARCHAR(255) NOT NULL, template TEXT, UNIQUE(formkey))");