Commit 824ba189 authored by Petar Hristov's avatar Petar Hristov 💬
Browse files

Merge branch 'Sprint/2021-13' into 'master'

Sprint/2021 13

See merge request !160
parents 22493dde 51522bc7
......@@ -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;
......
......@@ -23,5 +23,6 @@
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -23,5 +23,10 @@ namespace Coscine.Api.Project.ReturnObjects
/// How much space is availabe to be taken by resources (in gb).
/// </summary>
public int Allocated { get; set; }
/// <summary>
/// Maximum amount of quota (in gb).
/// </summary>
public int Maximum { get; set; }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment