cloudscribe / cloudscribe.SimpleContent

A simple, yet flexible content and blog engine for ASP.NET Core that can work with or without a database, supports markdown or html editing
https://www.cloudscribe.com/docs/cloudscribe-simplecontent
Apache License 2.0
334 stars 65 forks source link

When a role name is changed, this breaks any page settings view roles #582

Closed CrispinF closed 11 months ago

CrispinF commented 1 year ago

If a page has been set to be visible to role "test1" and the role is then renamed to "test2", the page settings remain unchanged and users in the renamed role lose access to the page.

JimKerslake commented 1 year ago

I'm adding event handlers: IHandleRoleDeleted: Task Handle(ISiteRole role);

IHandleRoleUpdated Task Handle(ISiteRole role, string oldRoleName);

Noting that the ISiteRole should carry with it the Guid siteId and also its new name

JimKerslake commented 1 year ago

cloudscribe.Core.Models 6.0.4 cloudscribe.Core.Web 6.0.37 cloudscribe.Core.Identity 6.0.8

JimKerslake commented 1 year ago

This is a bit harder than it seems because if an admin user edits the name of a role that they themselves are in, and if there is a restriction on the page to use that role name, then they would expect to still be able to view that page (the role name that they are in has changed, but so too has the restriction on the page). In practice the page vanishes from the navigation until after the user logs out & back in again (or an app restart) because of the caching of both user claims and the nav tree. This is confusing and I've made some efforts to try and refresh the claims and nav caching when this happens - but it still isn't perfect.

Need also to consider deletion of a role - that presumably must just remove the role restriction on all pages that referred to it? (or rather remove that reference from inside a potential csv of rolenames).

JimKerslake commented 1 year ago

cloudscribe.Core.SimpleContent 6.0.3

JimKerslake commented 1 year ago

Very belatedly I now realise that cloudscribe core has an interface called IGuardNeededRoles whose job is to prevent the editing or deletion of roles that need to be 'protected' (eg if they are referenced by Auth Policies) so it would have been possible to use that to prevent the renaming of any roles that are referenced by pages - that would have been more consistent, but also more inflexible than allowing the re-name and updating the pages to match.

CrispinF commented 11 months ago

Tested OK.