This commit is contained in:
2018-11-30 18:22:20 +00:00
parent 2a16580ddc
commit c3647d6fc1
8 changed files with 46 additions and 35 deletions

View File

@@ -380,7 +380,7 @@ namespace AyaNova
// ******************** TESTING WIPE DB ***************************** // ******************** TESTING WIPE DB *****************************
// //
//Set this to true to wipe the db and reinstall a trial license and re-seed the data //Set this to true to wipe the db and reinstall a trial license and re-seed the data
var TESTING_REFRESH_DB = true;//############################################################################################# var TESTING_REFRESH_DB = false;//#############################################################################################
#if (DEBUG) #if (DEBUG)
//TESTING //TESTING

View File

@@ -160,8 +160,12 @@ namespace AyaNova.Biz
//put //put
internal bool Put(DataFilter dbObj, DataFilter inObj) internal bool Put(DataFilter dbObj, DataFilter inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Replace the db object with the PUT object //Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id,Serial"); CopyObject.Copy(inObj, dbObj, "Id");
//Set "original" value of concurrency token to input token //Set "original" value of concurrency token to input token
//this will allow EF to check it out //this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken; ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
@@ -278,7 +282,7 @@ namespace AyaNova.Biz
} }
if (filterItem["value"] == null) if (filterItem["value"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"value\" property "); AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"value\" property ");
//NOTE: value of nothing, null or empty is a valid value so no checking for it here //NOTE: value of nothing, null or empty is a valid value so no checking for it here
} }
} }
catch (Newtonsoft.Json.JsonReaderException ex) catch (Newtonsoft.Json.JsonReaderException ex)

View File

@@ -170,6 +170,10 @@ namespace AyaNova.Biz
//put //put
internal bool Put(Tag dbObj, Tag inObj) internal bool Put(Tag dbObj, Tag inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Ensure it follows the rules //Ensure it follows the rules
inObj.Name = CleanTagName(inObj.Name); inObj.Name = CleanTagName(inObj.Name);

View File

@@ -187,6 +187,10 @@ namespace AyaNova.Biz
//put //put
internal bool Put(TagGroup dbObj, TagGroup inObj) internal bool Put(TagGroup dbObj, TagGroup inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Ensure it follows the rules //Ensure it follows the rules
inObj.Name = CleanTagGroupName(inObj.Name); inObj.Name = CleanTagGroupName(inObj.Name);

View File

@@ -220,6 +220,10 @@ namespace AyaNova.Biz
//put //put
internal bool Put(User dbObj, User inObj) internal bool Put(User dbObj, User inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Get a snapshot of the original db value object before changes //Get a snapshot of the original db value object before changes
User SnapshotObj = new User(); User SnapshotObj = new User();
CopyObject.Copy(dbObj, SnapshotObj); CopyObject.Copy(dbObj, SnapshotObj);

View File

@@ -45,7 +45,10 @@ namespace AyaNova.Biz
//put //put
internal bool Put(UserOptions dbObj, UserOptions inObj) internal bool Put(UserOptions dbObj, UserOptions inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Replace the db object with the PUT object //Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id, UserId, OwnerId"); CopyObject.Copy(inObj, dbObj, "Id, UserId, OwnerId");
//Set "original" value of concurrency token to input token //Set "original" value of concurrency token to input token

View File

@@ -33,7 +33,7 @@ namespace AyaNova.Biz
} }
} }
internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
{ {
ct = dbcontext; ct = dbcontext;
@@ -227,6 +227,9 @@ namespace AyaNova.Biz
//put //put
internal bool Put(Widget dbObj, Widget inObj) internal bool Put(Widget dbObj, Widget inObj)
{ {
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Replace the db object with the PUT object //Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id,Serial"); CopyObject.Copy(inObj, dbObj, "Id,Serial");

View File

@@ -20,7 +20,7 @@ namespace raven_integration
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("Test DataFilter"); d.name = Util.Uniquify("Test DataFilter");
// d.ownerId = 1L; // d.ownerId = 1L;
d["public"] = true; d["public"] = true;
d.listKey = "Widget"; d.listKey = "Widget";
@@ -32,45 +32,34 @@ namespace raven_integration
df.value = "Generic";//lots of seed widgets start with Generic df.value = "Generic";//lots of seed widgets start with Generic
dfilter.Add(df); dfilter.Add(df);
d.filter=dfilter.ToString();//it expects it to be a json string, not actual json d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
ApiResponse a = await Util.PostAsync("DataFilter", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); ApiResponse a = await Util.PostAsync("DataFilter", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long Id = a.ObjectResponse["data"]["id"].Value<long>(); long Id = a.ObjectResponse["data"]["id"].Value<long>();
string Name = a.ObjectResponse["data"]["name"].Value<string>();
Name.Should().StartWith("Test DataFilter");
// // //RETRIEVE //RETRIEVE
// // /* //Get one
// // { a = await Util.GetAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
// // "data": { Util.ValidateDataReturnResponseOk(a);
// // "id": 24, a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataFilter");
// // "created": "2018-03-28T21:07:41.9703503Z",
// // "concurrencyToken": 9502,
// // "ownerId": 1,
// // "name": "یونی‌کُد چیست؟"
// // }
// // }
// // */
// // //Get one
// // a = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
// // Util.ValidateDataReturnResponseOk(a);
// // a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("testtag");
// // //UPDATE //Get as alternate user should work for public filter
a = await Util.GetAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
// // //PUT Util.ValidateDataReturnResponseOk(a);
// // d.Id = tagId; a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataFilter");
// // d.name = Util.Uniquify("PutTestTag");
// // d.created = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
// // d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
// // d.OwnerId = 1L;
// // ApiResponse PUTTestResponse = await Util.PutAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString()); //UPDATE
// // Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//PUT, make private
d["public"] = false;
d.name = Util.Uniquify("Put - Test DataFilter (privatized)");
d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
ApiResponse PUTTestResponse = await Util.PutAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
// // //check PUT worked // // //check PUT worked
// // ApiResponse checkPUTWorked = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull")); // // ApiResponse checkPUTWorked = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));