Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Fix/xxxx-resourceVisibility
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2427-adminTrouble
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/2001-extendAnalyticsLogger
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2309-docs
  • Issue/2330-fixNaNQuotainAdmin
  • Product/1119-quotaAdminPage
  • Product/1287-dotnet5Sharepoint
  • Product/1559-rdsS3QuotaManagement
  • Product/1600-rdsS3QuotaManagement
  • Product/1623-allocatedQuotaForAdmin
  • Sprint/2020-22
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-13
  • Sprint/2021-17
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Topic/1163-adminApi
  • Topic/1335-dotnet5Apis
  • Topic/1568-quotaApiAdjustments
  • Topic/1688-allocatedQuotaForAdminApi
  • dev
  • gitkeep
  • master
  • v1.1.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v3.0.0
  • v3.0.1
  • v3.0.2
  • v3.0.3
  • v3.0.4
  • v3.0.5
  • v3.0.6
  • v3.0.7
  • v3.0.8
68 results

Target

Select target project
  • coscine/backend/apis/admin
1 result
Select Git revision
  • Fix/xxxx-resourceVisibility
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2427-adminTrouble
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/2001-extendAnalyticsLogger
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2309-docs
  • Issue/2330-fixNaNQuotainAdmin
  • Product/1119-quotaAdminPage
  • Product/1287-dotnet5Sharepoint
  • Product/1559-rdsS3QuotaManagement
  • Product/1600-rdsS3QuotaManagement
  • Product/1623-allocatedQuotaForAdmin
  • Sprint/2020-22
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-13
  • Sprint/2021-17
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Topic/1163-adminApi
  • Topic/1335-dotnet5Apis
  • Topic/1568-quotaApiAdjustments
  • Topic/1688-allocatedQuotaForAdminApi
  • dev
  • gitkeep
  • master
  • v1.1.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v3.0.0
  • v3.0.1
  • v3.0.2
  • v3.0.3
  • v3.0.4
  • v3.0.5
  • v3.0.6
  • v3.0.7
  • v3.0.8
68 results
Show changes
Commits on Source (5)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<AssemblyName>Coscine.Api.Admin</AssemblyName> <AssemblyName>Coscine.Api.Admin</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<Version>2.3.2</Version> <Version>2.4.0</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<Authors>RWTH Aachen University</Authors> <Authors>RWTH Aachen University</Authors>
......
...@@ -6,14 +6,15 @@ using Coscine.ApiCommons; ...@@ -6,14 +6,15 @@ using Coscine.ApiCommons;
using Coscine.Configuration; using Coscine.Configuration;
using Coscine.Database.DataModel; using Coscine.Database.DataModel;
using Coscine.Database.Models; using Coscine.Database.Models;
using Coscine.Logging;
using Coscine.Metadata; using Coscine.Metadata;
using Coscine.ResourceLoader; using Coscine.ResourceLoader;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System; using System;
using System.Linq; using System.Linq;
namespace Coscine.Api.Admin.Controllers namespace Coscine.Api.Admin.Controllers
{ {
/// <summary> /// <summary>
...@@ -22,7 +23,7 @@ namespace Coscine.Api.Admin.Controllers ...@@ -22,7 +23,7 @@ namespace Coscine.Api.Admin.Controllers
[Authorize] [Authorize]
public class AdminController : Controller public class AdminController : Controller
{ {
private readonly RdfStoreConnector _rdfStoreConnector = new RdfStoreConnector(Program.Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url")); private readonly RdfStoreConnector _rdfStoreConnector = new(Program.Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
private readonly Authenticator _authenticator; private readonly Authenticator _authenticator;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly string _graphUrl; private readonly string _graphUrl;
...@@ -33,16 +34,17 @@ namespace Coscine.Api.Admin.Controllers ...@@ -33,16 +34,17 @@ namespace Coscine.Api.Admin.Controllers
private readonly string _adminRole; private readonly string _adminRole;
private readonly ResourceModel _resourceModel; private readonly ResourceModel _resourceModel;
private readonly ProjectModel _projectModel; private readonly ProjectModel _projectModel;
private readonly ProjectRoleModel _projectRoleModel;
private readonly ProjectQuotaModel _projectQuotaModel; private readonly ProjectQuotaModel _projectQuotaModel;
private readonly ResourceTypeModel _resourceTypeModel; private readonly ResourceTypeModel _resourceTypeModel;
private readonly Emitter _emitter; private readonly Emitter _emitter;
private readonly float _oneGb = 1024 * 1024 * 1024; private readonly float _oneGb = 1024 * 1024 * 1024;
private readonly CoscineLogger _coscineLogger;
/// <summary> /// <summary>
/// Default Constructor. /// Default Constructor.
/// </summary> /// </summary>
public AdminController() public AdminController(ILogger<AdminController> logger)
{ {
_authenticator = new Authenticator(this, Program.Configuration); _authenticator = new Authenticator(this, Program.Configuration);
_configuration = Program.Configuration; _configuration = Program.Configuration;
...@@ -54,16 +56,17 @@ namespace Coscine.Api.Admin.Controllers ...@@ -54,16 +56,17 @@ namespace Coscine.Api.Admin.Controllers
_adminRole = "supportAdmin"; _adminRole = "supportAdmin";
_resourceModel = new ResourceModel(); _resourceModel = new ResourceModel();
_projectModel = new ProjectModel(); _projectModel = new ProjectModel();
_projectRoleModel = new ProjectRoleModel();
_projectQuotaModel = new ProjectQuotaModel(); _projectQuotaModel = new ProjectQuotaModel();
_resourceTypeModel = new ResourceTypeModel(); _resourceTypeModel = new ResourceTypeModel();
_emitter = new Emitter(Program.Configuration); _emitter = new Emitter(Program.Configuration);
_coscineLogger = new CoscineLogger(logger);
} }
/// <summary> /// <summary>
/// Check if the user has a specific role. /// Check if the user has a specific role.
/// </summary> /// </summary>
/// <param name="userId">Id (guid) if the user.</param> /// <param name="userId">Id (GUID) if the user.</param>
/// <param name="role">The role of the user.</param> /// <param name="role">The role of the user.</param>
/// <returns>True if user has the role and false if not.</returns> /// <returns>True if user has the role and false if not.</returns>
private bool HasRole(string userId, string role) private bool HasRole(string userId, string role)
...@@ -82,12 +85,7 @@ namespace Coscine.Api.Admin.Controllers ...@@ -82,12 +85,7 @@ namespace Coscine.Api.Admin.Controllers
// Get the role based on the blank node and compare it to the requested role // Get the role based on the blank node and compare it to the requested role
var roleTriples = graph.GetTriplesWithSubjectPredicate(userSubject, graph.CreateUriNode(new Uri(_roleUrl))); var roleTriples = graph.GetTriplesWithSubjectPredicate(userSubject, graph.CreateUriNode(new Uri(_roleUrl)));
if (roleTriples?.FirstOrDefault()?.Object.ToString() != $"{_roleUrlPrefix}{role}") return (roleTriples?.FirstOrDefault()?.Object.ToString()) == _roleUrlPrefix + role;
{
return false;
}
return true;
} }
/// <summary> /// <summary>
...@@ -129,10 +127,10 @@ namespace Coscine.Api.Admin.Controllers ...@@ -129,10 +127,10 @@ namespace Coscine.Api.Admin.Controllers
} }
/// <summary> /// <summary>
/// Find the project related to the the projectString(Guid or slug) /// Find the project related to the projectString(GUID or slug)
/// </summary> /// </summary>
/// <param name="projectString">Either the id (guid) of the project or the slug.</param> /// <param name="projectString">Either the id (GUID) of the project or the slug.</param>
/// <returns>Json list of all quotas.</returns> /// <returns>JSON list of all quotas.</returns>
[HttpGet("[controller]/{projectString}")] [HttpGet("[controller]/{projectString}")]
public ActionResult<ProjectObject> GetProject(string projectString) public ActionResult<ProjectObject> GetProject(string projectString)
{ {
...@@ -147,7 +145,8 @@ namespace Coscine.Api.Admin.Controllers ...@@ -147,7 +145,8 @@ namespace Coscine.Api.Admin.Controllers
if (Guid.TryParse(projectString, out Guid guid)) if (Guid.TryParse(projectString, out Guid guid))
{ {
project = _projectModel.GetById(guid); project = _projectModel.GetById(guid);
} else }
else
{ {
project = _projectModel.GetBySlug(projectString); project = _projectModel.GetBySlug(projectString);
} }
...@@ -164,7 +163,8 @@ namespace Coscine.Api.Admin.Controllers ...@@ -164,7 +163,8 @@ namespace Coscine.Api.Admin.Controllers
GUID = project.Id, GUID = project.Id,
Name = project.ProjectName, Name = project.ProjectName,
ShortName = project.DisplayName, ShortName = project.DisplayName,
Quotas = quotas.Select(x => new ProjectQuotaObject { Quotas = quotas.Select(x => new ProjectQuotaObject
{
QuotaId = x.RelationId, QuotaId = x.RelationId,
ResourceType = _resourceTypeModel.GetById(x.ResourceTypeId).DisplayName, ResourceType = _resourceTypeModel.GetById(x.ResourceTypeId).DisplayName,
Quota = x.Quota, Quota = x.Quota,
...@@ -178,13 +178,13 @@ namespace Coscine.Api.Admin.Controllers ...@@ -178,13 +178,13 @@ namespace Coscine.Api.Admin.Controllers
/// <summary> /// <summary>
/// Update the project quota /// Update the project quota
/// </summary> /// </summary>
/// <param name="updateQuotaParameter">Json object for updatin quota.</param> /// <param name="updateQuotaParameter">JSON object for updating quota.</param>
/// <returns>NoContent (204) ond success.</returns> /// <returns>NoContent (204) on success.</returns>
[HttpPost("[controller]/")] [HttpPost("[controller]/")]
public IActionResult UpdateQuota([FromBody] UpdateQuotaParameterObject updateQuotaParameter) public IActionResult UpdateQuota([FromBody] UpdateQuotaParameterObject updateQuotaParameter)
{ {
var user = _authenticator.GetUserId(); var user = _authenticator.GetUser();
if (!HasRole(user, _adminRole)) if (!HasRole(user.Id.ToString(), _adminRole))
{ {
return Unauthorized($@"User has not the role: ""{_adminRole}""."); return Unauthorized($@"User has not the role: ""{_adminRole}"".");
} }
...@@ -203,7 +203,38 @@ namespace Coscine.Api.Admin.Controllers ...@@ -203,7 +203,38 @@ namespace Coscine.Api.Admin.Controllers
_emitter.EmitQuotaChanged(new AdminEventArgs(Program.Configuration) { ProjectId = projectQuota.ProjectId }); _emitter.EmitQuotaChanged(new AdminEventArgs(Program.Configuration) { ProjectId = projectQuota.ProjectId });
if (Request.Query != null && Request.Query["noanalyticslog"] != "true")
{
var project = _projectModel.GetById(projectQuota.ProjectId);
LogAnalyticsAdminProjectQuotaChange(project, user);
}
return NoContent(); return NoContent();
} }
private void LogAnalyticsAdminProjectQuotaChange(Project project, User user)
{
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == project.Id);
var quotaObjects = quotas.Select(x => new ProjectQuotaObject
{
QuotaId = x.RelationId,
ResourceType = _resourceTypeModel.GetById(x.ResourceTypeId).DisplayName,
Quota = x.Quota,
MaxQuota = x.MaxQuota,
Used = x.Quota,
Allocated = CalculateAllocatedForAll(_resourceTypeModel.GetById(x.ResourceTypeId), project.Id)
}).ToList();
_coscineLogger.AnalyticsLog(
new AnalyticsLogObject
{
Type = "Action",
Operation = "Admin Project Quota Change",
RoleId = _projectRoleModel.GetGetUserRoleForProject(project.Id, user.Id).ToString(),
UserId = user.Id.ToString(),
ProjectId = project.Id.ToString(),
QuotaSize = quotaObjects.ConvertAll(x => $"{x.ResourceType}: {x.Allocated}/{x.Used}")
});
}
} }
} }
\ No newline at end of file