Skip to content
Snippets Groups Projects

Sprint/2021 13

Merged Petar Hristov requested to merge Sprint/2021-13 into master
3 files
+ 29
10
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -44,9 +44,6 @@ namespace Coscine.Api.Project.Controllers
private readonly InvitationModel _invitationModel;
private readonly RoleModel _roleModel;
private readonly UserModel _userModel;
private readonly int _maxAvailable = 100;
private readonly string _userUrlPrefix = "https://purl.org/coscine/users";
private readonly Uri _orgPrefixUrl = new Uri("http://www.w3.org/ns/org#");
private readonly RdfStoreConnector _rdfStoreConnector;
/// <summary>
@@ -213,10 +210,16 @@ namespace Coscine.Api.Project.Controllers
Id = x.Id,
Name = x.DisplayName,
Used = CalculateUsed(x, projectGuid),
Allocated = projectQuota == null ? 0 : projectQuota.Quota
Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota.MaxQuota
};
}
private int GetMaxQuota(Guid projectId, Guid resourceTypeId)
{
return _projectQuotaModel.GetWhere(x => x.ProjectId == projectId && x.ResourceTypeId == resourceTypeId).MaxQuota;
}
private int CalculateUsed(ResourceType resourceType, Guid projectId)
{
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
@@ -281,7 +284,8 @@ namespace Coscine.Api.Project.Controllers
Id = resourceTypeGuid,
Name = resourceType.DisplayName,
Used = CalculateUsed(resourceType, projectGuid),
Allocated = projectQuota.Quota
Allocated = projectQuota.Quota,
Maximum = projectQuota.MaxQuota
};
return Json(projectQuotaReturnObject);
@@ -327,7 +331,7 @@ namespace Coscine.Api.Project.Controllers
return NotFound($"Could not find resourceType with id: {resourceTypeId}");
}
return Json(new MaxProjectQuota { Id = resourceTypeGuid, Available = _maxAvailable });
return Json(new MaxProjectQuota { Id = resourceTypeGuid, Available = GetMaxQuota(projectGuid, resourceTypeGuid) });
}
/// <summary>
@@ -371,9 +375,16 @@ namespace Coscine.Api.Project.Controllers
return NotFound($"Could not find resourceType with id: {resourceTypeId}");
}
if (resourceType.DisplayName.Equals("rdss3"))
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
if (resourceTypeDefinition == null)
{
return BadRequest($"Cannot adjust quota for rdss3.");
return BadRequest($"No provider for: \"{resourceType.DisplayName}\".");
}
if (!resourceTypeDefinition.GetResourceTypeInformation().Result.IsQuotaAdjustable)
{
return BadRequest($"Cannot adjust quota for {resourceType.DisplayName}.");
}
if (updateProjectQuotaObject.Allocated < 0)
@@ -389,9 +400,11 @@ namespace Coscine.Api.Project.Controllers
return BadRequest($"Cannot set quota ({updateProjectQuotaObject.Allocated}) below the used value ({used}).");
}
if (updateProjectQuotaObject.Allocated > _maxAvailable)
var maxAvailabe = GetMaxQuota(projectGuid, resourceTypeGuid);
if (updateProjectQuotaObject.Allocated > maxAvailabe)
{
return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {_maxAvailable}");
return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {maxAvailabe}");
}
projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated;
Loading