diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs
index 1a523835c8..c3dcf846dd 100644
--- a/src/Umbraco.Core/Services/UserService.cs
+++ b/src/Umbraco.Core/Services/UserService.cs
@@ -672,6 +672,27 @@ namespace Umbraco.Core.Services
uow.Commit();
}
}
+
+ ///
+ /// Add a specific section to all users
+ ///
+ /// This is useful when a new section is created to allow all users accessing it
+ /// Alias of the section to add
+ public void AddSectionToAllUsers(string sectionAlias)
+ {
+ var uow = _uowProvider.GetUnitOfWork();
+ using (var repository = _repositoryFactory.CreateUserRepository(uow))
+ {
+ var allUsers = repository.GetAll();
+ foreach (var user in allUsers.Where(u => !u.AllowedSections.Contains(sectionAlias)))
+ {
+ //now add the section for each user and commit
+ user.AddAllowedSection(sectionAlias);
+ repository.AddOrUpdate(user);
+ }
+ uow.Commit();
+ }
+ }
///
/// Get permissions set for a user and optional node ids
@@ -745,4 +766,4 @@ namespace Umbraco.Core.Services
///
public static event TypedEventHandler> DeletedUserType;
}
-}
\ No newline at end of file
+}