public void UpdateUser(UserWithPermissionsContract contract) { ParamIs.NotNull(() => contract); UpdateEntity <User>(contract.Id, (session, user) => { if (!EntryPermissionManager.CanEditUser(PermissionContext, user.GroupId)) { var loggedUser = GetLoggedUser(session); var msg = string.Format("{0} (level {1}) not allowed to edit {2}", loggedUser, loggedUser.GroupId, user); log.Error(msg); throw new NotAllowedException(msg); } if (EntryPermissionManager.CanEditGroupTo(PermissionContext, contract.GroupId)) { user.GroupId = contract.GroupId; } if (EntryPermissionManager.CanEditAdditionalPermissions(PermissionContext)) { user.AdditionalPermissions = new PermissionCollection(contract.AdditionalPermissions.Select(p => PermissionToken.GetById(p.Id))); } var diff = OwnedArtistForUser.Sync(user.AllOwnedArtists, contract.OwnedArtistEntries, a => user.AddOwnedArtist(session.Load <Artist>(a.Artist.Id))); SessionHelper.Sync(session, diff); user.Active = contract.Active; AuditLog(string.Format("updated {0}", EntryLinkFactory.CreateEntryLink(user)), session); }, PermissionToken.ManageUserPermissions, skipLog: true); }
public static string PermissionTokenName(PermissionTokenContract token) { var t = PermissionToken.GetById(token.Id); return(PermissionTokenNames.ResourceManager.GetString(t.Name) ?? t.Name); }
public UserWithPermissionsContract ToContract() { return(new UserWithPermissionsContract { Active = this.Active, GroupId = this.GroupId, Id = this.Id, Name = this.Name, OwnedArtistEntries = OwnedArtists.ToArray(), Poisoned = this.Poisoned, AdditionalPermissions = new HashSet <PermissionToken>(Permissions.Where(p => p.HasFlag).Select(p => PermissionToken.GetById(p.PermissionType.Id))) }); }
public ServerOnlyUserWithPermissionsContract ToContract() { return(new ServerOnlyUserWithPermissionsContract { Active = Active, Email = Email ?? string.Empty, GroupId = GroupId, Id = Id, Name = Name, OwnedArtistEntries = OwnedArtists.ToArray(), Poisoned = Poisoned, Supporter = Supporter, AdditionalPermissions = new HashSet <PermissionToken>(Permissions.Where(p => p.HasFlag).Select(p => PermissionToken.GetById(p.PermissionType.Id))) }); }