diff --git a/Blueprint.Api/Blueprint.Api.csproj b/Blueprint.Api/Blueprint.Api.csproj index 3d9d6ba..a4d1a1e 100755 --- a/Blueprint.Api/Blueprint.Api.csproj +++ b/Blueprint.Api/Blueprint.Api.csproj @@ -1,7 +1,7 @@ <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> - <Version>1.4.2</Version> + <Version>1.4.3</Version> <TargetFramework>net8.0</TargetFramework> <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> <NoWarn>CS1591</NoWarn> diff --git a/Blueprint.Api/Services/MselService.cs b/Blueprint.Api/Services/MselService.cs index 67bbf83..43d24ef 100755 --- a/Blueprint.Api/Services/MselService.cs +++ b/Blueprint.Api/Services/MselService.cs @@ -175,6 +175,7 @@ public MselService( // get the units' msels var unitMselList = await _context.MselUnits .Where(mu => unitIdList.Contains(mu.UnitId) && mu.Msel.Status != MselItemStatus.Archived) + .Include(mu => mu.Msel.UserMselRoles) .Select(mu => mu.Msel) .ToListAsync(ct); // get msels created by user and all templates, if user is a content developer @@ -183,10 +184,16 @@ public MselService( { myMselList = await _context.Msels .Where(m => (m.CreatedBy == userId || m.IsTemplate) && m.Status != MselItemStatus.Archived) + .Include(m => m.UserMselRoles) .ToListAsync(ct); } // combine lists var mselList = unitMselList.Union(myMselList).OrderBy(m => m.Name); + // only return UserMselRoles for the requested user + foreach (var msel in mselList) + { + FilterUserMselRolesByUser(userId, msel); + } return _mapper.Map<IEnumerable<Msel>>(mselList); } @@ -212,6 +219,7 @@ public MselService( .Include(m => m.UserMselRoles) .AsSplitQuery() .SingleOrDefaultAsync(sm => sm.Id == id, ct); + FilterUserMselRolesByUser(_user.GetId(), mselEntity); var msel = _mapper.Map<Msel>(mselEntity); // add the needed parameters for Gallery integration if (msel.UseGallery) @@ -1903,6 +1911,18 @@ private async Task<IEnumerable<Guid>> GetMyDeployedMselIdsAsync(CancellationToke return myDeployedMselIds; } + private void FilterUserMselRolesByUser(Guid userId, MselEntity msel) + { + var userMselRoles = msel.UserMselRoles.ToArray(); + for (var i = 0; i < userMselRoles.Count(); i++) + { + if (userMselRoles[i].UserId != userId) + { + msel.UserMselRoles.Remove(userMselRoles[i]); + } + } + } + } public class DuplicateResult