private void EntityTests() { Debug.WriteLine("==== START ENTITY TESTS===="); var entityManager = new EntityManager(); InputEntity inputEntity = new InputEntity(); //entity.Id = new Guid("C5050AC8-5967-4CE1-95E7-A79B054F9D14"); inputEntity.Id = Guid.NewGuid(); inputEntity.Name = "goro_test"; inputEntity.Label = "Goro Test"; inputEntity.LabelPlural = "Goro Tests"; inputEntity.System = true; List<Guid> allowedRoles = new List<Guid>(); allowedRoles.Add(new Guid("F42EBA3B-6433-752B-6C34-B322A7B4CE7D")); inputEntity.RecordPermissions = new RecordPermissions(); inputEntity.RecordPermissions.CanRead = allowedRoles; inputEntity.RecordPermissions.CanCreate = allowedRoles; inputEntity.RecordPermissions.CanUpdate = allowedRoles; inputEntity.RecordPermissions.CanDelete = allowedRoles; try { Entity entity = inputEntity.MapTo<Entity>(); EntityResponse response = entityManager.CreateEntity(inputEntity); InputTextField field = new InputTextField(); field.Id = Guid.NewGuid(); field.Name = "text_field"; field.Label = "Text field"; field.PlaceholderText = "Text field placeholder text"; field.Description = "Text field description"; field.HelpText = "Text field help text"; field.Required = true; field.Unique = true; field.Searchable = true; field.Auditable = true; field.System = true; field.DefaultValue = ""; field.MaxLength = 200; FieldResponse fieldResponse = entityManager.CreateField(entity.Id, field, false); //inputEntity.Label = "GoroTest_edited"; //inputEntity.PluralLabel = "Goro Tests - edited"; //Expando obj = new Expando(); //obj["Label"] = "GoroTest_edited"; //obj["PluralLabel"] = "Goro Tests - edited"; //response = entityManager.PartialUpdateEntity(entity.Id.Value, obj); //field.Label = "TextField_edited"; InputField fieldObj = new InputTextField(); fieldObj.Label = "TextField_edited"; //fieldResponse = entityManager.PartialUpdateField(entity.Id, field.Id.Value, fieldObj); //fieldResponse = entityManager.DeleteField(entity.Id.Value, field.Id.Value); //List<Field> fields = CreateTestFieldCollection(entity); ////FieldResponse fieldResponse = entityManager.CreateField(entity.Id.Value, fields[0]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[1]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[2]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[3]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[4]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[5]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[6]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[7]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[8]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[9]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[10]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[11]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[12]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[13]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[14]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[15]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[16]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[17]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[18]); //fieldResponse = entityManager.CreateField(entity.Id.Value, fields[19]); //EntityResponse entityResponse = entityManager.ReadEntity(entity.Id.Value); //entity = entityResponse.Object; //List<RecordsList> recordsLists = CreateTestViewCollection(entity); //RecordsListResponse recordsListsResponse = entityManager.CreateRecordsList(entity.Id.Value, recordsLists[0]); //recordsLists[0].Label = "Edited View"; //recordsListsResponse = entityManager.UpdateRecordsList(entity.Id.Value, recordsLists[0]); //List<RecordView> recordViewList = CreateTestFormCollection(entity); //RecordViewResponse recordViewResponse = entityManager.CreateRecordView(entity.Id.Value, recordViewList[0]); //recordViewList[0].Label = "Edited Form"; //recordViewResponse = entityManager.CreateRecordView(entity.Id.Value, recordViewList[0]); EntityListResponse entityListResponse = entityManager.ReadEntities(); EntityResponse resultEntity = entityManager.ReadEntity(entity.Id); response = entityManager.DeleteEntity(entity.Id); } catch (StorageException e) { Debug.WriteLine(e); } Debug.WriteLine("==== END ENTITY TESTS===="); }
internal static object GetCurrentUserPermissions(HttpContext context) { if (context == null) throw new NullReferenceException("context"); ErpUser user = null; if (context.User != null && context.User is ErpPrincipal) { var identity = (context.User as ErpPrincipal).Identity as ErpIdentity; if (identity != null) user = identity.User; } EntityManager entMan = new EntityManager(); var entities = entMan.ReadEntities().Object; List<object> permissions = new List<object>(); foreach (var entity in entities) { bool canRead = false; bool canCreate = false; bool canUpdate = false; bool canDelete = false; if (user != null) { canRead = user.Roles.Any(x => entity.RecordPermissions.CanRead.Any(z => z == x.Id)); canCreate = user.Roles.Any(x => entity.RecordPermissions.CanCreate.Any(z => z == x.Id)); canUpdate = user.Roles.Any(x => entity.RecordPermissions.CanUpdate.Any(z => z == x.Id)); canDelete = user.Roles.Any(x => entity.RecordPermissions.CanDelete.Any(z => z == x.Id)); } else { canRead = entity.RecordPermissions.CanRead.Any(z => z == SystemIds.GuestRoleId); canCreate = entity.RecordPermissions.CanCreate.Any(z => z == SystemIds.GuestRoleId); canUpdate = entity.RecordPermissions.CanUpdate.Any(z => z == SystemIds.GuestRoleId); canDelete = entity.RecordPermissions.CanDelete.Any(z => z == SystemIds.GuestRoleId); } if (canRead || canCreate || canUpdate || canDelete) permissions.Add(new { entityId = entity.Id, entityName = entity.Name, canRead = canRead, canCreate = canCreate, canUpdate = canUpdate, canDelete = canDelete }); } return permissions; }