Skip to content

include UserMselRoles with MSEL list #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading