ISectionService how to access in V16?

In UmbCheckout I am using the ISectionService to check whether a section has been registered prior to adding to a usergroup as part of a migration.

var umbCheckoutSection = _sectionService.GetByAlias(Consts.Sections.SectionAlias);
if (umbCheckoutSection != null)
{
userGroup.AddAllowedSection(Consts.Sections.SectionAlias);
}

How can I do this in V16 now that the service has been removed?

Have done something similar with the Sustainability package, I think this is what you’re after?

var adminGroup = await _userGroupService.GetAsync(Cms.Core.Constants.Security.AdminGroupAlias);

if (adminGroup != null)
{
    if (!adminGroup.AllowedSections.Contains(Constants.SectionAlias))
    {
        adminGroup.AddAllowedSection(Constants.SectionAlias);
        await _userGroupService.UpdateAsync(adminGroup, Cms.Core.Constants.Security.SuperUserKey);
    }
}
1 Like

That could work, I will give it a try and report back soon!

Many thanks :slight_smile:

Isn’t this slightly different, in that you are adding a know existing section.. your package section to the allowed sections.. and not checking that the section exists.. potentially from another package?

Though I guess it highlights a possible path, make sure you’ve added access to all the sections for the admin group.. or a migrationGroup and then allowedSections can be used as the section discovery?

I might change the migration to check if the group exists or not rather than if the section is registered.

I guess as sections are registered in the UI now, the C# wouldn’t know about them

I think so too, hardcoding it works for now, but yeah, I also couldn’t find any interface like we had in v13 (like ISection or ISectionService). I don’t know how they do it in UIBuilder :man_shrugging: there should be a way for c# to register it? as its done there.

(post deleted by author)