This commit is contained in:
2023-04-20 00:31:49 +00:00
parent b301b907b3
commit 99c0505a06
3 changed files with 68 additions and 54 deletions

View File

@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
@@ -7,7 +8,7 @@ using Microsoft.Extensions.Logging;
using Sockeye.Models;
using Sockeye.Api.ControllerHelpers;
using Sockeye.Biz;
using System.Linq;
namespace Sockeye.Api.Controllers
{
@@ -102,39 +103,43 @@ namespace Sockeye.Api.Controllers
// /// <summary>
// /// Get the top level ancestor of provided type and id
// /// (e.g. find the WorkOrder principle for a WorkOrderItemPart object descendant)
// /// </summary>
// /// <param name="sockType"></param>
// /// <param name="id"></param>
// /// <returns>A type and id of ancestor</returns>
// [HttpGet("ancestor/{sockType}/{id}")]
// public async Task<IActionResult> GetAncestor([FromRoute] SockType sockType, [FromRoute] long id)
// {
// if (serverState.IsClosed)
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
/// <summary>
/// Get the top level ancestor of provided type and id
/// (e.g. find the WorkOrder principle for a WorkOrderItemPart object descendant)
/// </summary>
/// <param name="sockType"></param>
/// <param name="id"></param>
/// <returns>A type and id of ancestor</returns>
[HttpGet("ancestor/{sockType}/{id}")]
public async Task<IActionResult> GetAncestor([FromRoute] SockType sockType, [FromRoute] long id)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
// //since this is for opening an entire object it's appropriate to check if they have any role first
// if (!Authorized.HasAnyRole(HttpContext.Items, sockType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
//since this is for opening an entire object it's appropriate to check if they have any role first
if (!Authorized.HasAnyRole(HttpContext.Items, sockType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!ModelState.IsValid)
// return BadRequest(new ApiErrorResponse(ModelState));
// if (id == 0)
// return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "id can't be zero"));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (id == 0)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "id can't be zero"));
// switch (sockType)
// {
switch (sockType)
{
case SockType.SubscriptionItem:
{
var subId = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == id).Select(z => z.SubscriptionId).SingleOrDefaultAsync();
return Ok(ApiOkResponse.Response(new { SockType = (int)SockType.Subscription, Id = subId }));
}
default:
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
// default:
// return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
}
// }
// }
}

View File

@@ -17,8 +17,8 @@ LEFT JOIN acustomer ON (asubscription.customerid = acustomer.id)";
var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
DefaultColumns = new List<string>() { "PurchaseExpireDate", "Product", "SubSite", "Customer", "active" };
DefaultSortBy = new Dictionary<string, string>() { { "PurchaseExpireDate", "-" } };
DefaultColumns = new List<string>() { "PurchaseExpireDate", "Product", "Customer", "active" };
DefaultSortBy = new Dictionary<string, string>() { { "PurchaseExpireDate", "+" } };
FieldDefinitions = new List<DataListFieldDefinition>();
@@ -40,17 +40,19 @@ LEFT JOIN acustomer ON (asubscription.customerid = acustomer.id)";
FieldKey = "OriginalOrderDate",
SockType = (int)SockType.SubscriptionItem,
UiFieldDataType = (int)UiFieldDataType.DateTime,
SqlValueColumnName = "asubscriptionitem.originalorderdate",
SqlIdColumnName = "asubscriptionitem.id",
IsRowId = true
SqlValueColumnName = "asubscriptionitem.originalorderdate",
SqlIdColumnName = "asubscriptionitem.id"
});
FieldDefinitions.Add(new DataListFieldDefinition
{
TKey = "PurchaseExpireDate",
FieldKey = "PurchaseExpireDate",
SockType = (int)SockType.SubscriptionItem,
UiFieldDataType = (int)UiFieldDataType.DateTime,
SqlValueColumnName = "asubscriptionitem.expiredate"
SqlValueColumnName = "asubscriptionitem.expiredate",
SqlIdColumnName = "asubscriptionitem.id",
IsRowId = true
});
//SUBSCRIPTION
@@ -82,13 +84,7 @@ LEFT JOIN acustomer ON (asubscription.customerid = acustomer.id)";
SqlValueColumnName = "asubscriptionitem.active"
});
FieldDefinitions.Add(new DataListFieldDefinition
{
TKey = "Tags",
FieldKey = "tags",
UiFieldDataType = (int)UiFieldDataType.Tags,
SqlValueColumnName = "asubscription.tags"
});
//META column
FieldDefinitions.Add(new DataListFieldDefinition

View File

@@ -650,7 +650,7 @@ namespace Sockeye.Biz
});
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//SUBSCRIPTION
//
roles.Add(SockType.Subscription, new BizRoleSet()
@@ -667,6 +667,19 @@ namespace Sockeye.Biz
Select = AuthorizationRoles.All
});
roles.Add(SockType.SubscriptionItem, new BizRoleSet()
{
Change = AuthorizationRoles.BizAdmin
| AuthorizationRoles.Service
| AuthorizationRoles.Sales
| AuthorizationRoles.Accounting,
ReadFullRecord = AuthorizationRoles.BizAdminRestricted
| AuthorizationRoles.ServiceRestricted
| AuthorizationRoles.Tech
| AuthorizationRoles.SalesRestricted
,
Select = AuthorizationRoles.All
});
////////////////////////////////////////////////////////////////////
#endregion all roles init
@@ -683,22 +696,22 @@ namespace Sockeye.Biz
//And seperately, set the JSON variable so can copy from debug variable "value" property for lastRoles here to compare
/*
/*
string json = Newtonsoft.Json.JsonConvert.SerializeObject(roles, Newtonsoft.Json.Formatting.None);
System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", "BizRoles.cs -> biz-role-rights.js Client roles JSON fragment:\n\n");
System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", json + "\n\n");
var lastRoles = "{\"Customer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNote\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNotifySubscription\":{\"Change\":10,\"ReadFullRecord\":65797,\"Select\":131071},\"HeadOffice\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Global\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"GlobalOps\":{\"Change\":16384,\"ReadFullRecord\":8192,\"Select\":0},\"User\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071,\"Select\":0},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576,\"Select\":0},\"Backup\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"FileAttachment\":{\"Change\":2,\"ReadFullRecord\":3,\"Select\":0},\"ServerJob\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"OpsNotificationSettings\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"ServerMetrics\":{\"Change\":16384,\"ReadFullRecord\":24576,\"Select\":0},\"Translation\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"DataListSavedFilter\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"FormUserOptions\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"PickListTemplate\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"BizMetrics\":{\"Change\":2,\"ReadFullRecord\":98369,\"Select\":0},\"Notification\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"NotifySubscription\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"Report\":{\"Change\":3,\"ReadFullRecord\":131071,\"Select\":131071},\"Memo\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Reminder\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Review\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Integration\":{\"Change\":49514,\"ReadFullRecord\":49514,\"Select\":49514},\"License\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"TrialLicenseRequest\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"SubscriptionServer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Purchase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Product\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"GZCase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071}}";
Dictionary<SockType, BizRoleSet> lastRolesDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<SockType, BizRoleSet>>(lastRoles);
if (lastRolesDeserialized.Count != roles.Count)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(roles, Newtonsoft.Json.Formatting.None);
System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", "BizRoles.cs -> biz-role-rights.js Client roles JSON fragment:\n\n");
System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", json + "\n\n");
var lastRoles = "{\"Customer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNote\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNotifySubscription\":{\"Change\":10,\"ReadFullRecord\":65797,\"Select\":131071},\"HeadOffice\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Global\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"GlobalOps\":{\"Change\":16384,\"ReadFullRecord\":8192,\"Select\":0},\"User\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071,\"Select\":0},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576,\"Select\":0},\"Backup\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"FileAttachment\":{\"Change\":2,\"ReadFullRecord\":3,\"Select\":0},\"ServerJob\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"OpsNotificationSettings\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"ServerMetrics\":{\"Change\":16384,\"ReadFullRecord\":24576,\"Select\":0},\"Translation\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"DataListSavedFilter\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"FormUserOptions\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"PickListTemplate\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"BizMetrics\":{\"Change\":2,\"ReadFullRecord\":98369,\"Select\":0},\"Notification\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"NotifySubscription\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"Report\":{\"Change\":3,\"ReadFullRecord\":131071,\"Select\":131071},\"Memo\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Reminder\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Review\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Integration\":{\"Change\":49514,\"ReadFullRecord\":49514,\"Select\":49514},\"Vendor\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"License\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"TrialLicenseRequest\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"SubscriptionServer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Purchase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"VendorNotification\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Product\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"GZCase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Subscription\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"SubscriptionItem\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071}}";
Dictionary<SockType, BizRoleSet> lastRolesDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<SockType, BizRoleSet>>(lastRoles);
if (lastRolesDeserialized.Count != roles.Count)
{
{
((ILogger)Sockeye.Util.ApplicationLogging.CreateLogger("BizRoles.cs")).LogWarning("BizRoles::Constructor - roles were modified from last snapshot for client!!!");
}
}
*/
{
((ILogger)Sockeye.Util.ApplicationLogging.CreateLogger("BizRoles.cs")).LogWarning("BizRoles::Constructor - roles were modified from last snapshot for client!!!");
}
}
*/
#endif
#endregion