Fixes BulkInsertRecords to not require a trans , removes inner trans from PermissionRepository, fixes up events in PermissionRepository and MemberGroupRepository, fixes up uow in UserService
This commit is contained in:
@@ -183,16 +183,31 @@ namespace Umbraco.Core.Persistence
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="collection"></param>
|
||||
[Obsolete("Use the method that specifies an SqlSyntaxContext instance instead")]
|
||||
public static void BulkInsertRecords<T>(this Database db, IEnumerable<T> collection)
|
||||
{
|
||||
//don't do anything if there are no records.
|
||||
if (collection.Any() == false)
|
||||
return;
|
||||
db.BulkInsertRecords(collection, null, SqlSyntaxContext.SqlSyntaxProvider, true, false);
|
||||
}
|
||||
|
||||
using (var tr = db.GetTransaction())
|
||||
{
|
||||
db.BulkInsertRecords(collection, tr, SqlSyntaxContext.SqlSyntaxProvider, true, true); // use native, commit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the bulk insertion
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="collection"></param>
|
||||
/// <param name="syntaxProvider"></param>
|
||||
/// <param name="useNativeSqlPlatformBulkInsert">
|
||||
/// If this is false this will try to just generate bulk insert statements instead of using the current SQL platform's bulk
|
||||
/// insert logic. For SQLCE, bulk insert statements do not work so if this is false it will insert one at a time.
|
||||
/// </param>
|
||||
/// <returns>The number of items inserted</returns>
|
||||
public static int BulkInsertRecords<T>(this Database db,
|
||||
IEnumerable<T> collection,
|
||||
ISqlSyntaxProvider syntaxProvider,
|
||||
bool useNativeSqlPlatformBulkInsert = true)
|
||||
{
|
||||
return BulkInsertRecords<T>(db, collection, null, syntaxProvider, useNativeSqlPlatformBulkInsert, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -267,6 +282,7 @@ namespace Umbraco.Core.Persistence
|
||||
|
||||
if (commitTrans)
|
||||
{
|
||||
if (tr == null) throw new ArgumentNullException("The transaction cannot be null if commitTrans is true");
|
||||
tr.Complete();
|
||||
}
|
||||
return processed;
|
||||
@@ -275,6 +291,7 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
if (commitTrans)
|
||||
{
|
||||
if (tr == null) throw new ArgumentNullException("The transaction cannot be null if commitTrans is true");
|
||||
tr.Dispose();
|
||||
}
|
||||
throw;
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
PersistNewItem(m);
|
||||
}
|
||||
SavedMemberGroup.RaiseEvent(new SaveEventArgs<IMemberGroup>(missingGroups), this);
|
||||
SavedMemberGroup.RaiseEvent(new SaveEventArgs<IMemberGroup>(missingGroups), this, UnitOfWork.EventManager);
|
||||
|
||||
//now go get all the dto's for roles with these role names
|
||||
var rolesForNames = Database.Fetch<NodeDto>(existingSql).ToArray();
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class PermissionRepository<TEntity>
|
||||
where TEntity : class, IAggregateRoot
|
||||
{
|
||||
private readonly IDatabaseUnitOfWork _unitOfWork;
|
||||
private readonly IScopeUnitOfWork _unitOfWork;
|
||||
private readonly IRuntimeCacheProvider _runtimeCache;
|
||||
private readonly ISqlSyntaxProvider _sqlSyntax;
|
||||
|
||||
internal PermissionRepository(IDatabaseUnitOfWork unitOfWork, CacheHelper cache, ISqlSyntaxProvider sqlSyntax)
|
||||
internal PermissionRepository(IScopeUnitOfWork unitOfWork, CacheHelper cache, ISqlSyntaxProvider sqlSyntax)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
//Make this repository use an isolated cache
|
||||
@@ -126,37 +126,33 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public void ReplaceUserPermissions(int userId, IEnumerable<char> permissions, params int[] entityIds)
|
||||
{
|
||||
var db = _unitOfWork.Database;
|
||||
using (var trans = db.GetTransaction())
|
||||
|
||||
//we need to batch these in groups of 2000 so we don't exceed the max 2100 limit
|
||||
foreach (var idGroup in entityIds.InGroupsOf(2000))
|
||||
{
|
||||
//we need to batch these in groups of 2000 so we don't exceed the max 2100 limit
|
||||
foreach (var idGroup in entityIds.InGroupsOf(2000))
|
||||
{
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE userId=@userId AND nodeId in (@nodeIds)",
|
||||
new { userId = userId, nodeIds = idGroup });
|
||||
}
|
||||
|
||||
var toInsert = new List<User2NodePermissionDto>();
|
||||
foreach (var p in permissions)
|
||||
{
|
||||
foreach (var e in entityIds)
|
||||
{
|
||||
toInsert.Add(new User2NodePermissionDto
|
||||
{
|
||||
NodeId = e,
|
||||
Permission = p.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_unitOfWork.Database.BulkInsertRecords(toInsert, trans);
|
||||
|
||||
trans.Complete();
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(toInsert), false), this);
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE userId=@userId AND nodeId in (@nodeIds)",
|
||||
new { userId = userId, nodeIds = idGroup });
|
||||
}
|
||||
|
||||
var toInsert = new List<User2NodePermissionDto>();
|
||||
foreach (var p in permissions)
|
||||
{
|
||||
foreach (var e in entityIds)
|
||||
{
|
||||
toInsert.Add(new User2NodePermissionDto
|
||||
{
|
||||
NodeId = e,
|
||||
Permission = p.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_unitOfWork.Database.BulkInsertRecords(toInsert, _sqlSyntax);
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(toInsert), false), this, _unitOfWork.EventManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,31 +164,26 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public void AssignUserPermission(int userId, char permission, params int[] entityIds)
|
||||
{
|
||||
var db = _unitOfWork.Database;
|
||||
using (var trans = db.GetTransaction())
|
||||
{
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE userId=@userId AND permission=@permission AND nodeId in (@entityIds)",
|
||||
new
|
||||
{
|
||||
userId = userId,
|
||||
permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
entityIds = entityIds
|
||||
});
|
||||
|
||||
var actions = entityIds.Select(id => new User2NodePermissionDto
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE userId=@userId AND permission=@permission AND nodeId in (@entityIds)",
|
||||
new
|
||||
{
|
||||
NodeId = id,
|
||||
Permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = userId
|
||||
}).ToArray();
|
||||
userId = userId,
|
||||
permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
entityIds = entityIds
|
||||
});
|
||||
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, trans);
|
||||
var actions = entityIds.Select(id => new User2NodePermissionDto
|
||||
{
|
||||
NodeId = id,
|
||||
Permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = userId
|
||||
}).ToArray();
|
||||
|
||||
trans.Complete();
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax);
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this, _unitOfWork.EventManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -204,31 +195,26 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public void AssignEntityPermission(TEntity entity, char permission, IEnumerable<int> userIds)
|
||||
{
|
||||
var db = _unitOfWork.Database;
|
||||
using (var trans = db.GetTransaction())
|
||||
{
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId AND permission=@permission AND userId in (@userIds)",
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId AND permission=@permission AND userId in (@userIds)",
|
||||
new
|
||||
{
|
||||
nodeId = entity.Id,
|
||||
nodeId = entity.Id,
|
||||
permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
userIds = userIds
|
||||
});
|
||||
|
||||
var actions = userIds.Select(id => new User2NodePermissionDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
Permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = id
|
||||
}).ToArray();
|
||||
var actions = userIds.Select(id => new User2NodePermissionDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
Permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
UserId = id
|
||||
}).ToArray();
|
||||
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, trans);
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax);
|
||||
|
||||
trans.Complete();
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this, _unitOfWork.EventManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,25 +228,20 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public void ReplaceEntityPermissions(EntityPermissionSet permissionSet)
|
||||
{
|
||||
var db = _unitOfWork.Database;
|
||||
using (var trans = db.GetTransaction())
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId", new { nodeId = permissionSet.EntityId });
|
||||
|
||||
var actions = permissionSet.UserPermissionsSet.Select(p => new User2NodePermissionDto
|
||||
{
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId", new { nodeId = permissionSet.EntityId });
|
||||
NodeId = permissionSet.EntityId,
|
||||
Permission = p.Permission,
|
||||
UserId = p.UserId
|
||||
}).ToArray();
|
||||
|
||||
var actions = permissionSet.UserPermissionsSet.Select(p => new User2NodePermissionDto
|
||||
{
|
||||
NodeId = permissionSet.EntityId,
|
||||
Permission = p.Permission,
|
||||
UserId = p.UserId
|
||||
}).ToArray();
|
||||
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, trans);
|
||||
|
||||
trans.Complete();
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
_unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax);
|
||||
|
||||
//Raise the event
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this, _unitOfWork.EventManager);
|
||||
}
|
||||
|
||||
private static IEnumerable<EntityPermission> ConvertToPermissionList(IEnumerable<User2NodePermissionDto> result)
|
||||
|
||||
@@ -107,10 +107,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="permissionSet"></param>
|
||||
public void ReplaceContentPermissions(EntityPermissionSet permissionSet)
|
||||
{
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
repository.ReplaceContentPermissions(permissionSet);
|
||||
uow.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +123,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userIds"></param>
|
||||
public void AssignContentPermission(IContent entity, char permission, IEnumerable<int> userIds)
|
||||
{
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
repository.AssignEntityPermission(entity, permission, userIds);
|
||||
uow.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Alias of the default MemberType</returns>
|
||||
public string GetDefaultMemberType()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var types = repository.GetAll().Select(x => x.Alias).ToArray();
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><c>True</c> if the User exists otherwise <c>False</c></returns>
|
||||
public bool Exists(string username)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
return repository.Exists(username);
|
||||
}
|
||||
@@ -152,12 +152,15 @@ namespace Umbraco.Core.Services
|
||||
user.AddAllowedSection("media");
|
||||
|
||||
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(user), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return user;
|
||||
}
|
||||
|
||||
repository.AddOrUpdate(user);
|
||||
uow.Commit();
|
||||
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(user, false), this);
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(user, false), this ,uow.EventManager);
|
||||
|
||||
return user;
|
||||
}
|
||||
@@ -170,7 +173,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var user = repository.Get((int)id);
|
||||
|
||||
@@ -201,7 +204,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetByEmail(string email)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUser>.Builder.Where(x => x.Email.Equals(email));
|
||||
var user = repository.GetByQuery(query).FirstOrDefault();
|
||||
@@ -217,7 +220,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetByUsername(string username)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUser>.Builder.Where(x => x.Username.Equals(username));
|
||||
var user = repository.GetByQuery(query).FirstOrDefault();
|
||||
@@ -288,12 +291,16 @@ namespace Umbraco.Core.Services
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
if (DeletingUser.IsRaisedEventCancelled(new DeleteEventArgs<IUser>(user), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return;
|
||||
}
|
||||
repository.Delete(user);
|
||||
uow.Commit();
|
||||
DeletedUser.RaiseEvent(new DeleteEventArgs<IUser>(user, false), this, uow.EventManager);
|
||||
|
||||
}
|
||||
|
||||
DeletedUser.RaiseEvent(new DeleteEventArgs<IUser>(user, false), this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,12 +318,18 @@ namespace Umbraco.Core.Services
|
||||
if (raiseEvents)
|
||||
{
|
||||
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entity), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
repository.AddOrUpdate(entity);
|
||||
try
|
||||
{
|
||||
uow.Commit();
|
||||
|
||||
if (raiseEvents)
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(entity, false), this, uow.EventManager);
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
@@ -328,8 +341,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(entity, false), this);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -340,24 +352,30 @@ namespace Umbraco.Core.Services
|
||||
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
|
||||
public void Save(IEnumerable<IUser> entities, bool raiseEvents = true)
|
||||
{
|
||||
var asArray = entities.ToArray();
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
if (raiseEvents)
|
||||
{
|
||||
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entities), this, uow.EventManager))
|
||||
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(asArray), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (var member in entities)
|
||||
foreach (var member in asArray)
|
||||
{
|
||||
repository.AddOrUpdate(member);
|
||||
}
|
||||
//commit the whole lot in one go
|
||||
uow.Commit();
|
||||
|
||||
if (raiseEvents)
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(asArray, false), this, uow.EventManager);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(entities, false), this);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -371,7 +389,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IUser}"/></returns>
|
||||
public IEnumerable<IUser> FindByEmail(string emailStringToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
var query = new Query<IUser>();
|
||||
@@ -412,7 +430,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IUser}"/></returns>
|
||||
public IEnumerable<IUser> FindByUsername(string login, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
var query = new Query<IUser>();
|
||||
@@ -454,7 +472,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="System.int"/> with number of Users for passed in type</returns>
|
||||
public int GetCount(MemberCountType countType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
IQuery<IUser> query;
|
||||
|
||||
@@ -497,7 +515,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IUser> GetAll(int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
return repository.GetPagedResultsByQuery(null, pageIndex, pageSize, out totalRecords, member => member.Username);
|
||||
@@ -506,7 +524,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
internal IEnumerable<IUser> GetNextUsers(int id, int count)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = (UserRepository) RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
return repository.GetNextUsers(id, count);
|
||||
@@ -546,7 +564,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetUserById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
return repository.Get(id);
|
||||
}
|
||||
@@ -565,6 +583,7 @@ namespace Umbraco.Core.Services
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
repository.ReplaceUserPermissions(userId, permissions, entityIds);
|
||||
uow.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,6 +599,8 @@ namespace Umbraco.Core.Services
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
repository.AssignUserPermission(userId, permission, entityIds);
|
||||
uow.Commit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,7 +611,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUserType"/></returns>
|
||||
public IEnumerable<IUserType> GetAllUserTypes(params int[] ids)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
|
||||
{
|
||||
return repository.GetAll(ids);
|
||||
@@ -604,7 +625,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeByAlias(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUserType>.Builder.Where(x => x.Alias == alias);
|
||||
var contents = repository.GetByQuery(query);
|
||||
@@ -619,7 +640,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
return repository.Get(id);
|
||||
}
|
||||
@@ -632,7 +653,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetReadOnlyUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUserType>.Builder.Where(x => x.Name == name);
|
||||
var contents = repository.GetByQuery(query);
|
||||
@@ -654,14 +675,18 @@ namespace Umbraco.Core.Services
|
||||
if (raiseEvents)
|
||||
{
|
||||
if (SavingUserType.IsRaisedEventCancelled(new SaveEventArgs<IUserType>(userType), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
repository.AddOrUpdate(userType);
|
||||
uow.Commit();
|
||||
if (raiseEvents)
|
||||
SavedUserType.RaiseEvent(new SaveEventArgs<IUserType>(userType, false), this, uow.EventManager);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
SavedUserType.RaiseEvent(new SaveEventArgs<IUserType>(userType, false), this);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -674,12 +699,16 @@ namespace Umbraco.Core.Services
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
|
||||
{
|
||||
if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs<IUserType>(userType), this, uow.EventManager))
|
||||
{
|
||||
uow.Commit();
|
||||
return;
|
||||
}
|
||||
repository.Delete(userType);
|
||||
uow.Commit();
|
||||
DeletedUserType.RaiseEvent(new DeleteEventArgs<IUserType>(userType, false), this, uow.EventManager);
|
||||
|
||||
}
|
||||
|
||||
DeletedUserType.RaiseEvent(new DeleteEventArgs<IUserType>(userType, false), this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -700,6 +729,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdate(user);
|
||||
}
|
||||
uow.Commit();
|
||||
//TODO: Events?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,13 +753,14 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
users = repository.GetAll();
|
||||
}
|
||||
foreach (var user in users.Where(u => !u.AllowedSections.InvariantContains(sectionAlias)))
|
||||
foreach (var user in users.Where(u => u.AllowedSections.InvariantContains(sectionAlias) == false))
|
||||
{
|
||||
//now add the section for each user and commit
|
||||
user.AddAllowedSection(sectionAlias);
|
||||
repository.AddOrUpdate(user);
|
||||
}
|
||||
uow.Commit();
|
||||
//TODO: Events?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,7 +773,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
public IEnumerable<EntityPermission> GetPermissions(IUser user, params int[] nodeIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var uow = UowProvider.GetReadOnlyUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
{
|
||||
var explicitPermissions = repository.GetUserPermissionsForEntities(user.Id, nodeIds);
|
||||
|
||||
Reference in New Issue
Block a user