Commit e85c05db authored by Petar Hristov's avatar Petar Hristov 💬
Browse files

Merge branch 'Topic/1714-newResourceTypesUDE' into 'Product/1629-onboardingOtherUniversities'

Topic/1714 new resource types ude

See merge request !166
parents 4981f221 1c91eb52
...@@ -211,13 +211,14 @@ namespace Coscine.Api.Project.Controllers ...@@ -211,13 +211,14 @@ namespace Coscine.Api.Project.Controllers
Name = x.DisplayName, Name = x.DisplayName,
Used = CalculateUsed(x, projectGuid), Used = CalculateUsed(x, projectGuid),
Allocated = projectQuota == null ? 0 : projectQuota.Quota, Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota.MaxQuota Maximum = projectQuota == null ? 0 : projectQuota.MaxQuota
}; };
} }
private int GetMaxQuota(Guid projectId, Guid resourceTypeId) 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) private int CalculateUsed(ResourceType resourceType, Guid projectId)
...@@ -284,8 +285,8 @@ namespace Coscine.Api.Project.Controllers ...@@ -284,8 +285,8 @@ namespace Coscine.Api.Project.Controllers
Id = resourceTypeGuid, Id = resourceTypeGuid,
Name = resourceType.DisplayName, Name = resourceType.DisplayName,
Used = CalculateUsed(resourceType, projectGuid), Used = CalculateUsed(resourceType, projectGuid),
Allocated = projectQuota.Quota, Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota.MaxQuota Maximum = projectQuota == null ? 0 : projectQuota.MaxQuota
}; };
return Json(projectQuotaReturnObject); return Json(projectQuotaReturnObject);
...@@ -407,9 +408,24 @@ namespace Coscine.Api.Project.Controllers ...@@ -407,9 +408,24 @@ namespace Coscine.Api.Project.Controllers
return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {maxAvailabe}"); return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {maxAvailabe}");
} }
projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated; var defaultQuotas = _rdfStoreConnector.GetQuotaDefault(user.Id.ToString());
_projectQuotaModel.Update(projectQuotaForCurrent); 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(); return NoContent();
} }
...@@ -570,7 +586,20 @@ namespace Coscine.Api.Project.Controllers ...@@ -570,7 +586,20 @@ namespace Coscine.Api.Project.Controllers
return Unauthorized("User is not allowed to create SubProjects."); return Unauthorized("User is not allowed to create SubProjects.");
} }
var project = _projectModel.StoreFromObject(projectObject, user, _rdfStoreConnector.GetQuotaDefault(user.Id.ToString())); var defaultQuotas = _rdfStoreConnector.GetQuotaDefault(user.Id.ToString());
var projectQuotas = defaultQuotas.Select(defaulQuota =>
{
var resourceType = _resourceTypeModel.GetWhere(resourceType => resourceType.DisplayName == defaulQuota.ResourceType);
return new ProjectQuota
{
MaxQuota = defaulQuota.DefaultMaxQuota,
Quota = defaulQuota.DefaultQuota,
ResourceTypeId = resourceType.Id
};
});
var project = _projectModel.StoreFromObject(projectObject, user, projectQuotas);
if (projectObject.ParentId != new Guid() if (projectObject.ParentId != new Guid()
// Both an owner and a member can add subprojects to projects // Both an owner and a member can add subprojects to projects
...@@ -621,7 +650,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -621,7 +650,7 @@ namespace Coscine.Api.Project.Controllers
Issuer = x.Issuer, Issuer = x.Issuer,
ProjectId = x.Project, ProjectId = x.Project,
RoleId = x.Role, RoleId = x.Role,
UserMail = x.InviteeEmail UserMail = x.InviteeEmail
}); });
return new ActionResult<IEnumerable<InvitationReturnObject>>(invitations); return new ActionResult<IEnumerable<InvitationReturnObject>>(invitations);
...@@ -709,7 +738,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -709,7 +738,7 @@ namespace Coscine.Api.Project.Controllers
{ {
var invitation = _invitationModel.GetById(invitationId); var invitation = _invitationModel.GetById(invitationId);
if(invitation == null) if (invitation == null)
{ {
return NotFound("Invitation was not found."); return NotFound("Invitation was not found.");
} }
...@@ -738,7 +767,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -738,7 +767,7 @@ namespace Coscine.Api.Project.Controllers
var invitation = _invitationModel.GetByToken(token); var invitation = _invitationModel.GetByToken(token);
if(invitation == null) if (invitation == null)
{ {
return NotFound("Invitation was not found."); return NotFound("Invitation was not found.");
} }
...@@ -795,7 +824,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -795,7 +824,7 @@ namespace Coscine.Api.Project.Controllers
return false; return false;
} }
} }
private void LogAnalyticsViewHome(List<string> projectIds) private void LogAnalyticsViewHome(List<string> projectIds)
{ {
_coscineLogger.AnalyticsLog( _coscineLogger.AnalyticsLog(
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Coscine.Action" Version="2.*-*" /> <PackageReference Include="Coscine.Action" Version="2.*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" /> <PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" /> <PackageReference Include="Coscine.Database" Version="2.6.0-issues-0028-maxq0002" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" /> <PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" /> <PackageReference Include="Coscine.Metadata" Version="2.3.0-issues-0028-maxq0002" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" /> <PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" /> <PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
</ItemGroup> </ItemGroup>
......
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