From 415584f4cf907892b9f43cb43f71a29d449ee9f6 Mon Sep 17 00:00:00 2001 From: EngincanV Date: Thu, 4 Feb 2021 10:23:55 +0300 Subject: [PATCH] Change AbpAuthorizationException as BusinessException --- .../Organizations/OrganizationAppService.cs | 6 +++--- src/EventHub.Domain.Shared/EventHubErrorCodes.cs | 1 + .../Localization/EventHub/en.json | 3 ++- .../Pages/Organizations/Edit.cshtml.cs | 14 ++------------ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/EventHub.Application/Organizations/OrganizationAppService.cs b/src/EventHub.Application/Organizations/OrganizationAppService.cs index 100bba2..f447d95 100644 --- a/src/EventHub.Application/Organizations/OrganizationAppService.cs +++ b/src/EventHub.Application/Organizations/OrganizationAppService.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using EventHub.Permissions; using Microsoft.AspNetCore.Authorization; +using Volo.Abp; using Volo.Abp.Application.Dtos; -using Volo.Abp.Authorization; using Volo.Abp.Domain.Repositories; using Volo.Abp.Users; @@ -82,7 +81,8 @@ namespace EventHub.Organizations if (organization.OwnerUserId != CurrentUser.GetId()) { - throw new AbpAuthorizationException(); + throw new BusinessException(EventHubErrorCodes.NotAuthorizedToUpdateOrganizationProfile) + .WithData("OrganizationName", organization.DisplayName); } organization.SetDisplayName(input.DisplayName); diff --git a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs index 7923307..3d1603a 100644 --- a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs +++ b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs @@ -6,5 +6,6 @@ public const string NotAuthorizedToCreateEventInThisOrganization = "EventHub:NotAuthorizedToCreateEventInThisOrganization"; public const string EventEndTimeCantBeEarlierThanStartTime = "EventHub:EventEndTimeCantBeEarlierThanStartTime"; public const string CantRegisterOrUnregisterForAPastEvent = "EventHub:CantRegisterOrUnregisterForAPastEvent"; + public const string NotAuthorizedToUpdateOrganizationProfile = "EventHub:NotAuthorizedToUpdateOrganizationProfile"; } } diff --git a/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/src/EventHub.Domain.Shared/Localization/EventHub/en.json index 4477cf9..25f2ca7 100644 --- a/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -46,6 +46,7 @@ "Edit": "Edit", "EditOrganization": "Edit Organization", "PersonalWebsite": "Personal Website", - "SocialMedia": "Social Media" + "SocialMedia": "Social Media", + "EventHub:NotAuthorizedToUpdateOrganizationProfile": "You are not authorized to update the \"{OrganizationName}\" organization." } } diff --git a/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs index 0bb0b9c..a91a454 100644 --- a/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs +++ b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs @@ -23,19 +23,9 @@ namespace EventHub.Web.Pages.Organizations _organizationAppService = organizationAppService; } - public async Task OnGetAsync() + public async Task OnGetAsync() { - try - { - await GetOrganizationAsync(); - } - catch (Exception exception) - { - ShowAlert(exception); - return RedirectToPage("./Index"); - } - - return Page(); + await GetOrganizationAsync(); } public async Task OnPostAsync()