diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index a74c80e9..e42f09a9 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -380,7 +380,7 @@ namespace AyaNova // ******************** TESTING WIPE DB ***************************** // //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) //TESTING diff --git a/server/AyaNova/biz/DataFilterBiz.cs b/server/AyaNova/biz/DataFilterBiz.cs index c915d669..84a8579d 100644 --- a/server/AyaNova/biz/DataFilterBiz.cs +++ b/server/AyaNova/biz/DataFilterBiz.cs @@ -160,8 +160,12 @@ namespace AyaNova.Biz //put 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 - CopyObject.Copy(inObj, dbObj, "Id,Serial"); + CopyObject.Copy(inObj, dbObj, "Id"); //Set "original" value of concurrency token to input token //this will allow EF to check it out ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken; @@ -278,7 +282,7 @@ namespace AyaNova.Biz } if (filterItem["value"] == null) 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) diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs index 5bbf3549..aed73259 100644 --- a/server/AyaNova/biz/TagBiz.cs +++ b/server/AyaNova/biz/TagBiz.cs @@ -170,6 +170,10 @@ namespace AyaNova.Biz //put 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 inObj.Name = CleanTagName(inObj.Name); diff --git a/server/AyaNova/biz/TagGroupBiz.cs b/server/AyaNova/biz/TagGroupBiz.cs index e0092ce6..c545705e 100644 --- a/server/AyaNova/biz/TagGroupBiz.cs +++ b/server/AyaNova/biz/TagGroupBiz.cs @@ -187,6 +187,10 @@ namespace AyaNova.Biz //put 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 inObj.Name = CleanTagGroupName(inObj.Name); diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 8df75b45..248871fa 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -220,6 +220,10 @@ namespace AyaNova.Biz //put 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 User SnapshotObj = new User(); CopyObject.Copy(dbObj, SnapshotObj); diff --git a/server/AyaNova/biz/UserOptionsBiz.cs b/server/AyaNova/biz/UserOptionsBiz.cs index 8d8ecc3b..aba81d95 100644 --- a/server/AyaNova/biz/UserOptionsBiz.cs +++ b/server/AyaNova/biz/UserOptionsBiz.cs @@ -45,7 +45,10 @@ namespace AyaNova.Biz //put 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 CopyObject.Copy(inObj, dbObj, "Id, UserId, OwnerId"); //Set "original" value of concurrency token to input token diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index 403c35c4..097f6fdf 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -33,7 +33,7 @@ namespace AyaNova.Biz } } - + internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) { ct = dbcontext; @@ -227,6 +227,9 @@ namespace AyaNova.Biz //put 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 CopyObject.Copy(inObj, dbObj, "Id,Serial"); diff --git a/test/raven-integration/DataFilter/DataFilterCrud.cs b/test/raven-integration/DataFilter/DataFilterCrud.cs index de0b7256..ed335b1a 100644 --- a/test/raven-integration/DataFilter/DataFilterCrud.cs +++ b/test/raven-integration/DataFilter/DataFilterCrud.cs @@ -20,7 +20,7 @@ namespace raven_integration //CREATE dynamic d = new JObject(); d.name = Util.Uniquify("Test DataFilter"); - // d.ownerId = 1L; + // d.ownerId = 1L; d["public"] = true; d.listKey = "Widget"; @@ -32,45 +32,34 @@ namespace raven_integration df.value = "Generic";//lots of seed widgets start with Generic 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()); Util.ValidateDataReturnResponseOk(a); long Id = a.ObjectResponse["data"]["id"].Value(); - string Name = a.ObjectResponse["data"]["name"].Value(); - Name.Should().StartWith("Test DataFilter"); - // // //RETRIEVE - // // /* - // // { - // // "data": { - // // "id": 24, - // // "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().Should().StartWith("testtag"); + //RETRIEVE + //Get one + a = await Util.GetAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateDataReturnResponseOk(a); + a.ObjectResponse["data"]["name"].Value().Should().StartWith("Test DataFilter"); - // // //UPDATE - - // // //PUT - // // d.Id = tagId; - // // d.name = Util.Uniquify("PutTestTag"); - // // d.created = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture); - // // d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value(); - // // d.OwnerId = 1L; + //Get as alternate user should work for public filter + a = await Util.GetAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited")); + Util.ValidateDataReturnResponseOk(a); + a.ObjectResponse["data"]["name"].Value().Should().StartWith("Test DataFilter"); - // // ApiResponse PUTTestResponse = await Util.PutAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString()); - // // Util.ValidateHTTPStatusCode(PUTTestResponse, 200); + //UPDATE + + //PUT, make private + d["public"] = false; + d.name = Util.Uniquify("Put - Test DataFilter (privatized)"); + d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value(); + ApiResponse PUTTestResponse = await Util.PutAsync("DataFilter/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString()); + Util.ValidateHTTPStatusCode(PUTTestResponse, 200); // // //check PUT worked // // ApiResponse checkPUTWorked = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));