diff --git a/Keas.Mvc/Controllers/ReportController.cs b/Keas.Mvc/Controllers/ReportController.cs index 23a5b2aae..a2b7b49c2 100644 --- a/Keas.Mvc/Controllers/ReportController.cs +++ b/Keas.Mvc/Controllers/ReportController.cs @@ -14,7 +14,6 @@ namespace Keas.Mvc.Controllers { - [Authorize(Policy = AccessCodes.Codes.AnyRole)] public class ReportController : SuperController { private readonly ApplicationDbContext _context; @@ -35,6 +34,7 @@ public async Task Index() return View(model); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task PersonActions(DateTime? startDate, DateTime? endDate) { var team = await _context.Teams.SingleAsync(a => a.Slug == Team); @@ -64,13 +64,14 @@ public async Task PersonActions(DateTime? startDate, DateTime? end return View(model); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task ExpiringItems(DateTime? expiresBefore = null, string showType = "All") { var model = await _reportService.ExpiringItems(null, Team, expiresBefore, showType); return View(model); } - + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task SupervisorDirectReports(int personID = 0) { var model = await SupervisorReportViewModel.Create(_context, Team, personID); @@ -132,6 +133,7 @@ public async Task PersonTeamList(int personId) } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task UnAcceptedItems(string showType = "All") { var userRoles = await _securityService.GetUserRoleNamesInTeamOrAdmin(Team); @@ -140,6 +142,7 @@ public async Task UnAcceptedItems(string showType = "All") } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task KeyValues() { var model = await KeyValueReportViewModel.Create(_context, Team); @@ -187,11 +190,13 @@ public async Task EquipmentHistoryReport(int id) return View(await _reportService.EquipmentHistory(null, Team, id)) ; } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task PersonEquipmentHistoryReport(int id) { return View(await _reportService.PersonEquipmentHistory(null, Team, id)); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task AccessReport() { var accessList = await _reportService.AccessList(null, Team); @@ -238,6 +243,7 @@ public async Task CompletedDocuments(DateTime? start = null, Date return View(model); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task PeopleInTeam(bool hideInactive = true) { var team = await _context.Teams.SingleAsync(a => a.Slug == Team); @@ -256,6 +262,7 @@ public async Task PeopleInTeam(bool hideInactive = true) return View(model); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task PeopleLeavingWithAssets() { var theDate = DateTime.UtcNow.AddDays(30).Date; @@ -265,6 +272,7 @@ public async Task PeopleLeavingWithAssets() return View(peopleQuery); } + [Authorize(Policy = AccessCodes.Codes.AnyRole)] public async Task InActiveSpaces() { var spaceQuery = await _reportService.InactiveSpaces(Team); diff --git a/Keas.Mvc/Controllers/SupervisorController.cs b/Keas.Mvc/Controllers/SupervisorController.cs new file mode 100644 index 000000000..446ab1a47 --- /dev/null +++ b/Keas.Mvc/Controllers/SupervisorController.cs @@ -0,0 +1,64 @@ +using System; +using Keas.Core.Data; +using Keas.Mvc.Models; +using Keas.Mvc.Services; +using Microsoft.AspNetCore.Mvc; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Keas.Core.Helper; +using Microsoft.AspNetCore.Authorization; + +namespace Keas.Mvc.Controllers +{ + [Authorize] + public class SupervisorController : SuperController + { + private readonly ApplicationDbContext _context; + private readonly ISecurityService _securityService; + private readonly ITeamsManager _teamsManager; + + + public SupervisorController(ApplicationDbContext context, ISecurityService _securityService, IEventService _eventService, ITeamsManager teamsManager) + { + _context = context; + this._securityService = _securityService; + _teamsManager = teamsManager; + } + + public IActionResult RefreshPermissions() + { + _teamsManager.ClearTeams(); + return RedirectToAction("SelectTeam"); + } + + public async Task MyStaff() + { + var person = await _securityService.GetPerson(Team); + if(person == null){ + Message = "You are not yet added to the system."; + return RedirectToAction("NoAccess","Home"); + } + var viewmodel = await MyStaffListModel.Create(_context, person); + + return View(viewmodel); + } + + public async Task StaffStuff(int id) // id of staff being viewed + { + var supervisor = await _securityService.GetPerson(Team); + if(supervisor == null){ + Message = "You are not yet added to the system."; + return RedirectToAction("NoAccess","Home"); + } + var underling = await _context.People.Include(p=> p.Team).FirstOrDefaultAsync(p=> p.Id==id && p.SupervisorId == supervisor.Id); + if(underling == null){ + return RedirectToAction("AccessDenied","Account"); // is this the best way to do this? -river + } + var viewmodel = await MyStaffListItem.Create(_context, underling); + + return View(viewmodel); + } + + } +} diff --git a/Keas.Mvc/Models/MyStaffListModel.cs b/Keas.Mvc/Models/MyStaffListModel.cs new file mode 100644 index 000000000..6678514fe --- /dev/null +++ b/Keas.Mvc/Models/MyStaffListModel.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using Keas.Core.Data; +using Keas.Core.Domain; +using System.Linq; +using System.Threading.Tasks; +using Keas.Mvc.Services; +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq.Expressions; + +namespace Keas.Mvc.Models +{ + public class MyStaffListModel + { + public List People { get; set; } + + public static async Task Create(ApplicationDbContext context, Person person) + { + var viewModel = new MyStaffListModel + { + People = await context.People.Where(p => p.TeamId == person.TeamId && p.Active && p.SupervisorId == person.Id) + .Include(p => p.Team) + .OrderBy(p => p.LastName).ThenBy(p => p.FirstName) + .AsNoTracking().ToListAsync() + }; + return viewModel; + } + + } + + public class MyStaffListItem + { + public Person Person { get; set;} + public List KeySerials { get; set; } + public List Equipment { get; set; } + public List Access { get; set; } + public List Workstations { get; set; } + public List Documents { get; set; } + public Func DocumentUrlResolver { get; set; } + public List Histories { get; set; } + public bool PendingItems { get; set; } + public IEnumerable TeamsWithPendingAssignments { get; set; } + + + public static async Task Create(ApplicationDbContext context, Person person) + { + var viewModel = new MyStaffListItem + { + Person = person, + KeySerials = await context.KeySerials.Include(s=> s.Key).ThenInclude(k=> k.KeyXSpaces).ThenInclude(kxp=> kxp.Space).Include(s=> s.KeySerialAssignment) + .Where(s=> s.KeySerialAssignment.Person==person).AsNoTracking().ToListAsync(), + Equipment = await context.Equipment.Include(e => e.Space).Include(e=> e.Assignment).Where(e => e.Assignment.Person == person).AsNoTracking().ToListAsync(), + Access = await context.Access + .Where(x => x.Active && x.Assignments.Any(y => y.Person == person)) + .Select(a => new Access() + { + Id = a.Id, + Name = a.Name, + Assignments = a.Assignments.Where(b => b.Person == person).Select( + c => new AccessAssignment() + { + AccessId = c.AccessId, + ExpiresAt = c.ExpiresAt, + Id = c.Id + } + ).ToList() + }) + .AsNoTracking().ToListAsync(), + Workstations = await context.Workstations.Include(w=> w.Assignment).Include(w=> w.Space).Where(w=> w.Assignment.Person==person).AsNoTracking().ToListAsync(), + Documents = await context.Documents.Where(d => d.Person == person).AsNoTracking().ToListAsync(), + Histories = await context.Histories.Where(x => x.Target == person) + .OrderByDescending(x => x.ActedDate) + .Take(10).AsNoTracking().ToListAsync() + }; + + return viewModel; + } + + } +} diff --git a/Keas.Mvc/Views/Confirm/MyStuff.cshtml b/Keas.Mvc/Views/Confirm/MyStuff.cshtml index baf83a264..3570e0035 100644 --- a/Keas.Mvc/Views/Confirm/MyStuff.cshtml +++ b/Keas.Mvc/Views/Confirm/MyStuff.cshtml @@ -38,6 +38,16 @@
+
+
+
+

People

+
+
+ +
@@ -207,7 +217,7 @@ View } - @if(!Model.Workstations.Any()){ + @if(!Model.Documents.Any()){ You have no documents assigned. diff --git a/Keas.Mvc/Views/Report/Index.cshtml b/Keas.Mvc/Views/Report/Index.cshtml index b9c7cd96e..c8ad57edd 100644 --- a/Keas.Mvc/Views/Report/Index.cshtml +++ b/Keas.Mvc/Views/Report/Index.cshtml @@ -31,6 +31,9 @@
} + @if (Model.Contains(Role.Codes.KeyMaster) || Model.Contains(Role.Codes.EquipmentMaster) || Model.Contains(Role.Codes.AccessMaster) // basically Codes.AnyRole + || Model.Contains(Role.Codes.SpaceMaster) || Model.Contains(Role.Codes.DocumentMaster) || Model.Contains(Role.Codes.Admin) || Model.Contains(Role.Codes.PersonManager)) + {

People Reports

    @@ -54,6 +57,7 @@ }
+ } @if (Model.Contains(Role.Codes.SpaceMaster) || Model.Contains(Role.Codes.DepartmentalAdmin)) {
@@ -108,22 +112,37 @@
} -
-

General Reports

-
diff --git a/Keas.Mvc/Views/Shared/_Layout.cshtml b/Keas.Mvc/Views/Shared/_Layout.cshtml index 8c4316c1f..2da994b82 100644 --- a/Keas.Mvc/Views/Shared/_Layout.cshtml +++ b/Keas.Mvc/Views/Shared/_Layout.cshtml @@ -139,6 +139,9 @@ + } if ((await AuthorizationService.AuthorizeAsync(User, AccessCodes.Codes.DepartmentAdminAccess)).Succeeded || (await AuthorizationService.AuthorizeAsync(User, AccessCodes.Codes.PersonManagerAccess)).Succeeded) diff --git a/Keas.Mvc/Views/Supervisor/MyStaff.cshtml b/Keas.Mvc/Views/Supervisor/MyStaff.cshtml new file mode 100644 index 000000000..67d08d6f9 --- /dev/null +++ b/Keas.Mvc/Views/Supervisor/MyStaff.cshtml @@ -0,0 +1,52 @@ +@using Keas.Core.Extensions +@model Keas.Mvc.Models.MyStaffListModel + +@{ + ViewData["Title"] = "MyStaff"; +} + +
+
+
+
+

MyStaff

+
+
+
+
+
+
+
+

People

+
+
+ + + + + + + + + + @foreach (var person in Model.People) { + + + + + + } + @if(!Model.People.Any()){ + + + + } + +
NameEmailStuff
@Html.DisplayFor(modelItem => person.NameV2)@Html.DisplayFor(modelItem => person.Email) + @Html.ActionLink("View", "StaffStuff", "Supervisor", new { id= @person.Id }) +
You do not supervise anyone.
+
+
+ +
+
diff --git a/Keas.Mvc/Views/Supervisor/StaffStuff.cshtml b/Keas.Mvc/Views/Supervisor/StaffStuff.cshtml new file mode 100644 index 000000000..0c795f0d5 --- /dev/null +++ b/Keas.Mvc/Views/Supervisor/StaffStuff.cshtml @@ -0,0 +1,250 @@ +@using Keas.Core.Extensions +@model Keas.Mvc.Models.MyStaffListItem + +@{ + ViewData["Title"] = "Staff Stuff"; +} +@if(Model.PendingItems){ + var currentSlug = TempData["TeamName"] as string; + if (Model.TeamsWithPendingAssignments.Any(a => a.Slug != null && a.Slug == currentSlug)) + { +
+
+

You have pending items!

+ Go to Accept page +
+
+ } + if (Model.TeamsWithPendingAssignments.Any(a => a.Slug != currentSlug)) + { +

You have items pending in other teams:

+ foreach (var teamWithPending in Model.TeamsWithPendingAssignments.Where(a => a.Slug != currentSlug)) + { +
+
+

You have pending items in team @teamWithPending.Name!

+ Go to Accept page +
+
+ } + } +} +
+
+
+
+

@Model.Person.Name's Stuff

+
+
+
+
+
+
+
+

Keys

+
+
+
+ + + + + + + + + + + + @foreach (var serial in Model.KeySerials) { + + + + + + + + } + + @if (!Model.KeySerials.Any()) { + + + + } + +
CodeSerialNameExpirationAccepted?
@serial.Key.Code@serial.Number@serial.Key.Name@serial.KeySerialAssignment.ExpiresAt.ToShortDateString()@serial.KeySerialAssignment.ConfirmedAt.AcceptedWithDate()
@Model.Person.Name has no Keys assigned.
+
+
+
+
+
+

Equipment

+
+
+ + + + + + + + + + + + + + @foreach (var equipment in Model.Equipment) { + + + + + + + + + + } + @if(!Model.Equipment.Any()){ + + + + } + +
Serial NumberNameMakeModelRoomExpirationAccepted?
@equipment.SerialNumber@equipment.Name@equipment.Make@equipment.Model@equipment.Space?.ShortName@equipment.Assignment.ExpiresAt.ToShortDateString()@equipment.Assignment.ConfirmedAt.AcceptedWithDate()
@Model.Person.Name has no equipment assigned.
+
+
+ +
+
+
+

Access

+
+
+ + + + + + + + + @foreach (var access in Model.Access) { + + + + + } + @if(!Model.Access.Any()){ + + + + } + +
NameExpiration
@access.Name@access.Assignments.First().ExpiresAt.ToShortDateString()
@Model.Person.Name has no access assigned.
+
+
+ + +
+
+
+

Workstations

+
+
+ + + + + + + + + + + + @foreach (var workstation in Model.Workstations) { + + + + + + + } + @if(!Model.Workstations.Any()){ + + + + } + +
NameRoomExpirationAccepted?
@workstation.Title@workstation.Space.ShortName@workstation.Assignment.ExpiresAt.ToShortDateString()@workstation.Assignment.ConfirmedAt.AcceptedWithDate()
@Model.Person.Name has no workstations assigned.
+ +
+
+ +
+
+
+

Documents

+
+
+ + + + + + + + + + + + @foreach (var document in Model.Documents) { + + + + + + + } + @if(!Model.Documents.Any()){ + + + + } + +
NameStatusDateLink
@document.Name@document.Status@(document.CompletedAt.HasValue ? document.CompletedAt : document.CreatedAt)View
@Model.Person.Name has no documents assigned.
+ +
+
+ +
+
+

History

+
+ + + + + + + + + @foreach (var history in Model.Histories) { + + + + + } + @if(!Model.Histories.Any()){ + + + + } + +
@history.ActedDate.ToShortDateString()@history.Description
No history to display
+
+
+ +
+