Skip to content

Commit af662fe

Browse files
Allowed retrieval of current user configuration when accessing user profile as a non-admin user (#18099)
* Allowed retrieval of current user configuration when accessing user profile as a non-admin user. * Update src/Umbraco.Web.UI.Client/src/packages/user/user/repository/config/current-user-config.repository.ts --------- Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 160710b commit af662fe

26 files changed

+234
-13
lines changed

src/Umbraco.Cms.Api.Management/Factories/UserPresentationFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public async Task<CurrenUserConfigurationResponseModel> CreateCurrentUserConfigu
143143
KeepUserLoggedIn = _securitySettings.KeepUserLoggedIn,
144144
UsernameIsEmail = _securitySettings.UsernameIsEmail,
145145
PasswordConfiguration = _passwordConfigurationPresentationFactory.CreatePasswordConfigurationResponseModel(),
146+
147+
// You should not be able to change any password or set 2fa if any providers has deny local login set.
148+
AllowChangePassword = _externalLoginProviders.HasDenyLocalLogin() is false,
149+
AllowTwoFactor = _externalLoginProviders.HasDenyLocalLogin() is false,
146150
};
147151

148152
return await Task.FromResult(model);

src/Umbraco.Cms.Api.Management/OpenApi.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35929,6 +35929,8 @@
3592935929
},
3593035930
"CurrenUserConfigurationResponseModel": {
3593135931
"required": [
35932+
"allowChangePassword",
35933+
"allowTwoFactor",
3593235934
"keepUserLoggedIn",
3593335935
"passwordConfiguration",
3593435936
"usernameIsEmail"
@@ -35948,6 +35950,12 @@
3594835950
"$ref": "#/components/schemas/PasswordConfigurationResponseModel"
3594935951
}
3595035952
]
35953+
},
35954+
"allowChangePassword": {
35955+
"type": "boolean"
35956+
},
35957+
"allowTwoFactor": {
35958+
"type": "boolean"
3595135959
}
3595235960
},
3595335961
"additionalProperties": false
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using Umbraco.Cms.Api.Management.ViewModels.Security;
1+
using Umbraco.Cms.Api.Management.ViewModels.Security;
22

33
namespace Umbraco.Cms.Api.Management.ViewModels.User.Current;
44

5+
// TODO (V16): Correct the spelling on this class name, it should be CurrentUserConfigurationResponseModel.
56
public class CurrenUserConfigurationResponseModel
67
{
78
public bool KeepUserLoggedIn { get; set; }
@@ -10,4 +11,8 @@ public class CurrenUserConfigurationResponseModel
1011
public bool UsernameIsEmail { get; set; }
1112

1213
public required PasswordConfigurationResponseModel PasswordConfiguration { get; set; }
14+
15+
public bool AllowChangePassword { get; set; }
16+
17+
public bool AllowTwoFactor { get; set; }
1318
}

src/Umbraco.Web.UI.Client/src/external/backend-api/src/types.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ export type CurrenUserConfigurationResponseModel = {
470470
*/
471471
usernameIsEmail: boolean;
472472
passwordConfiguration: (PasswordConfigurationResponseModel);
473+
allowChangePassword: boolean;
474+
allowTwoFactor: boolean;
473475
};
474476

475477
export type DatabaseInstallRequestModel = {

src/Umbraco.Web.UI.Client/src/packages/user/change-password/entity-action/manifests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UMB_USER_ENTITY_TYPE } from '@umbraco-cms/backoffice/user';
1+
import { UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS, UMB_USER_ENTITY_TYPE } from '@umbraco-cms/backoffice/user';
22

33
export const manifests: Array<UmbExtensionManifest> = [
44
{
@@ -18,7 +18,7 @@ export const manifests: Array<UmbExtensionManifest> = [
1818
alias: 'Umb.Condition.User.IsDefaultKind',
1919
},
2020
{
21-
alias: 'Umb.Condition.User.AllowChangePassword',
21+
alias: UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS,
2222
},
2323
],
2424
},

src/Umbraco.Web.UI.Client/src/packages/user/current-user/mfa-login/manifests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UMB_CURRENT_USER_ALLOW_MFA_CONDITION_ALIAS } from '@umbraco-cms/backoffice/user';
2+
13
export const manifests: Array<UmbExtensionManifest> = [
24
{
35
type: 'currentUserAction',
@@ -13,7 +15,7 @@ export const manifests: Array<UmbExtensionManifest> = [
1315
},
1416
conditions: [
1517
{
16-
alias: 'Umb.Condition.User.AllowMfaAction',
18+
alias: UMB_CURRENT_USER_ALLOW_MFA_CONDITION_ALIAS,
1719
},
1820
],
1921
},

src/Umbraco.Web.UI.Client/src/packages/user/current-user/profile/manifests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UMB_SECTION_USER_PERMISSION_CONDITION_ALIAS } from '@umbraco-cms/backoffice/section';
2+
import { UMB_CURRENT_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS } from '@umbraco-cms/backoffice/user';
23

34
export const manifests: Array<UmbExtensionManifest> = [
45
{
@@ -43,7 +44,7 @@ export const manifests: Array<UmbExtensionManifest> = [
4344
},
4445
conditions: [
4546
{
46-
alias: 'Umb.Condition.User.AllowChangePassword',
47+
alias: UMB_CURRENT_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS,
4748
},
4849
],
4950
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS = 'Umb.Condition.User.AllowChangePassword';
2+
export const UMB_CURRENT_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS = 'Umb.Condition.CurrentUser.AllowChangePassword';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import UmbCurrentUserConfigRepository from '../../repository/config/current-user-config.repository.js';
2+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
3+
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';
4+
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
5+
6+
export class UmbCurrentUserAllowChangePasswordActionCondition extends UmbConditionBase<UmbConditionConfigBase> {
7+
#configRepository = new UmbCurrentUserConfigRepository(this._host);
8+
9+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10+
constructor(host: UmbControllerHost, args: any) {
11+
super(host, args);
12+
this.#init();
13+
}
14+
15+
async #init() {
16+
await this.#configRepository.initialized;
17+
this.observe(
18+
this.#configRepository.part('allowChangePassword'),
19+
(isAllowed) => {
20+
this.permitted = isAllowed;
21+
},
22+
'_userAllowChangePasswordActionCondition',
23+
);
24+
}
25+
}
26+
27+
export { UmbCurrentUserAllowChangePasswordActionCondition as api };
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS } from './constants.js';
1+
import { UMB_CURRENT_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS, UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS } from './constants.js';
22

33
export const manifests: Array<UmbExtensionManifest> = [
44
{
@@ -7,4 +7,10 @@ export const manifests: Array<UmbExtensionManifest> = [
77
alias: UMB_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS,
88
api: () => import('./user-allow-change-password-action.condition.js'),
99
},
10+
{
11+
type: 'condition',
12+
name: 'Current User Allow Change Password Condition',
13+
alias: UMB_CURRENT_USER_ALLOW_CHANGE_PASSWORD_CONDITION_ALIAS,
14+
api: () => import('./current-user-allow-change-password-action.condition.js'),
15+
},
1016
];

0 commit comments

Comments
 (0)