private IEnumerable <ManagedRole> UpdateRoles(IManagedUser user, RoleList roles, ICollection <IEntity> entities) { using (Profiler.Measure("PlatformService.UpdateRoles:user")) { if (user == null) { throw new ArgumentNullException("user"); } var ids = roles == null?Enumerable.Empty <string>() : roles.Select(r => r.RemoteId.ToString()); var removeRoles = roles != null?user.Roles.Where(r => !ids.Contains(r.RemoteId)) : Enumerable.Empty <ManagedRole>(); user.Roles.RemoveRange(removeRoles); if (roles == null) { return(Enumerable.Empty <ManagedRole>()); } var updatedEntities = roles.Where(r => r.RemoteId > 0).Select(r => UpdateRole(null, r, entities)).ToList(); entities.AddRange(updatedEntities); return(updatedEntities); } }
private IEnumerable <ManagedRole> UpdateRoles(IManagedTenant tenant, RoleList roles, ICollection <IEntity> entities) { using (Profiler.Measure("PlatformService.UpdateRoles:tenant")) { if (tenant == null) { throw new ArgumentNullException("tenant"); } var ids = roles == null?Enumerable.Empty <string>() : roles.Select(r => r.RemoteId.ToString()); CastEntityHelper.Delete(tenant.Roles.Where(r => !ids.Contains(r.RemoteId)).Select(t => new EntityRef(t.Id))); if (roles == null) { return(Enumerable.Empty <ManagedRole>()); } var updatedEntities = roles.Where(r => r.RemoteId > 0).Select(r => UpdateRole(tenant, r, entities)).ToList(); entities.AddRange(updatedEntities); return(updatedEntities); } }
public override void Persist() { Contact cnt = contact.SelectSingle(); cnt = (Contact)contact.Cache.CreateCopy(cnt); if (UserList.Current != null) { UserList.Current.IsAssigned = cnt != null; foreach (Contact existing in PXSelect <Contact, Where <Contact.userID, Equal <Current <Users.pKID> > > > .Select(this)) { existing.UserID = null; contact.Update(existing); } if (cnt != null) { cnt.UserID = UserList.Current.PKID; contact.Update(cnt); } } foreach (Users user in UserList.Cache.Deleted) { cnt = (Contact)contact.View.SelectSingleBound(new object[] { user }); if (cnt != null) { cnt.UserID = null; contact.Update(cnt); } } if (UserList.Current != null && UserList.Current.OverrideADRoles != true && UserList.Current.Source == PXUsersSourceListAttribute.ActiveDirectory) { foreach (UsersInRoles userrole in RoleList.Select()) { RoleList.Delete(userrole); } } base.Persist(); }
public override void Persist() { foreach (Users user in UserList.Cache.Deleted) { Contact cnt = (Contact)contact.View.SelectSingleBound(new object[] { user }); if (cnt != null) { cnt.UserID = null; contact.Update(cnt); EPEmployee emp = Employee.Select(cnt.ContactID); if (emp != null) { emp = PXCache <EPEmployee> .CreateCopy(emp); emp.UserID = null; Employee.Update(emp); } } } if (UserList.Current != null && UserList.Current.OverrideADRoles != true && UserList.Current.Source == PXUsersSourceListAttribute.ActiveDirectory) { //notice that this select returns nothing if called on AccessUsers. AccessUsers::roleList() returns empty list; foreach (UsersInRoles userrole in RoleList.Select()) { RoleList.Delete(userrole); } } //if no local roles selected - disable override. if (UserList.Current != null && UserList.Current.OverrideADRoles == true && UserList.Current.Source == PXUsersSourceListAttribute.ActiveDirectory) { if (RolesByUser.SelectSingle() == null) { UserListCurrent.Current.OverrideADRoles = false; } } base.Persist(); }
public override void Persist() { Contact cnt = contact.SelectSingle(); EPEmployee currentEmployee = (cnt != null) ? Employee.Select(cnt.ContactID) : null; cnt = (Contact)contact.Cache.CreateCopy(cnt); if (UserList.Current != null) { UserList.Current.IsAssigned = cnt != null; foreach (Contact existing in PXSelect <Contact, Where <Contact.userID, Equal <Current <Users.pKID> > > > .Select(this)) { existing.UserID = null; contact.Update(existing); EPEmployee emp = Employee.Select(existing.ContactID); if (emp != null) { emp = PXCache <EPEmployee> .CreateCopy(emp); emp.UserID = null; Employee.Update(emp); } } if (cnt != null) { cnt.UserID = UserList.Current.PKID; contact.Update(cnt); if (currentEmployee != null) { currentEmployee = PXCache <EPEmployee> .CreateCopy(currentEmployee); currentEmployee.UserID = UserList.Current.PKID; Employee.Update(currentEmployee); } } } foreach (Users user in UserList.Cache.Deleted) { cnt = (Contact)contact.View.SelectSingleBound(new object[] { user }); if (cnt != null) { cnt.UserID = null; contact.Update(cnt); EPEmployee emp = Employee.Select(cnt.ContactID); if (emp != null) { emp = PXCache <EPEmployee> .CreateCopy(emp); emp.UserID = null; Employee.Update(emp); } } } if (UserList.Current != null && UserList.Current.OverrideADRoles != true && UserList.Current.Source == PXUsersSourceListAttribute.ActiveDirectory) { //notice that this select returns nothing if called on AccessUsers. AccessUsers::roleList() returns empty list; foreach (UsersInRoles userrole in RoleList.Select()) { RoleList.Delete(userrole); } } //if no local roles selected - disable override. if (UserList.Current != null && UserList.Current.OverrideADRoles == true && UserList.Current.Source == PXUsersSourceListAttribute.ActiveDirectory) { if (RolesByUser.SelectSingle() == null) { UserListCurrent.Current.OverrideADRoles = false; } } base.Persist(); }
/// <summary> /// 获取某个资源角色的数据权限列表 /// </summary> /// <param name="resourceId"></param> /// <param name="roles"></param> /// <returns></returns> private static DataPermissionList CollectDataPermissions(long resourceId, RoleList roles) { return(RepositoryFacade.ResolveInstance <DataPermissionRepository>() .GetDataPermissionList(resourceId, roles.Select(p => p.Id).Cast <long>().ToList())); }