From 0aad951ab1df377ecc804a2468181cf38b0e6c6a Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 20 May 2019 21:35:50 +0000 Subject: [PATCH] --- devdocs/todo.txt | 2 +- .../Controllers/AttachmentController.cs | 22 ++++++++++--------- server/AyaNova/biz/UserBiz.cs | 4 ++-- server/AyaNova/models/FileAttachment.cs | 3 +-- server/AyaNova/util/AySchema.cs | 2 +- server/AyaNova/util/FileUtil.cs | 4 +--- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 0da9e800..bf0ed288 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -22,7 +22,7 @@ Remove OwnerId - Event object uses it see eventlog above - FormCustom uses it much like DataFilter does, could also be renamed to UserId and semantically be better - UserOptions (rename to userID) - - OpsJob (might be removable?) + - OpsJob (might be removable, rename it CreatorID? Or, if it's already logged in the event log then maybe no creator ID is required at all.) OwnerID is put on httpcontext in startup.cs, will it still be necessary? Clean up owner ID and rules now that it's deprecated diff --git a/server/AyaNova/Controllers/AttachmentController.cs b/server/AyaNova/Controllers/AttachmentController.cs index 3316bda3..cd32d032 100644 --- a/server/AyaNova/Controllers/AttachmentController.cs +++ b/server/AyaNova/Controllers/AttachmentController.cs @@ -186,14 +186,16 @@ namespace AyaNova.Api.Controllers if (!badRequest) { //check if object exists - // long attachToObjectOwnerId = attachToObject.OwnerId(ct); - // if (attachToObjectOwnerId == -1) - // { - // badRequest = true; - // errorMessage = "Invalid attach object"; - // } - // else - // { + //Updated code: this used to check if the ownerId was -1 to see if it didn't exist, but since ownerId zapped this seems like the next best way to do it + //Not sure at all what the ownerid check was doing before that verified it's existance, the code is long gone now and I can't be arsed to look it up in the repo history + //If the tests pass then it's fine :) + if (!BizObjectExistsInDatabase.Exists(attachToObject)) + { + badRequest = true; + errorMessage = "Invalid attach object"; + } + else + { // User needs modify rights to the object type in question if (!Authorized.HasModifyRole(HttpContext.Items, attachToObject.ObjectType)) { @@ -202,7 +204,7 @@ namespace AyaNova.Api.Controllers return StatusCode(403, new ApiNotAuthorizedResponse()); } - //} + } } @@ -222,7 +224,7 @@ namespace AyaNova.Api.Controllers { foreach (UploadedFileInfo a in uploadFormData.UploadedFiles) { - var v = FileUtil.storeFileAttachment(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, UserId, attachToObject, ct); + var v = FileUtil.storeFileAttachment(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, attachToObject, ct); returnList.Add(new NameIdItem() { Name = v.DisplayFileName, diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 8ab41de2..b5510a04 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -62,7 +62,7 @@ namespace AyaNova.Biz inObj.Tags = TagUtil.NormalizeTags(inObj.Tags); //Seeder sets user options in advance so no need to create them here in that case if (inObj.UserOptions == null) - inObj.UserOptions = new UserOptions(UserId); + inObj.UserOptions = new UserOptions(); Validate(inObj, null); @@ -103,7 +103,7 @@ namespace AyaNova.Biz inObj.Tags = TagUtil.NormalizeTags(inObj.Tags); //Seeder sets user options in advance so no need to create them here in that case if (inObj.UserOptions == null) - inObj.UserOptions = new UserOptions(UserId); + inObj.UserOptions = new UserOptions(); Validate(inObj, null); if (HasErrors) diff --git a/server/AyaNova/models/FileAttachment.cs b/server/AyaNova/models/FileAttachment.cs index 113fbf9d..4435067f 100644 --- a/server/AyaNova/models/FileAttachment.cs +++ b/server/AyaNova/models/FileAttachment.cs @@ -10,8 +10,7 @@ namespace AyaNova.Models public long Id { get; set; } public uint ConcurrencyToken { get; set; } - [Required] - public long OwnerId { get; set; } + //----------------------------------------- [Required] public long AttachToObjectId { get; set; } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 6c783322..7350f2fb 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -228,7 +228,7 @@ namespace AyaNova.Util { LogUpdateMessage(log); - exec("CREATE TABLE afileattachment (id BIGSERIAL PRIMARY KEY, ownerid bigint not null," + + exec("CREATE TABLE afileattachment (id BIGSERIAL PRIMARY KEY, " + "attachtoobjectid bigint not null, attachtoobjecttype integer not null, " + "storedfilename text not null, displayfilename text not null, contenttype text, notes text)"); diff --git a/server/AyaNova/util/FileUtil.cs b/server/AyaNova/util/FileUtil.cs index e417c507..f696e0eb 100644 --- a/server/AyaNova/util/FileUtil.cs +++ b/server/AyaNova/util/FileUtil.cs @@ -256,11 +256,10 @@ namespace AyaNova.Util /// /// /// - /// /// /// /// - internal static FileAttachment storeFileAttachment(string tempFilePath, string contentType, string fileName, long userId, AyaTypeId attachToObject, AyContext ct) + internal static FileAttachment storeFileAttachment(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct) { //calculate hash var hash = FileHash.GetChecksum(tempFilePath); @@ -286,7 +285,6 @@ namespace AyaNova.Util //Build AyFileInfo FileAttachment fi = new FileAttachment() { - OwnerId = userId, StoredFileName = hash, DisplayFileName = fileName, Notes = string.Empty,