From 92b4f8cf14851f86966ca77fa6a65e918120fc3e Mon Sep 17 00:00:00 2001 From: Vladimir Buravlev Date: Thu, 24 Oct 2024 09:20:37 +0200 Subject: [PATCH] VM-1483: short message model and forbid --- .../Models/MessageShort.cs | 3 ++- .../SendMessage/SendMessageCommandHandler.cs | 4 ++-- .../Controllers/Api/VcmpMessageController.cs | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/VirtoCommerce.MarketplaceCommunicationModule.Core/Models/MessageShort.cs b/src/VirtoCommerce.MarketplaceCommunicationModule.Core/Models/MessageShort.cs index 4f23da2..dcefbcb 100644 --- a/src/VirtoCommerce.MarketplaceCommunicationModule.Core/Models/MessageShort.cs +++ b/src/VirtoCommerce.MarketplaceCommunicationModule.Core/Models/MessageShort.cs @@ -3,7 +3,8 @@ public class MessageShort { public string SenderId { get; set; } public string RecipientId { get; set; } - public string ProductId { get; set; } + public string EntityId { get; set; } + public string EntityType { get; set; } public string Content { get; set; } public string ReplyTo { get; set; } diff --git a/src/VirtoCommerce.MarketplaceCommunicationModule.Data/Commands/SendMessage/SendMessageCommandHandler.cs b/src/VirtoCommerce.MarketplaceCommunicationModule.Data/Commands/SendMessage/SendMessageCommandHandler.cs index ad867ab..c2fa50a 100644 --- a/src/VirtoCommerce.MarketplaceCommunicationModule.Data/Commands/SendMessage/SendMessageCommandHandler.cs +++ b/src/VirtoCommerce.MarketplaceCommunicationModule.Data/Commands/SendMessage/SendMessageCommandHandler.cs @@ -39,9 +39,9 @@ public virtual async Task Handle(SendMessageCommand request, CancellationT var message = AbstractTypeFactory.TryCreateInstance(); message.SenderId = request.Message.SenderId ?? (await GetOrCreateCommunicationUserForSeller(request.SellerId)).Id; message.Content = request.Message.Content; - message.EntityId = request.Message.ProductId; + message.EntityId = request.Message.EntityId; + message.EntityId = request.Message.EntityType; message.ThreadId = request.Message.ReplyTo; - message.EntityType = CoreModuleConstants.EntityType.Product; var messageRecipient = AbstractTypeFactory.TryCreateInstance(); messageRecipient.RecipientId = request.Message.RecipientId; diff --git a/src/VirtoCommerce.MarketplaceCommunicationModule.Web/Controllers/Api/VcmpMessageController.cs b/src/VirtoCommerce.MarketplaceCommunicationModule.Web/Controllers/Api/VcmpMessageController.cs index 1d5af43..b0bbe86 100644 --- a/src/VirtoCommerce.MarketplaceCommunicationModule.Web/Controllers/Api/VcmpMessageController.cs +++ b/src/VirtoCommerce.MarketplaceCommunicationModule.Web/Controllers/Api/VcmpMessageController.cs @@ -32,7 +32,7 @@ public async Task> Search([FromBody] SearchMes var authorizationResult = await _authorizationService.AuthorizeAsync(User, query, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Read)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(query); @@ -46,7 +46,7 @@ public async Task SendMessage([FromBody] SendMessageCommand comman var authorizationResult = await _authorizationService.AuthorizeAsync(User, command, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Send)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(command); @@ -60,7 +60,7 @@ public async Task UpdateMessage([FromBody] UpdateMessageCommand co var authorizationResult = await _authorizationService.AuthorizeAsync(User, command, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Edit)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(command); @@ -74,7 +74,7 @@ public async Task DeleteMessage([FromBody] DeleteMessageCommand co var authorizationResult = await _authorizationService.AuthorizeAsync(User, command, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Delete)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(command); @@ -88,7 +88,7 @@ public async Task MarkMessageAsRead([FromBody] MarkMessageAsReadCo var authorizationResult = await _authorizationService.AuthorizeAsync(User, command, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Read)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(command); @@ -102,7 +102,7 @@ public async Task SendReaction([FromBody] SendReactionCommand comm var authorizationResult = await _authorizationService.AuthorizeAsync(User, command, new SellerAuthorizationRequirement(Core.ModuleConstants.Security.Permissions.Read)); if (!authorizationResult.Succeeded) { - return Unauthorized(); + return Forbid(); } var result = await _mediator.Send(command);