Skip to content

Commit

Permalink
Merge pull request #1066 from gordon-cs/security-hotfix-schedule-access
Browse files Browse the repository at this point in the history
Add SYB to schedules
  • Loading branch information
EjPlatzer authored Sep 11, 2024
2 parents 6cfdf8d + e5f12b6 commit 18bc5bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Gordon360/Authorization/StateYourBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class StateYourBusiness : ActionFilterAttribute
private IMembershipService _membershipService;
private IMembershipRequestService _membershipRequestService;
private INewsService _newsService;
private IAccountService _accountService;

//RecIM services
private IParticipantService _recimParticipantService;
Expand All @@ -64,12 +65,13 @@ public async override Task OnActionExecutionAsync(ActionExecutingContext actionC
_membershipRequestService = context.HttpContext.RequestServices.GetRequiredService<IMembershipRequestService>();
_newsService = context.HttpContext.RequestServices.GetRequiredService<INewsService>();
_CCTContext = context.HttpContext.RequestServices.GetService<CCTContext>();

Check warning on line 67 in Gordon360/Authorization/StateYourBusiness.cs

View workflow job for this annotation

GitHub Actions / deploy-prod

Possible null reference assignment.
_accountService = context.HttpContext.RequestServices.GetRequiredService<IAccountService>();

// set RecIM services
_recimParticipantService = context.HttpContext.RequestServices.GetRequiredService<IParticipantService>();
_recimTeamService = context.HttpContext.RequestServices.GetRequiredService<ITeamService>();
_recimActivityService = context.HttpContext.RequestServices.GetRequiredService<Services.RecIM.IActivityService>();

user_name = AuthUtils.GetUsername(authenticatedUser);
user_groups = AuthUtils.GetGroups(authenticatedUser);

Expand Down Expand Up @@ -187,6 +189,10 @@ private async Task<bool> CanReadOneAsync(string resource)
}
case Resource.NEWS:
return true;
case Resource.STUDENT_SCHEDULE:
if (context.ActionArguments["username"] is string viewed_username)
return user_groups.Contains(AuthGroup.Advisors) || viewed_username.EqualsIgnoreCase(user_name) || _accountService.GetAccountByUsername(viewed_username).AccountType.EqualsIgnoreCase("FACULTY");
return false;
default: return false;

}
Expand Down
4 changes: 3 additions & 1 deletion Gordon360/Controllers/ScheduleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Gordon360.Enums;
using Gordon360.Models.ViewModels;
using Gordon360.Services;
using Gordon360.Static.Names;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,7 +11,7 @@
namespace Gordon360.Controllers;

[Route("api/[controller]")]
public class ScheduleController(IScheduleService scheduleService) : ControllerBase
public class ScheduleController(IScheduleService scheduleService) : GordonControllerBase
{

/// <summary>
Expand All @@ -19,6 +20,7 @@ public class ScheduleController(IScheduleService scheduleService) : ControllerBa
/// <returns>A IEnumerable of session objects as well as the schedules</returns>
[HttpGet]
[Route("{username}/allcourses")]
[StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.STUDENT_SCHEDULE)]
public async Task<ActionResult<CoursesBySessionViewModel>> GetAllCourses(string username)
{
IEnumerable<CoursesBySessionViewModel> result = await scheduleService.GetAllCoursesAsync(username);
Expand Down
1 change: 1 addition & 0 deletions Gordon360/Static Classes/Names.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class Resource
public const string RECIM_PARTICIPANT_ADMIN = "The admin status of a RecIM participating user";
public const string RECIM_SUPER_ADMIN = "A RecIM director level resource";
public const string RECIM_SURFACE = "RecIM Surfaces/Playing fields/Locations";
public const string STUDENT_SCHEDULE = "A student's schedule events";

// Partial resources, to be targetted by Operation.READ_PARTIAL
public const string MEMBERSHIP_REQUEST_BY_ACTIVITY = "Membership Request Resources associated with an activity";
Expand Down

0 comments on commit 18bc5bf

Please sign in to comment.