Invite & Library Edit - Missing SideNav Code (#2322)
This commit is contained in:
parent
7c8fdd9ea8
commit
a3afa04be4
9 changed files with 139 additions and 66 deletions
|
|
@ -459,7 +459,7 @@ public class AccountController : BaseApiController
|
|||
if (adminUser == null) return Unauthorized();
|
||||
if (!await _unitOfWork.UserRepository.IsUserAdminAsync(adminUser)) return Unauthorized(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
|
||||
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(dto.UserId);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(dto.UserId, AppUserIncludes.SideNavStreams);
|
||||
if (user == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-user"));
|
||||
|
||||
// Check if username is changing
|
||||
|
|
@ -509,6 +509,7 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
lib.AppUsers ??= new List<AppUser>();
|
||||
lib.AppUsers.Remove(user);
|
||||
user.RemoveSideNavFromLibrary(lib);
|
||||
}
|
||||
|
||||
libraries = (await _unitOfWork.LibraryRepository.GetLibraryForIdsAsync(dto.Libraries, LibraryIncludes.AppUser)).ToList();
|
||||
|
|
@ -518,6 +519,7 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
lib.AppUsers ??= new List<AppUser>();
|
||||
lib.AppUsers.Add(user);
|
||||
user.CreateSideNavFromLibrary(lib);
|
||||
}
|
||||
|
||||
user.AgeRestriction = hasAdminRole ? AgeRating.NotApplicable : dto.AgeRestriction.AgeRating;
|
||||
|
|
@ -528,6 +530,9 @@ public class AccountController : BaseApiController
|
|||
if (!_unitOfWork.HasChanges() || await _unitOfWork.CommitAsync())
|
||||
{
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.UserUpdate, MessageFactory.UserUpdateEvent(user.Id, user.UserName), user.Id);
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.SideNavUpdate, MessageFactory.SideNavUpdateEvent(user.Id), user.Id);
|
||||
// If we adjust library access, dashboards should re-render
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.DashboardUpdate, MessageFactory.DashboardUpdateEvent(user.Id), user.Id);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
|
@ -627,8 +632,10 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
lib.AppUsers ??= new List<AppUser>();
|
||||
lib.AppUsers.Add(user);
|
||||
user.CreateSideNavFromLibrary(lib);
|
||||
}
|
||||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
user.AgeRestriction = hasAdminRole ? AgeRating.NotApplicable : dto.AgeRestriction.AgeRating;
|
||||
user.AgeRestrictionIncludeUnknowns = hasAdminRole || dto.AgeRestriction.IncludeUnknowns;
|
||||
|
||||
|
|
@ -649,6 +656,7 @@ public class AccountController : BaseApiController
|
|||
await _unitOfWork.CommitAsync();
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var emailLink = await _accountService.GenerateEmailLink(Request, user.ConfirmationToken, "confirm-email", dto.Email);
|
||||
|
|
|
|||
|
|
@ -109,16 +109,7 @@ public class LibraryController : BaseApiController
|
|||
|
||||
foreach (var user in userNeedingNewLibrary)
|
||||
{
|
||||
var maxCount = user.SideNavStreams.Select(s => s.Order).Max();
|
||||
user.SideNavStreams.Add(new AppUserSideNavStream()
|
||||
{
|
||||
Name = library.Name,
|
||||
Order = maxCount + 1,
|
||||
IsProvided = false,
|
||||
StreamType = SideNavStreamType.Library,
|
||||
LibraryId = library.Id,
|
||||
Visible = true,
|
||||
});
|
||||
user.CreateSideNavFromLibrary(library);
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +192,7 @@ public class LibraryController : BaseApiController
|
|||
[HttpPost("grant-access")]
|
||||
public async Task<ActionResult<MemberDto>> UpdateUserLibraries(UpdateLibraryForUserDto updateLibraryForUserDto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(updateLibraryForUserDto.Username);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(updateLibraryForUserDto.Username, AppUserIncludes.SideNavStreams);
|
||||
if (user == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-doesnt-exist"));
|
||||
|
||||
var libraryString = string.Join(',', updateLibraryForUserDto.SelectedLibraries.Select(x => x.Name));
|
||||
|
|
@ -217,10 +208,12 @@ public class LibraryController : BaseApiController
|
|||
{
|
||||
// Remove
|
||||
library.AppUsers.Remove(user);
|
||||
user.RemoveSideNavFromLibrary(library);
|
||||
}
|
||||
else if (!libraryContainsUser && libraryIsSelected)
|
||||
{
|
||||
library.AppUsers.Add(user);
|
||||
user.CreateSideNavFromLibrary(library);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,6 +228,11 @@ public class LibraryController : BaseApiController
|
|||
_logger.LogInformation("Added: {SelectedLibraries} to {Username}",libraryString, updateLibraryForUserDto.Username);
|
||||
// Bust cache
|
||||
await _libraryCacheProvider.RemoveByPrefixAsync(CacheKey);
|
||||
|
||||
// TODO: Update a user's SideNav based on library access
|
||||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
|
||||
return Ok(_mapper.Map<MemberDto>(user));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue