-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInfoController.cs
More file actions
145 lines (133 loc) · 6.05 KB
/
Copy pathUserInfoController.cs
File metadata and controls
145 lines (133 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Viper.Models.AAUD;
using Viper.Areas.RAPS.Services;
using Web.Authorization;
using Viper.Classes;
using Viper.Classes.SQLContext;
using Viper.Areas.Directory.Models;
using System.Runtime.Versioning;
using System.Collections.Generic;
using Viper.Areas.Directory.Services;
using Viper.Classes.Utilities;
using Microsoft.Extensions.Caching.Memory;
namespace Viper.Areas.Directory.Controllers
{
[Area("Directory")]
[Permission(Allow = "SVMSecure")]
public class UserInfoController : AreaController
{
public Classes.SQLContext.AAUDContext _aaud;
private UserInfoService _userInfo;
public IUserHelper UserHelper;
private readonly RAPSContext _rapsContext;
public UserInfoController(
RAPSContext rapsContext,
AAUDContext aaudContext,
CoursesContext coursesContext,
EquipmentLoanContext equipmentLoanContext,
PPSContext ppsContext,
IDCardsContext idCardsContext,
KeysContext keysContext)
{
_aaud = aaudContext;
_rapsContext = rapsContext;
UserHelper = new UserHelper();
// Get services from DI container
var httpClientFactory = HttpHelper.HttpContext?.RequestServices.GetService(typeof(IHttpClientFactory)) as IHttpClientFactory;
var memoryCache = HttpHelper.HttpContext?.RequestServices.GetService(typeof(IMemoryCache)) as IMemoryCache;
var configuration = HttpHelper.HttpContext?.RequestServices.GetService(typeof(IConfiguration)) as IConfiguration;
_userInfo = new UserInfoService(
aaudContext,
rapsContext,
coursesContext,
equipmentLoanContext,
ppsContext,
idCardsContext,
keysContext,
configuration!,
httpClientFactory!,
memoryCache!
);
}
/// <summary>
/// Redirect if we don't have a mothraID
/// </summary>
[Route("/userinfo/")]
public ActionResult Index()
{
return Redirect("/Directory");
}
/// <summary>
/// UserInfo Page
/// </summary>
/// <param name="id">MothraID</param>
/// <returns></returns>
[Route("/userinfo/{mothraID}")]
public async Task<ActionResult> UserInfo(string? mothraID)
{
// Validate required parameters
if (string.IsNullOrWhiteSpace(mothraID))
{
return Redirect("/Directory");
}
else
{
// Check if user is viewing their own page
var currentUser = UserHelper.GetCurrentUser();
bool ownPage = mothraID == currentUser.MothraId;
var individual = await _aaud.AaudUsers.Where(u => (u.MothraId == mothraID)).FirstOrDefaultAsync();
string? iamId = null;
if (individual != null) iamId = individual.IamId;
// Get user information
var userInfo = await _userInfo.GetUserInfoAsync(iamId, mothraID);
if (userInfo == null)
{
return Redirect("/Directory");
}
// Set permissions for the view
userInfo.CanViewDirectoryDetail = ownPage || UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.directoryDetail");
userInfo.CanViewStudentID = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.studentID");
userInfo.CanViewIAM = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.iam");
userInfo.CanViewRoles = ownPage || UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.raps");
userInfo.CanViewUCPath = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.directoryUCPathInfo");
userInfo.CanViewUCPathDetail = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.directoryUCPathInfoAllDetail");
userInfo.CanViewIDCards = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.idcards");
userInfo.CanViewKeys = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.keys");
userInfo.CanViewLoans = ownPage || UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.loans");
userInfo.CanViewInstinct = ownPage || UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.userinfo.instinct");
userInfo.CanViewADGroups = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.UserInfo.ADGroups");
userInfo.CanViewDirectoryDetail = true;
userInfo.CanViewStudentID = true;
userInfo.CanViewIAM = true;
userInfo.CanViewRoles = true;
userInfo.CanViewUCPath = true;
userInfo.CanViewUCPathDetail = true;
userInfo.CanViewIDCards = true;
userInfo.CanViewKeys = true;
userInfo.CanViewLoans = true;
userInfo.CanViewInstinct = true;
userInfo.CanViewADGroups = true;
return View("~/Areas/Directory/Views/UserInfo.cshtml", userInfo);
}
}
/// <summary>
/// Get user photo, stubbed for now
/// </summary>
/// <param name="mailID">Mail ID</param>
/// <param name="altphoto">Use alternative photo</param>
/// <returns></returns>
[Route("/userPhoto")]
public async Task<ActionResult> UserPhoto(string mailID, bool altphoto = false)
{
return NotFound();
}
[Route("/[area]/nav")]
public async Task<ActionResult<IEnumerable<NavMenuItem>>> Nav()
{
var nav = new List<NavMenuItem>();
return await Task.Run(() => nav);
}
}
}