Skip to content

Commit

Permalink
Merge pull request #11 from ucdavis/fix/roletemplate-performance
Browse files Browse the repository at this point in the history
Fix/roletemplate performance
  • Loading branch information
bsedwards authored Jan 12, 2024
2 parents 79052e2 + 4dd80cc commit 481ec17
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
12 changes: 9 additions & 3 deletions web/Areas/RAPS/Controllers/RAPSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
{
instance = path[(int)rapsIdx + 1];
}
string page = "";
if (rapsIdx != null && rapsIdx > -1 && path?.Count > rapsIdx + 2)
{
page = path[(int)rapsIdx + 2];
}
ViewData["ViperLeftNav"] = await Nav(roleIdValid ? roleId : null,
permIdValid ? permissionId : null,
memberId,
instance);
instance,
page);
}

/// <summary>
Expand Down Expand Up @@ -93,7 +99,7 @@ public async Task<ActionResult> Index(string? instance)
// Problem("Entity set 'RAPSContext.TblRoles' is null.");}
}

public async Task<NavMenu> Nav(int? roleId, int? permissionId, string? memberId, string instance = "VIPER")
public async Task<NavMenu> Nav(int? roleId, int? permissionId, string? memberId, string instance = "VIPER", string page = "")
{
TblRole? selectedRole = (roleId != null) ? await _RAPSContext.TblRoles.FindAsync(roleId) : null;
TblPermission? selectedPermission = (permissionId != null) ? await _RAPSContext.TblPermissions.FindAsync(permissionId) : null;
Expand All @@ -108,7 +114,7 @@ public async Task<NavMenu> Nav(int? roleId, int? permissionId, string? memberId,
{
if(_securityService.IsAllowedTo("AccessInstance", inst))
{
nav.Add(new NavMenuItem() { MenuItemText = inst, MenuItemURL = "~/raps/" + inst });
nav.Add(new NavMenuItem() { MenuItemText = inst, MenuItemURL = "~/raps/" + inst + "/" + page });
}
}
nav.Add(new NavMenuItem() { MenuItemText = "Roles", IsHeader = true });
Expand Down
19 changes: 13 additions & 6 deletions web/Areas/RAPS/Controllers/RoleTemplatesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,25 @@ public RoleTemplatesController(RAPSContext context)

// GET: RoleTemplates
[HttpGet]
public async Task<ActionResult<IEnumerable<RoleTemplate>>> GetRoleTemplates(string instance)
public async Task<ActionResult<IEnumerable<RoleTemplateSimplified>>> GetRoleTemplates(string instance)
{
if (_context.RoleTemplates == null)
{
return NotFound();
}
return await _context.RoleTemplates
if (_context.RoleTemplates == null)
{
return NotFound();
}
List<RoleTemplate> dbRoleTemplates = await _context.RoleTemplates
.Include(rt => rt.RoleTemplateRoles)
.ThenInclude(rtr => rtr.Role)
.Where(RAPSSecurityService.FilterRoleTemplatesToInstance(instance))
.OrderBy(rt => rt.TemplateName)
.ToListAsync();

List<RoleTemplateSimplified> roleTemplates = new();
foreach(var rt in dbRoleTemplates)
{
roleTemplates.Add(new RoleTemplateSimplified(rt));
}
return roleTemplates;
}

// GET: RoleTemplates/5
Expand Down
8 changes: 8 additions & 0 deletions web/Areas/RAPS/Models/RoleSimplified.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Viper.Areas.RAPS.Models
{
public class RoleSimplified
{
public int RoleId { get; set; }
public string FriendlyName { get; set; } = null!;
}
}
34 changes: 34 additions & 0 deletions web/Areas/RAPS/Models/RoleTemplateSimplified.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Viper.Models.RAPS;

namespace Viper.Areas.RAPS.Models
{
/* Streamlined object to return from the RoleTemplate REST calls */
public class RoleTemplateSimplified
{
public int RoleTemplateId { get; set; }

public string TemplateName { get; set; } = null!;

public string Description { get; set; } = null!;

public virtual ICollection<RoleSimplified> Roles { get; set; } = new List<RoleSimplified>();

public RoleTemplateSimplified() { }
public RoleTemplateSimplified(RoleTemplate rt)
{
RoleTemplateId = rt.RoleTemplateId;
TemplateName = rt.TemplateName;
Description = rt.Description;
Roles = new List<RoleSimplified>();
foreach (var rtr in rt.RoleTemplateRoles)
{
Roles.Add(new RoleSimplified()
{
RoleId = rtr.Role.RoleId,
FriendlyName = rtr.Role.FriendlyName
});
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task<IViewComponentResult> InvokeAsync()
UserHelper userHelper = new UserHelper();
string? loginId = userHelper?.GetCurrentUser()?.LoginId;
bool onDev = HttpHelper.Environment?.EnvironmentName == "Development";
ViewData["sessionRefreshUrl"] = (onDev ? "http://localhost/" : "/")
ViewData["sessionRefreshUrl"] = (onDev ? "http://localhost/" : ("https://" + HttpHelper.HttpContext?.Request.Host.Value + "/"))
+ "/public/timeout/seconds_until_timeout_v2.cfm?id="
+ (loginId ?? "")
+ "&service=" + (onDev ? "Viper2-dev" : "Viper2");
Expand Down

0 comments on commit 481ec17

Please sign in to comment.