Commit e1168fa9 authored by L. Ellenbeck's avatar L. Ellenbeck
Browse files

Update: max quota coscine/issues#1568

parent f15224d7
......@@ -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>
......@@ -389,9 +393,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,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