Skip to content
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
14 changes: 14 additions & 0 deletions ResourceInformationV2.Data/DataHelpers/SecurityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public async Task<string> GetDepartmentName(string sourceName, string netId) {
return entry?.DepartmentTag ?? "";
}

public async Task<bool> ChangeOwner(string sourceName, int newId) {
var oldOwner = await resourceRepository.ReadAsync(c => c.SecurityEntries.Include(c => c.Source).FirstOrDefault(se => se.Source != null && se.Source.Code == sourceName.Replace("!", "") && se.IsOwner));
if (oldOwner == null) {
return false;
}
oldOwner.IsOwner = false;
var newOwner = await resourceRepository.ReadAsync(c => c.SecurityEntries.FirstOrDefault(se => se.Id == newId));
if (newOwner == null) {
return false;
}
newOwner.IsOwner = true;
return await resourceRepository.UpdateAsync(oldOwner) > 0 && await resourceRepository.UpdateAsync(newOwner) > 0;
}

public async Task<bool> ConfirmNetIdCanAccessSource(string sourceName, string netId) {
return await resourceRepository.ReadAsync(c => c.SecurityEntries.Include(c => c.Source).Any(se => se.Source != null && se.Source.Code == sourceName.Replace("!", "") && se.Email == netId));
}
Expand Down
18 changes: 6 additions & 12 deletions ResourceInformationV2.Data/PageList/PageGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@ public static class PageGroup {
{ SidebarEnum.AddEditInformation, new() { new ("Home", "/"),
new ("Add/Edit Information", "/add") } },
{ SidebarEnum.PeopleItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("People", "/person/general") } },
new ("Edit People", "/person/edit") } },
{ SidebarEnum.PublicationItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("Publications", "/publication/general") } },
new ("Edit Publications", "/publication/edit") } },
{ SidebarEnum.ResourceItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("Resources", "/resource/general") } },
new ("Edit Resources", "/resource/edit") } },
{ SidebarEnum.FaqItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("FAQs", "/faq/general") } },
new ("Edit FAQs", "/faq/edit") } },
{ SidebarEnum.NotesItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("Notes", "/note/general") } },
new ("Edit Notes", "/note/edit") } },
{ SidebarEnum.EventItem, new() { new ("Home", "/"),
new ("Edit", "/edit"),
new ("Notes", "/event/general") } }
new ("Edit Events", "/event/edit") } }
};

private static readonly Dictionary<SidebarEnum, List<PageLink>> _sidebars = new() {
Expand Down
37 changes: 26 additions & 11 deletions ResourceInformationV2/Components/Pages/Configuration/Security.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
<div class="security-box">
<p>@netid.Display</p>
<button class="ilw-button" @onclick="e => Remove(netid.Email)">Remove</button>
<button class="ilw-button" disabled="@netid.IsOwner" @onclick="e => Remove(netid.Email)">Remove</button>
</div>
}

Expand All @@ -19,16 +19,17 @@
<p>Add a Net ID to add to the list. The <em>@@illinois.edu</em> is optional.</p>
</div>

<div class="ils-input-entry">
<label for="department">Restrict to a department</label>
<select id="department" class="ils-input-long" @bind="NewDepartment">
<option value="">None (access to all departments)</option>
@foreach (var item in Departments)
{
<option value="@item">@item</option>
}
</select>
</div>
@if (Departments.Count > 0) {
<div class="ils-input-entry">
<label for="department">Restrict to a department</label>
<select id="department" class="ils-input-long" @bind="NewDepartment">
<option value="">None (access to all departments)</option>
@foreach (var item in Departments) {
<option value="@item">@item</option>
}
</select>
</div>
}
<p><button class="ilw-button" @onclick="Add">Add Net ID</button></p>
<h2>API Updates</h2>
<p>This generates an API key that will allow you to programatically add, update, and delete items within your source.</p>
Expand All @@ -54,4 +55,18 @@
<p>If you had a valid API key before creating this new API key, it will be usable as well. If you wish to deactivate the old API key (because it has been compromised), then you should invalidate the API key and then create a new key.</p>
<p><code>API Key: <strong>@ApiGuid</strong></code></p>
}

<h2>Change Owner</h2>
<p>Each Resource Source must have an owner. You can change the owner below:</p>
<div class="ils-input-entry">
<label for="newowner">Owner</label>
<select id="newowner" class="ils-input-long" @bind="CurrentOwnerId">
@foreach (var netid in NetIds) {
<option value="@netid.Id">@netid.Email</option>
}
</select>
</div>
<p><button class="ilw-button" @onclick="ChangeOwner">Change Owner</button></p>


</ilw-content>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class Security {

public string ApiGuid { get; set; } = "";

public int CurrentOwnerId { get; set; }
public List<string> Departments { get; set; } = [];
public DateTime LastDateApiChanged { get; set; }

Expand Down Expand Up @@ -76,10 +77,21 @@ public async Task InvalidateApi() {
UseApi = false;
}

public async Task ChangeOwner() {
var source = await Layout.CheckSource();
if (await SecurityHelper.ChangeOwner(source, CurrentOwnerId)) {
if (NetIds.Any(a => a.IsOwner) && NetIds.Any(a => a.Id == CurrentOwnerId)) {
NetIds.First(a => a.IsOwner).IsOwner = false;
NetIds.First(a => a.Id == CurrentOwnerId).IsOwner = true;
}
await Layout.AddMessage("The Owner has been changed");
}
}

public async Task Remove(string netId) {
var source = await Layout.CheckSource();
if (await SecurityHelper.RemoveName(source, netId)) {
NetIds.Remove(NetIds.FirstOrDefault(n => n.Email == netId));
NetIds.Remove(NetIds.FirstOrDefault(n => n.Email == netId) ?? new SecurityEntry());
}
var email = await UserHelper.GetUser(AuthenticationStateProvider);
if (netId == email) {
Expand All @@ -96,6 +108,7 @@ protected override async Task OnInitializedAsync() {
NetIds = await SecurityHelper.GetNames(source);
(UseApi, LastDateApiChanged, ApiDraft) = await ApiHelper.GetApi(source);
Layout.SetSidebar(SidebarEnum.Configuration, "Configuration");
CurrentOwnerId = NetIds.FirstOrDefault(n => n.IsOwner)?.Id ?? 0;
Departments = [.. (await FilterHelper.GetFilters(source, TagType.Department)).TagSources.Select(ts => ts.Title)];
}
}
Expand Down
6 changes: 4 additions & 2 deletions ResourceInformationV2/Components/Pages/ContactUs/About.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<h2>Resources</h2>
<p>To get help with the resource repository, contact Bryan Jonker at <a href="mailto:jonker@illinois.edu">jonker@illinois.edu</a>. </p>

<p>To report a bug or request an enhancement, go to <a href="https://go.illinois.edu/itpartners-resource-help">our GitHub repository and create an issue</a>. This will log the issue so we can review it. Note that this application is meant for campus, which means we cannot customize it to a specific unit unless others will benefit from the change.</p>
<p>The Resource API allows you to pull this information into your webpage. If you want to see the details of the API, see our <a href="https://resourceapi.wigg.illinois.edu/api/swagger/ui">API Documentation</a>.</p>

<p>This application is meant to be used with the Illinois Toolkit, although there's no reason why you cannot use this application alone. The <a href="https://builder3.toolkit.illinois.edu">Toolkit Builder</a> will have examples of how this can be integrated with the toolkit.</p>
<p>To report a bug or request an enhancement, go to <a href="https://go.illinois.edu/itpartners-resource-help">our GitHub repository and create an issue</a>. This will log the issue so we can review it. Note that this application is meant for campus, which means we cannot customize it to a specific unit unless others will benefit from the change.</p>

<p>We are also working on enhancements and documentation for this. To see the project status of individual items, you can look at <a href="https://github.com/orgs/web-illinois/projects/17/">our GitHub project status board</a>.</p>

<p>This application is meant to be used with the Illinois Toolkit, although there's no reason why you cannot use this application alone. The <a href="https://builder3.toolkit.illinois.edu">Toolkit Builder</a> will have examples of how this can be integrated with the toolkit.</p>

<h2>About This Project</h2>

<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Text;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using ResourceInformationV2.Components.Layout;
using ResourceInformationV2.Data.DataHelpers;
using ResourceInformationV2.Data.PageList;
using ResourceInformationV2.Search.Getters;
using ResourceInformationV2.Search.Models;
using System.Text;

namespace ResourceInformationV2.Components.Pages.Transfer {

Expand Down Expand Up @@ -88,7 +88,7 @@ private async Task Download() {
default:
break;
}
var fileStream = new MemoryStream(Encoding.ASCII.GetBytes(text));
using var fileStream = new MemoryStream(Encoding.UTF8.GetBytes(text));
using var streamRef = new DotNetStreamReference(fileStream);
await JsRuntime.InvokeVoidAsync("downloadFileFromStream", $"{source}_{DateTime.Now.ToString("yyyy_MM_dd")}_{SelectedOption.ToLowerInvariant()}.txt", streamRef);
await Layout.AddMessage("Text file downloaded successfully.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Text;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using ResourceInformationV2.Components.Layout;
using ResourceInformationV2.Data.DataHelpers;
using ResourceInformationV2.Data.PageList;
using ResourceInformationV2.Search.Helpers;
using ResourceInformationV2.Search.Models;
using System.Text;

namespace ResourceInformationV2.Components.Pages.Transfer {

Expand Down Expand Up @@ -40,9 +40,9 @@ private async Task Download() {
await Layout.AddMessage("JSON file being prepared -- this may take a while.");
var source = await Layout.CheckSource();

Enum.TryParse(SelectedOption, out UrlTypes urlType);
_ = Enum.TryParse(SelectedOption, out UrlTypes urlType);
var text = await JsonHelper.GetJsonFull(source, urlType);
var fileStream = new MemoryStream(Encoding.ASCII.GetBytes(text));
using var fileStream = new MemoryStream(Encoding.UTF8.GetBytes(text));
using var streamRef = new DotNetStreamReference(fileStream);
await JsRuntime.InvokeVoidAsync("downloadFileFromStream", $"{source}_{DateTime.Now.ToString("yyyy_MM_dd")}_{SelectedOption.ToLowerInvariant()}.json", streamRef);
await Layout.AddMessage("JSON file downloaded successfully.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ResourceInformationV2.Search.Helpers;
using ResourceInformationV2.Search.Models;
using ResourceInformationV2.Search.Setters;
using System.Text;

namespace ResourceInformationV2.Components.Pages.Transfer {

Expand Down Expand Up @@ -62,7 +63,8 @@ protected override async Task OnInitializedAsync() {
}

private async Task LoadFile(InputFileChangeEventArgs e) {
_reader = await new StreamReader(e.File.OpenReadStream(_maxFileSize)).ReadToEndAsync();
using var streamReader = new StreamReader(e.File.OpenReadStream(_maxFileSize), Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
_reader = await streamReader.ReadToEndAsync();
await Layout.AddMessage("File loaded for " + SelectedOption + " and ready to be uploaded");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ResourceInformationV2.Data.PageList;
using ResourceInformationV2.Search.Helpers;
using ResourceInformationV2.Search.Models;
using System.Text;

namespace ResourceInformationV2.Components.Pages.Transfer {

Expand Down Expand Up @@ -39,7 +40,8 @@ protected override async Task OnInitializedAsync() {
}

private async Task LoadFile(InputFileChangeEventArgs e) {
_reader = await new StreamReader(e.File.OpenReadStream(_maxFileSize)).ReadToEndAsync();
using var streamReader = new StreamReader(e.File.OpenReadStream(_maxFileSize), Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
_reader = await streamReader.ReadToEndAsync();
await Layout.AddMessage("File loaded for " + SelectedOption + " and ready to be uploaded");
}

Expand Down
Loading