Skip to content

Commit

Permalink
Update naming (#13)
Browse files Browse the repository at this point in the history
* Add MentoredUserIds to Membership
Remove AddressId
Make GetMemberhips call return User as well

* Update permissions

* update spacing

* constant adjustments
type names
UserPermissions userid
  • Loading branch information
ninjapiratica authored Dec 26, 2024
1 parent 0fa7708 commit 6d11fc6
Show file tree
Hide file tree
Showing 68 changed files with 2,923 additions and 3,095 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
namespace NP.Lti13Platform.AssignmentGradeServices.Configs
namespace NP.Lti13Platform.AssignmentGradeServices.Configs;

public class ServiceEndpointsConfig
{
public class ServiceEndpointsConfig
{
/// <summary>
/// Endpoint used to get a list of line items or create a new line item.
/// <para>Must include route parameters for {deploymentId} and {contextId}.</para>
/// </summary>
/// <value>Default: /lti13/{deploymentId}/{contextId}/lineItems</value>
public string LineItemsUrl { get; set; } = "/lti13/{deploymentId}/{contextId}/lineItems";
/// <summary>
/// Endpoint used to get a list of line items or create a new line item.
/// <para>Must include route parameters for {deploymentId} and {contextId}.</para>
/// </summary>
/// <value>Default: /lti13/{deploymentId}/{contextId}/lineItems</value>
public string LineItemsUrl { get; set; } = "/lti13/{deploymentId}/{contextId}/lineItems";

/// <summary>
/// Endpoint used to Get/Update/Delete a line item. Also used as the base url for getting results or posting scores.
/// <para>Must include route parameters for {deploymentId}, {contextId} and {lineItemId}.</para>
/// </summary>
/// <value>Default:/lti13/{deploymentId}/{contextId}/lineItems/{lineItemId}</value>
public string LineItemUrl { get; set; } = "/lti13/{deploymentId}/{contextId}/lineItems/{lineItemId}";
}
/// <summary>
/// Endpoint used to Get/Update/Delete a line item. Also used as the base url for getting results or posting scores.
/// <para>Must include route parameters for {deploymentId}, {contextId} and {lineItemId}.</para>
/// </summary>
/// <value>Default:/lti13/{deploymentId}/{contextId}/lineItems/{lineItemId}</value>
public string LineItemUrl { get; set; } = "/lti13/{deploymentId}/{contextId}/lineItems/{lineItemId}";
}
41 changes: 20 additions & 21 deletions NP.Lti13Platform.AssignmentGradeServices/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
namespace NP.Lti13Platform.AssignmentGradeServices
namespace NP.Lti13Platform.AssignmentGradeServices;

internal static class RouteNames
{
internal static class RouteNames
{
internal const string GET_LINE_ITEMS = "GET_LINE_ITEMS";
internal const string GET_LINE_ITEM = "GET_LINE_ITEM";
internal const string GET_LINE_ITEM_RESULTS = "GET_LINE_ITEM_RESULTS";
}
internal static readonly string GET_LINE_ITEMS = "GET_LINE_ITEMS";
internal static readonly string GET_LINE_ITEM = "GET_LINE_ITEM";
internal static readonly string GET_LINE_ITEM_RESULTS = "GET_LINE_ITEM_RESULTS";
}

internal static class ContentTypes
{
internal const string LineItemContainer = "application/vnd.ims.lis.v2.lineitemcontainer+json";
internal const string LineItem = "application/vnd.ims.lis.v2.lineitem+json";
internal const string ResultContainer = "application/vnd.ims.lis.v2.resultcontainer+json";
internal const string Score = "application/vnd.ims.lis.v1.score+json";
}
internal static class ContentTypes
{
internal static readonly string LineItemContainer = "application/vnd.ims.lis.v2.lineitemcontainer+json";
internal static readonly string LineItem = "application/vnd.ims.lis.v2.lineitem+json";
internal static readonly string ResultContainer = "application/vnd.ims.lis.v2.resultcontainer+json";
internal static readonly string Score = "application/vnd.ims.lis.v1.score+json";
}

public static class ServiceScopes
{
public const string LineItem = "https://purl.imsglobal.org/spec/lti-ags/scope/lineitem";
public const string LineItemReadOnly = "https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly";
public const string ResultReadOnly = "https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly";
public const string Score = "https://purl.imsglobal.org/spec/lti-ags/scope/score";
}
public static class ServiceScopes
{
public static readonly string LineItem = "https://purl.imsglobal.org/spec/lti-ags/scope/lineitem";
public static readonly string LineItemReadOnly = "https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly";
public static readonly string ResultReadOnly = "https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly";
public static readonly string Score = "https://purl.imsglobal.org/spec/lti-ags/scope/score";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,55 @@
using NP.Lti13Platform.Core.Services;
using System.Text.Json.Serialization;

namespace NP.Lti13Platform.AssignmentGradeServices.Populators
namespace NP.Lti13Platform.AssignmentGradeServices.Populators;

public interface IServiceEndpoints
{
public interface IServiceEndpoints
{
[JsonPropertyName("https://purl.imsglobal.org/spec/lti-ags/claim/endpoint")]
public LineItemServiceEndpoints? ServiceEndpoints { get; set; }
[JsonPropertyName("https://purl.imsglobal.org/spec/lti-ags/claim/endpoint")]
public LineItemServiceEndpoints? ServiceEndpoints { get; set; }

public class LineItemServiceEndpoints
{
[JsonPropertyName("scope")]
public required IEnumerable<string> Scopes { get; set; }
public class LineItemServiceEndpoints
{
[JsonPropertyName("scope")]
public required IEnumerable<string> Scopes { get; set; }

[JsonPropertyName("lineitems")]
public string? LineItemsUrl { get; set; }
[JsonPropertyName("lineitems")]
public string? LineItemsUrl { get; set; }

[JsonPropertyName("lineitem")]
public string? LineItemUrl { get; set; }
}
[JsonPropertyName("lineitem")]
public string? LineItemUrl { get; set; }
}
}

public class ServiceEndpointsPopulator(LinkGenerator linkGenerator, ILti13CoreDataService dataService, ILti13AssignmentGradeConfigService assignmentGradeService) : Populator<IServiceEndpoints>
public class ServiceEndpointsPopulator(LinkGenerator linkGenerator, ILti13CoreDataService dataService, ILti13AssignmentGradeConfigService assignmentGradeService) : Populator<IServiceEndpoints>
{
public override async Task PopulateAsync(IServiceEndpoints obj, MessageScope scope, CancellationToken cancellationToken = default)
{
public override async Task PopulateAsync(IServiceEndpoints obj, MessageScope scope, CancellationToken cancellationToken = default)
var lineItemScopes = scope.Tool.ServiceScopes
.Intersect([ServiceScopes.LineItem, ServiceScopes.LineItemReadOnly, ServiceScopes.ResultReadOnly, ServiceScopes.Score])
.ToList();

if (lineItemScopes.Count > 0 && scope.Context != null)
{
var lineItemScopes = scope.Tool.ServiceScopes
.Intersect([ServiceScopes.LineItem, ServiceScopes.LineItemReadOnly, ServiceScopes.ResultReadOnly, ServiceScopes.Score])
.ToList();
string? lineItemId = null;

if (lineItemScopes.Count > 0 && scope.Context != null)
if (scope.ResourceLink != null)
{
string? lineItemId = null;

if (scope.ResourceLink != null)
var lineItems = await dataService.GetLineItemsAsync(scope.Deployment.Id, scope.Context.Id, 0, 1, null, scope.ResourceLink.Id, null, cancellationToken);
if (lineItems.TotalItems == 1)
{
var lineItems = await dataService.GetLineItemsAsync(scope.Deployment.Id, scope.Context.Id, 0, 1, null, scope.ResourceLink.Id, null, cancellationToken);
if (lineItems.TotalItems == 1)
{
lineItemId = lineItems.Items.FirstOrDefault()?.Id;
}
lineItemId = lineItems.Items.FirstOrDefault()?.Id;
}
}

var config = await assignmentGradeService.GetConfigAsync(scope.Tool.ClientId, cancellationToken);
var config = await assignmentGradeService.GetConfigAsync(scope.Tool.ClientId, cancellationToken);

obj.ServiceEndpoints = new IServiceEndpoints.LineItemServiceEndpoints
{
Scopes = lineItemScopes,
LineItemsUrl = linkGenerator.GetUriByName(RouteNames.GET_LINE_ITEMS, new { deploymentId = scope.Deployment.Id, contextId = scope.Context.Id }, config.ServiceAddress.Scheme, new HostString(config.ServiceAddress.Authority)),
LineItemUrl = string.IsNullOrWhiteSpace(lineItemId) ? null : linkGenerator.GetUriByName(RouteNames.GET_LINE_ITEM, new { deploymentId = scope.Deployment.Id, contextId = scope.Context.Id, lineItemId }, config.ServiceAddress.Scheme, new HostString(config.ServiceAddress.Authority)),
};
}
obj.ServiceEndpoints = new IServiceEndpoints.LineItemServiceEndpoints
{
Scopes = lineItemScopes,
LineItemsUrl = linkGenerator.GetUriByName(RouteNames.GET_LINE_ITEMS, new { deploymentId = scope.Deployment.Id, contextId = scope.Context.Id }, config.ServiceAddress.Scheme, new HostString(config.ServiceAddress.Authority)),
LineItemUrl = string.IsNullOrWhiteSpace(lineItemId) ? null : linkGenerator.GetUriByName(RouteNames.GET_LINE_ITEM, new { deploymentId = scope.Deployment.Id, contextId = scope.Context.Id, lineItemId }, config.ServiceAddress.Scheme, new HostString(config.ServiceAddress.Authority)),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
using Microsoft.Extensions.Options;
using NP.Lti13Platform.AssignmentGradeServices.Configs;

namespace NP.Lti13Platform.AssignmentGradeServices.Services
namespace NP.Lti13Platform.AssignmentGradeServices.Services;

internal class DefaultAssignmentGradeConfigService(IOptionsMonitor<ServicesConfig> config, IHttpContextAccessor httpContextAccessor) : ILti13AssignmentGradeConfigService
{
internal class DefaultAssignmentGradeConfigService(IOptionsMonitor<ServicesConfig> config, IHttpContextAccessor httpContextAccessor) : ILti13AssignmentGradeConfigService
public async Task<ServicesConfig> GetConfigAsync(string clientId, CancellationToken cancellationToken = default)
{
public async Task<ServicesConfig> GetConfigAsync(string clientId, CancellationToken cancellationToken = default)
var servicesConfig = config.CurrentValue;
if (servicesConfig.ServiceAddress == ServicesConfig.DefaultUri)
{
var servicesConfig = config.CurrentValue;
if (servicesConfig.ServiceAddress == ServicesConfig.DefaultUri)
{
servicesConfig = servicesConfig with { ServiceAddress = new UriBuilder(httpContextAccessor.HttpContext?.Request.Scheme, httpContextAccessor.HttpContext?.Request.Host.Value).Uri };
}

return await Task.FromResult(servicesConfig);
servicesConfig = servicesConfig with { ServiceAddress = new UriBuilder(httpContextAccessor.HttpContext?.Request.Scheme, httpContextAccessor.HttpContext?.Request.Host.Value).Uri };
}

return await Task.FromResult(servicesConfig);
}
}
Loading

0 comments on commit 6d11fc6

Please sign in to comment.