Skip to content

Commit 114ab93

Browse files
bergmaniaZeegaan
andauthored
Moved endpoint to new controller to avoid issue with too hard access requirements (#11264)
* Fixed #11258 Moved endpoint and obsoleted the old one to avoid breaking changes.. The issue is the auth policies cannot be overridden.. You need all of them, and the controller requires you to have access to member types * Update src/Umbraco.Web.BackOffice/Controllers/MemberTypeQueryController.cs Co-authored-by: Nikolaj Geisle <[email protected]> Co-authored-by: Nikolaj Geisle <[email protected]>
1 parent d311cc3 commit 114ab93

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ internal async Task<Dictionary<string, object>> GetServerVariablesAsync()
279279
"memberTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MemberTypeController>(
280280
controller => controller.GetAllTypes())
281281
},
282+
{
283+
"memberTypeQueryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MemberTypeQueryController>(
284+
controller => controller.GetAllTypes())
285+
},
282286
{
283287
"memberGroupApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MemberGroupController>(
284288
controller => controller.GetAllGroups())

src/Umbraco.Web.BackOffice/Controllers/MemberTypeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public MemberTypeDisplay GetEmpty()
182182
/// <summary>
183183
/// Returns all member types
184184
/// </summary>
185+
[Obsolete("Use MemberTypeQueryController.GetAllTypes instead as it only requires AuthorizationPolicies.TreeAccessMembersOrMemberTypes and not both this and AuthorizationPolicies.TreeAccessMemberTypes")]
185186
[Authorize(Policy = AuthorizationPolicies.TreeAccessMembersOrMemberTypes)]
186187
public IEnumerable<ContentTypeBasic> GetAllTypes()
187188
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Microsoft.AspNetCore.Authorization;
5+
using Umbraco.Cms.Core.Mapping;
6+
using Umbraco.Cms.Core.Models;
7+
using Umbraco.Cms.Core.Models.ContentEditing;
8+
using Umbraco.Cms.Core.Services;
9+
using Umbraco.Cms.Web.Common.Attributes;
10+
using Umbraco.Cms.Web.Common.Authorization;
11+
using Constants = Umbraco.Cms.Core.Constants;
12+
13+
namespace Umbraco.Cms.Web.BackOffice.Controllers
14+
{
15+
/// <summary>
16+
/// An API controller used for dealing with member types
17+
/// </summary>
18+
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
19+
[Authorize(Policy = AuthorizationPolicies.TreeAccessMembersOrMemberTypes)]
20+
public class MemberTypeQueryController : BackOfficeNotificationsController
21+
{
22+
private readonly IMemberTypeService _memberTypeService;
23+
private readonly IUmbracoMapper _umbracoMapper;
24+
25+
26+
public MemberTypeQueryController(
27+
IMemberTypeService memberTypeService,
28+
IUmbracoMapper umbracoMapper)
29+
{
30+
_memberTypeService = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService));
31+
_umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
32+
}
33+
34+
/// <summary>
35+
/// Returns all member types
36+
/// </summary>
37+
public IEnumerable<ContentTypeBasic> GetAllTypes() =>
38+
_memberTypeService.GetAll()
39+
.Select(_umbracoMapper.Map<IMemberType, ContentTypeBasic>);
40+
41+
}
42+
}

src/Umbraco.Web.UI.Client/src/common/resources/membertype.resource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ function memberTypeResource($q, $http, umbRequestHelper, umbDataFormatter, local
4646
return umbRequestHelper.resourcePromise(
4747
$http.get(
4848
umbRequestHelper.getApiUrl(
49-
"memberTypeApiBaseUrl",
49+
"memberTypeQueryApiBaseUrl",
5050
"GetAllTypes")),
5151
'Failed to retrieve data for member types id');
52-
},
52+
},
5353

5454
getById: function (id) {
5555

0 commit comments

Comments
 (0)