Commit 60b8b558 authored by Petar Hristov's avatar Petar Hristov 💬
Browse files

Update: Setting Quota values by default (rpdm/issues#35)

parent 4981f221
......@@ -211,13 +211,14 @@ namespace Coscine.Api.Project.Controllers
Name = x.DisplayName,
Used = CalculateUsed(x, projectGuid),
Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota.MaxQuota
Maximum = projectQuota == null ? 0 : projectQuota.MaxQuota
};
}
private int GetMaxQuota(Guid projectId, Guid resourceTypeId)
{
return _projectQuotaModel.GetWhere(x => x.ProjectId == projectId && x.ResourceTypeId == resourceTypeId).MaxQuota;
var projectQuota = _projectQuotaModel.GetWhere(x => x.ProjectId == projectId && x.ResourceTypeId == resourceTypeId);
return projectQuota == null ? 0 : projectQuota.MaxQuota;
}
private int CalculateUsed(ResourceType resourceType, Guid projectId)
......@@ -284,8 +285,8 @@ namespace Coscine.Api.Project.Controllers
Id = resourceTypeGuid,
Name = resourceType.DisplayName,
Used = CalculateUsed(resourceType, projectGuid),
Allocated = projectQuota.Quota,
Maximum = projectQuota.MaxQuota
Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota == null ? 0 : projectQuota.MaxQuota
};
return Json(projectQuotaReturnObject);
......@@ -407,9 +408,24 @@ namespace Coscine.Api.Project.Controllers
return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {maxAvailabe}");
}
projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated;
_projectQuotaModel.Update(projectQuotaForCurrent);
var defaultQuotas = _rdfStoreConnector.GetQuotaDefault(user.Id.ToString());
var defaultQuota = defaultQuotas.FirstOrDefault(q => q.ResourceType == resourceType.DisplayName);
if (projectQuotaForCurrent == null)
{
var projectQuota = new ProjectQuota
{
MaxQuota = defaultQuota == null ? 0 : defaultQuota.DefaultMaxQuota,
Quota = defaultQuota == null ? 0 : defaultQuota.DefaultQuota,
ProjectId = project.Id,
ResourceTypeId = resourceType.Id
};
_projectQuotaModel.Insert(projectQuota);
}
else
{
projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated;
_projectQuotaModel.Update(projectQuotaForCurrent);
}
return NoContent();
}
......@@ -621,7 +637,7 @@ namespace Coscine.Api.Project.Controllers
Issuer = x.Issuer,
ProjectId = x.Project,
RoleId = x.Role,
UserMail = x.InviteeEmail
UserMail = x.InviteeEmail
});
return new ActionResult<IEnumerable<InvitationReturnObject>>(invitations);
......@@ -709,7 +725,7 @@ namespace Coscine.Api.Project.Controllers
{
var invitation = _invitationModel.GetById(invitationId);
if(invitation == null)
if (invitation == null)
{
return NotFound("Invitation was not found.");
}
......@@ -738,7 +754,7 @@ namespace Coscine.Api.Project.Controllers
var invitation = _invitationModel.GetByToken(token);
if(invitation == null)
if (invitation == null)
{
return NotFound("Invitation was not found.");
}
......@@ -795,7 +811,7 @@ namespace Coscine.Api.Project.Controllers
return false;
}
}
private void LogAnalyticsViewHome(List<string> projectIds)
{
_coscineLogger.AnalyticsLog(
......
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