This commit is contained in:
@@ -14,13 +14,13 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[ApiVersion("8.0")]
|
[ApiVersion("8.0")]
|
||||||
[Route("api/v{version:apiVersion}/form-setting")]
|
[Route("api/v{version:apiVersion}/form-user-options")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class FormSettingController : ControllerBase
|
public class FormUserOptionsController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AyContext ct;
|
private readonly AyContext ct;
|
||||||
private readonly ILogger<FormSettingController> log;
|
private readonly ILogger<FormUserOptionsController> log;
|
||||||
private readonly ApiServerState serverState;
|
private readonly ApiServerState serverState;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -29,7 +29,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <param name="dbcontext"></param>
|
/// <param name="dbcontext"></param>
|
||||||
/// <param name="logger"></param>
|
/// <param name="logger"></param>
|
||||||
/// <param name="apiServerState"></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;
|
ct = dbcontext;
|
||||||
log = logger;
|
log = logger;
|
||||||
@@ -37,40 +37,40 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create FormSetting
|
/// Create FormUserOptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newObject"></param>
|
/// <param name="newObject"></param>
|
||||||
/// <param name="apiVersion">From route path</param>
|
/// <param name="apiVersion">From route path</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> PostFormSetting([FromBody] FormSetting newObject, ApiVersion apiVersion)
|
public async Task<IActionResult> PostFormUserOptions([FromBody] FormUserOptions newObject, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
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))
|
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
FormSetting o = await biz.CreateAsync(newObject);
|
FormUserOptions o = await biz.CreateAsync(newObject);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
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>
|
/// <summary>
|
||||||
/// Get FormSetting
|
/// Get FormUserOptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="formKey"></param>
|
/// <param name="formKey"></param>
|
||||||
/// <returns>FormSetting</returns>
|
/// <returns>FormUserOptions</returns>
|
||||||
[HttpGet("{formKey}")]
|
[HttpGet("{formKey}")]
|
||||||
public async Task<IActionResult> GetFormSetting([FromRoute] string formKey)
|
public async Task<IActionResult> GetFormUserOptions([FromRoute] string formKey)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
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))
|
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
@@ -81,18 +81,18 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update FormSetting
|
/// Update FormUserOptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="updatedObject"></param>
|
/// <param name="updatedObject"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> PutFormSetting([FromBody] FormSetting updatedObject)
|
public async Task<IActionResult> PutFormUserOptions([FromBody] FormUserOptions updatedObject)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
|
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
var o = await biz.PutAsync(updatedObject);
|
var o = await biz.PutAsync(updatedObject);
|
||||||
@@ -107,18 +107,18 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete FormSetting
|
/// Delete FormUserOptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="formKey"></param>
|
/// <param name="formKey"></param>
|
||||||
/// <returns>NoContent</returns>
|
/// <returns>NoContent</returns>
|
||||||
[HttpDelete("{formKey}")]
|
[HttpDelete("{formKey}")]
|
||||||
public async Task<IActionResult> DeleteFormSetting([FromRoute] string formKey)
|
public async Task<IActionResult> DeleteFormUserOptions([FromRoute] string formKey)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
FormSettingBiz biz = FormSettingBiz.GetBiz(ct, HttpContext);
|
FormUserOptionsBiz biz = FormUserOptionsBiz.GetBiz(ct, HttpContext);
|
||||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
if (!await biz.DeleteAsync(formKey))
|
if (!await biz.DeleteAsync(formKey))
|
||||||
@@ -23,7 +23,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
NoType = 0,
|
NoType = 0,
|
||||||
Global = 1,
|
Global = 1,
|
||||||
FormSetting = 2,
|
FormUserOptions = 2,
|
||||||
[CoreBizObject,ReportableBizObject]
|
[CoreBizObject,ReportableBizObject]
|
||||||
User = 3,
|
User = 3,
|
||||||
ServerState = 4,
|
ServerState = 4,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -9,44 +9,44 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//## This class manages personal form settings for users
|
//## 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;
|
ct = dbcontext;
|
||||||
UserId = currentUserId;
|
UserId = currentUserId;
|
||||||
UserTranslationId = userTranslationId;
|
UserTranslationId = userTranslationId;
|
||||||
CurrentUserRoles = UserRoles;
|
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)
|
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
|
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
|
//EXISTS
|
||||||
internal async Task<bool> ExistsAsync(long id)
|
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
|
//CREATE
|
||||||
//
|
//
|
||||||
internal async Task<FormSetting> CreateAsync(FormSetting newObject)
|
internal async Task<FormUserOptions> CreateAsync(FormUserOptions newObject)
|
||||||
{
|
{
|
||||||
Validate(newObject, null);
|
Validate(newObject, null);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newObject.Setting = JsonUtil.CompactJson(newObject.Setting);
|
newObject.Options = JsonUtil.CompactJson(newObject.Options);
|
||||||
await ct.FormSetting.AddAsync(newObject);
|
await ct.FormUserOptions.AddAsync(newObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
return newObject;
|
return newObject;
|
||||||
}
|
}
|
||||||
@@ -57,16 +57,16 @@ namespace AyaNova.Biz
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//GET
|
//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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//UPDATE
|
//UPDATE
|
||||||
//
|
//
|
||||||
internal async Task<FormSetting> PutAsync(FormSetting putObject)
|
internal async Task<FormUserOptions> PutAsync(FormUserOptions putObject)
|
||||||
{
|
{
|
||||||
var dbObject = await GetAsync(putObject.FormKey);
|
var dbObject = await GetAsync(putObject.FormKey);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
@@ -80,7 +80,7 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
putObject.Setting = JsonUtil.CompactJson(putObject.Setting);
|
putObject.Options = JsonUtil.CompactJson(putObject.Options);
|
||||||
Validate(putObject, dbObject);
|
Validate(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
ct.Replace(dbObject, putObject);
|
ct.Replace(dbObject, putObject);
|
||||||
@@ -116,7 +116,7 @@ namespace AyaNova.Biz
|
|||||||
ValidateCanDelete(dbObject);
|
ValidateCanDelete(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.FormSetting.Remove(dbObject);
|
ct.FormUserOptions.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
return true;
|
return true;
|
||||||
@@ -129,7 +129,7 @@ namespace AyaNova.Biz
|
|||||||
//VALIDATION
|
//VALIDATION
|
||||||
//
|
//
|
||||||
|
|
||||||
private void Validate(FormSetting proposedObj, FormSetting currentObj)
|
private void Validate(FormUserOptions proposedObj, FormUserOptions currentObj)
|
||||||
{
|
{
|
||||||
if (proposedObj.UserId != UserId)
|
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)
|
if (inObj.UserId != UserId)
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace AyaNova.Models
|
|||||||
public virtual DbSet<DataListColumnView> DataListColumnView { get; set; }
|
public virtual DbSet<DataListColumnView> DataListColumnView { get; set; }
|
||||||
public virtual DbSet<Tag> Tag { get; set; }
|
public virtual DbSet<Tag> Tag { get; set; }
|
||||||
public virtual DbSet<FormCustom> FormCustom { 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<PickListTemplate> PickListTemplate { get; set; }
|
||||||
public virtual DbSet<License> License { get; set; }
|
public virtual DbSet<License> License { get; set; }
|
||||||
public virtual DbSet<Memo> Memo { get; set; }
|
public virtual DbSet<Memo> Memo { get; set; }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace AyaNova.Models
|
|||||||
## NOTE: there is only one formcustom per ayatype, the formkey is the ayatype enum name
|
## 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
|
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
|
- 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
|
- JSON FRAGMENT holds items that differ from stock, Hide not valid for non hideable core fields
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace AyaNova.Models
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class FormSetting
|
public class FormUserOptions
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public uint Concurrency { get; set; }
|
public uint Concurrency { get; set; }
|
||||||
@@ -16,7 +16,7 @@ namespace AyaNova.Models
|
|||||||
[Required, MaxLength(255)]
|
[Required, MaxLength(255)]
|
||||||
public string FormKey { get; set; }//max 255 characters ascii set
|
public string FormKey { get; set; }//max 255 characters ascii set
|
||||||
[Required]
|
[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]
|
[Required]
|
||||||
public long UserId {get;set;}
|
public long UserId {get;set;}
|
||||||
|
|
||||||
@@ -368,7 +368,7 @@ BEGIN
|
|||||||
case ayatype
|
case ayatype
|
||||||
when 0 then return 'LT:NoType';
|
when 0 then return 'LT:NoType';
|
||||||
when 1 then return 'LT:Global';
|
when 1 then return 'LT:Global';
|
||||||
when 2 then return 'FormSetting';
|
when 2 then return 'FormUserOptions';
|
||||||
when 3 then aytable = 'auser';
|
when 3 then aytable = 'auser';
|
||||||
when 4 then return 'LT:ServerState';
|
when 4 then return 'LT:ServerState';
|
||||||
when 5 then return 'LT:License';
|
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 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, "
|
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, setting TEXT NOT NULL)");
|
+ "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, "
|
await ExecQueryAsync("CREATE TABLE aformcustom (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
|
||||||
+ "formkey VARCHAR(255) NOT NULL, template TEXT, UNIQUE(formkey))");
|
+ "formkey VARCHAR(255) NOT NULL, template TEXT, UNIQUE(formkey))");
|
||||||
|
|||||||
Reference in New Issue
Block a user