Skip to content

Commit

Permalink
include UserMselRoles with MSEL list
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-tspencer committed Nov 14, 2024
1 parent 743b8bb commit 9fc6eee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Blueprint.Api/Blueprint.Api.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
20 changes: 20 additions & 0 deletions Blueprint.Api/Services/MselService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9fc6eee

Please sign in to comment.