Skip to content
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

Feature/raps inactive users role comparison #13

Merged
merged 3 commits into from
Jan 23, 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
24 changes: 23 additions & 1 deletion web/Areas/RAPS/Controllers/RAPSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Viper.Classes;
using System.Runtime.Versioning;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Data;

namespace Viper.Areas.RAPS.Controllers
{
Expand Down Expand Up @@ -119,7 +120,11 @@ public async Task<NavMenu> Nav(int? roleId, int? permissionId, string? memberId,
}
nav.Add(new NavMenuItem() { MenuItemText = "Roles", IsHeader = true });
nav.Add(new NavMenuItem() { MenuItemText = "Role List", MenuItemURL = "Rolelist" });
if(_securityService.IsAllowedTo("ViewRoles", instance))
if (_securityService.IsAllowedTo("EditRoleMembership", instance))
{
nav.Add(new NavMenuItem() { MenuItemText = "Role Comparison", MenuItemURL = "RolePermissionsComparison" });
}
if (_securityService.IsAllowedTo("ViewRoles", instance))
{
nav.Add(new NavMenuItem() { MenuItemText = "Role Templates", MenuItemURL = "RoleTemplateList" });
}
Expand Down Expand Up @@ -353,6 +358,23 @@ public async Task<IActionResult> RolePermissions(int roleId)
return await Task.Run(() => View("~/Areas/RAPS/Views/Roles/Permissions.cshtml"));
}

/// <summary>
/// Compare permissions for two roles
/// </summary>
/// <returns></returns>
[Route("/[area]/{Instance}/[action]")]
public async Task<IActionResult> RolePermissionsComparison(string instance)
{
if (_securityService.IsAllowedTo("EditRoleMembership", instance))
{
return await Task.Run(() => View("~/Areas/RAPS/Views/Roles/PermissionComparison.cshtml"));
}
else
{
return await Task.Run(() => View("~/Views/Home/403.cshtml"));
}
}

/// <summary>
/// List members of a permission
/// </summary>
Expand Down
36 changes: 36 additions & 0 deletions web/Areas/RAPS/Controllers/RolePermissionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
using System.Data;
using Viper.Areas.RAPS.Models;
using Viper.Areas.RAPS.Services;
Expand Down Expand Up @@ -99,6 +100,41 @@ public async Task<ActionResult<List<TblRolePermission>>> GetTblRolePermissions(s
return tblRolePermissions;
}


[HttpGet("Roles/{role1Id}/{role2Id}/PermissionComparison")]
[Permission(Allow = "RAPS.Admin,RAPS.EditRoleMembership")]
public async Task<ActionResult<RolePermissionComparison>> CompareRolePermissions(string instance, int role1Id, int role2Id)
{
TblRole? role1 = _securityService.GetRoleInInstance(instance, role1Id);
TblRole? role2 = _securityService.GetRoleInInstance(instance, role2Id);
if(role1 == null || role2 == null)
{
return NotFound();
}

if (!_securityService.IsAllowedTo("EditRoleMembership", instance) ||
!_securityService.IsAllowedTo("ViewRolePermissions", instance, role1) ||
!_securityService.IsAllowedTo("ViewRolePermissions", instance, role2))
{
return Forbid();
}

List<TblRolePermission> role1Permissions = await _context.TblRolePermissions
.Include(rp => rp.Permission)
.Where(rp => rp.RoleId == role1Id)
.OrderBy(rp => rp.Permission.Permission)
.ToListAsync();
List<TblRolePermission> role2Permissions = await _context.TblRolePermissions
.Include(rp => rp.Permission)
.Where(rp => rp.RoleId == role2Id)
.OrderBy(rp => rp.Permission.Permission)
.ToListAsync();


RolePermissionComparison result = new(role1Permissions, role2Permissions);
return result;
}

// POST Roles/5/Permissions
// POST Permissions/5/Roles
[HttpPost("Roles/{roleId}/Permissions")]
Expand Down
45 changes: 45 additions & 0 deletions web/Areas/RAPS/Models/RolePermissionComparison.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Viper.Models.RAPS;

namespace Viper.Areas.RAPS.Models
{
public class RolePermissionComparison
{
public List<RolePermission> Role1Permissions { get; set; } = new List<RolePermission>();
public List<RolePermission> Role2Permissions { get; set; } = new List<RolePermission>();

public RolePermissionComparison()
{

}

public RolePermissionComparison(List<TblRolePermission> role1Permissions, List<TblRolePermission> role2Permissions)
{
foreach(var p in role1Permissions)
{
Role1Permissions.Add(new RolePermission()
{
PermissionId = p.PermissionId,
Name = p.Permission.Permission,
IsInOtherList = role2Permissions.FindIndex(p2 => p2.PermissionId == p.PermissionId) >= 0
});
}

foreach (var p in role2Permissions)
{
Role2Permissions.Add(new RolePermission()
{
PermissionId = p.PermissionId,
Name = p.Permission.Permission,
IsInOtherList = role1Permissions.FindIndex(p1 => p1.PermissionId == p.PermissionId) >= 0
});
}
}

public class RolePermission
{
public int PermissionId { get; set; }
public string Name { get; set; } = string.Empty;
public bool IsInOtherList { get; set; }
}
}
}
49 changes: 36 additions & 13 deletions web/Areas/RAPS/Views/Members/List.cshtml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<h2>Search for a user</h2>
<q-form @@submit="return false;">
<q-input
class="q-ml-xs q-mr-xs"
dense
clearable
clear-icon="close"
outlined
debounce="300"
placeholder="Search for users"
v-model="userSearch"
autofocus>
</q-input>
<div class="row">
<q-input
class="q-ml-xs q-mr-xs col-12 col-sm-8 col-md-4"
dense
clearable
clear-icon="close"
outlined
debounce="300"
placeholder="Search for users"
v-model="userSearch"
autofocus>
</q-input>
<q-toggle v-model="includeInactive"
checked-icon="check"
unchecked-icon="clear"
label="Include Inactive Users">
</q-toggle>
</div>
</q-form>

<q-table title="Search Results"
Expand Down Expand Up @@ -47,6 +54,11 @@
{{props.row.displayLastName}}, {{props.row.displayFirstName}}
</q-td>
</template>
<template v-slot:body-cell-active="props">
<q-td :props="props" :class="props.row.current ? '' : 'bg-red-5 text-white'" width="25px">
{{props.row.current ? "Y" : "N"}}
</q-td>
</template>
</q-table>
@section Scripts {
<script src="~/js/qtable.js"></script>
Expand All @@ -55,13 +67,14 @@
data() {
return {
userSearch: "",
includeInactive: false,
members: new quasarTable({
keys: ["memberId"],
urlBase: "Members",
columns: [
{ name: "links", label: "", field: "", align: "left", style: "width:100px;" },
{ name: "member", label: "Member", field: "", align: "left", sortable: true },
{ name: "active", label: "Active", field: "current", align: "left", sortable: true, format: v => (v == 1 ? "Y" : "N") },
{ name: "active", label: "Active", field: "current", align: "left", sortable: true },
{ name: "countRoles", label: "Count Roles", field: "countRoles", align: "left", sortable: true },
{ name: "countPermissions", label: "Count Permissions", field: "countPermissions", align: "left", sortable: true }
],
Expand All @@ -71,14 +84,18 @@
},
methods: {
findUsers: async function () {
this.members.urlBase = "Members?search=" + this.userSearch
this.members.urlBase = "Members?search=" + this.userSearch + "&active=" + (this.includeInactive ? "all" : "active")
if (this.userSearch.length >= 3) {
this.members.load(this)
}
}
},
mounted() {
this.members.loading = false
var includeInactive = getItemFromStorage("RAPS_userSearch_includeInactive")
if(includeInactive) {
this.includeInactive = includeInactive
}
var userSearch = getItemFromStorage("RAPS_userSearch_userSearch")
if(userSearch) {
this.userSearch = userSearch
Expand All @@ -92,6 +109,12 @@
this.findUsers()
},
deep: true
},
includeInactive: {
handler(v) {
putItemInStorage("RAPS_userSearch_includeInactive", v)
this.findUsers()
}
}
}
})
Expand Down
5 changes: 3 additions & 2 deletions web/Areas/RAPS/Views/Members/Roles.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="row">
<q-input outlined dense v-model="memberRolesTable.object.comment" label="Comment"></q-input>
</div>
<div class="row">
<div class="row" v-if="showVMACSPush">
<q-toggle label="Push to VMACS" v-model="updateVMACS"></q-toggle>
</div>
</q-card-section>
Expand Down Expand Up @@ -223,7 +223,7 @@
addRolesThenPushToVMACS: async function() {
await this.addRoles()
this.loadTables()
this.pushToVMACS(true)
this.pushToVMACS(false)
},
loadTables: async function () {
await this.memberRolesTable.load(this)
Expand All @@ -234,6 +234,7 @@
this.member = await viperFetch(this, "members/" + this.memberId)
},
pushToVMACS: async function (skipToggleCheck) {
console.log(skipToggleCheck, this.updateVMACS)
if (skipToggleCheck || this.updateVMACS) {
Quasar.Loading.show({ message: "Updating VMACS" })
await viperFetch(this, "Members/" + this.memberId + "/Roles/VMACSExport", { method: "POST" })
Expand Down
1 change: 1 addition & 0 deletions web/Areas/RAPS/Views/Roles/Members.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
this.membersTable.load()
await this.loadRole()
this.showVMACSPush = this.role.instance.indexOf("VMACS") == 0
console.log(this.role, this.showVMACSPush)
danransom marked this conversation as resolved.
Show resolved Hide resolved
}
})
</script>
Expand Down
105 changes: 105 additions & 0 deletions web/Areas/RAPS/Views/Roles/PermissionComparison.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<h2>Compare permissions for two roles</h2>
<q-form @@submit="return false;">
<div class="row">
<q-select v-model="role1" :options="role1Roles"
dense options-dense outlined class="col-sm-6 col-md-4"
use-input hide-selected fill-input input-debounce="0" @@filter="role1Search">
</q-select>
<q-select v-model="role2" :options="role2Roles"
dense options-dense outlined class="col-sm-6 col-md-4"
use-input hide-selected fill-input input-debounce="0" @@filter="role2Search">
</q-select>
<q-btn label="Compare" dense flat class="bg-primary text-white q-px-md" @@click="compareRoles"></q-btn>
</div>
</q-form>

<div v-if="showComparison" class="q-gutter-sm q-pa-sm row items-start">
<q-card flat bordered style="max-width: 500px;" class="q-ml-sm q-m-sm q-px-md">
<q-card-section class="q-px-none">
<div class="text-h6 text-left">{{role1.label}}</div>
</q-card-section>
<table class="">
<thead>
<tr>
<th class="text-left">In Both</th>
<th class="text-left">Permission</th>
</tr>
</thead>
<tbody>
<tr v-for="(permission, index) in comparison.role1Permissions">
<td>
<q-icon name="check" color="green" v-if="permission.isInOtherList"></q-icon>
</td>
<td>{{permission.name}}</td>
</tr>
</tbody>
</table>
</q-card>
<q-card flat bordered style="max-width: 500px;" class="q-ml-sm q-m-sm q-px-md">
<q-card-section class="q-px-none">
<div class="text-h6 text-left">{{role2.label}}</div>
</q-card-section>
<table class="">
<thead>
<tr>
<th class="text-left">In Both</th>
<th class="text-left">Permission</th>
</tr>
</thead>
<tbody>
<tr v-for="(permission, index) in comparison.role2Permissions">
<td>
<q-icon name="check" color="green" v-if="permission.isInOtherList"></q-icon>
</td>
<td>{{permission.name}}</td>
</tr>
</tbody>
</table>
</q-card>
</div>


@section Scripts {
<script asp-add-nonce="true">
createVueApp({
data() {
return {
role1: 0,
role2: 0,
roles: [],
role1Roles: [],
role2Roles: [],
comparison: {},
showComparison: false
}
},
methods: {
compareRoles: async function () {
if (this.role1.value > 0 && this.role2.value > 0) {
this.comparison = await viperFetch(this, "Roles/" + this.role1.value + "/" + this.role2.value + "/PermissionComparison")
this.showComparison = true
}
},
role1Search: function (val, update, abort) {
update(() => {
const needle = val.toLowerCase()
this.role1Roles = this.roles.filter(v => v.label.toLowerCase().indexOf(needle) > -1)
})
},
role2Search: function (val, update, abort) {
update(() => {
const needle = val.toLowerCase()
this.role2Roles = this.roles.filter(v => v.label.toLowerCase().indexOf(needle) > -1)
})
}
},
async mounted() {
var result = await viperFetch(this, "Roles?application=0")
this.roles = result.map(r => ({
value: r.roleId, label: r.friendlyName
}))
this.role1Roles = this.role2Roles = this.roles
}
})
</script>
}