Skip to content
Snippets Groups Projects
Commit 55518e9f authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'Hotfix/2427-adminTrouble' into 'master'

Fix: Scope returned resource types through the library

See merge request !45
parents e9e7dd10 1759175d
No related branches found
No related tags found
1 merge request!45Fix: Scope returned resource types through the library
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Coscine.Api.Admin</RootNamespace>
......@@ -10,17 +10,17 @@
<PropertyGroup>
<Authors>RWTH Aachen University</Authors>
<Company>IT Center, RWTH Aachen University</Company>
<Copyright>2022 IT Center, RWTH Aachen University</Copyright>
<Copyright>2023 IT Center, RWTH Aachen University</Copyright>
<Description>Admin is a part of the Coscine group.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://git.rwth-aachen.de/coscine/backend/apis/Admin</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coscine.Action" Version="2.*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="1.*-*" />
<PackageReference Include="Coscine.Action" Version="*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="*-*" />
<PackageReference Include="Coscine.Database" Version="*-*" />
<PackageReference Include="Coscine.Metadata" Version="*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="*-*" />
</ItemGroup>
</Project>
......@@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Coscine.Api.Admin.Controllers
......@@ -66,8 +67,8 @@ namespace Coscine.Api.Admin.Controllers
[HttpGet("[controller]/{projectString}")]
public ActionResult<AdminProjectObject> GetProject(string projectString)
{
var user = _authenticator.GetUserId();
if (!HasRole(user, _adminRole))
var user = _authenticator.GetUser();
if (!HasRole(user.Id.ToString(), _adminRole))
{
return Unauthorized($"User does not have the role \"{_adminRole}\".");
}
......@@ -88,7 +89,13 @@ namespace Coscine.Api.Admin.Controllers
return NotFound("Project was not found.");
}
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == project.Id);
var listOfResources = ResourceTypeFactory.Instance.GetSpecificResourceTypes().Select(x => x.SpecificTypeName);
var allResourceTypeIds = _resourceTypeModel.GetAllWhere((resourceType) => listOfResources.Contains(resourceType.SpecificType)).Select(e => e.Id).ToList();
var quotas = _projectQuotaModel.GetAllWhere(pq =>
pq.ProjectId == project.Id &&
allResourceTypeIds.Contains(pq.ResourceTypeId)
).ToList();
return new AdminProjectObject
{
......
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Metadata;
using System.Collections.Generic;
using System.Linq;
namespace Coscine.Api.Admin.Util;
internal class OrganizationsHelper
{
private static readonly ExternalIdModel _externalIdModel = new();
private static readonly RdfStoreConnector _rdfStoreConnector = new(Program.Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
public static IEnumerable<string> GetOrganization(User user)
{
// Bellow code taken from Organizations API
var externalIds = _externalIdModel.GetAllWhere((externalId) => externalId.UserId == user.Id);
var externalIdList = _externalIdModel.GetAllWhere((externalId) => externalId.UserId == user.Id).Select(x => x.ExternalId1).ToList();
var externalOrganizations = externalIds.Select((externalId) => externalId.Organization);
var triplesExternalIds = _rdfStoreConnector.GetTriples(null, null, null, 1, externalIdList);
var triplesExternalOrganizations = externalOrganizations.SelectMany(x => _rdfStoreConnector.GetOrganizationByEntityId(x));
return triplesExternalIds.Select(x => x.Subject.ToString())
.Concat(triplesExternalOrganizations.Select(x => x.Subject.ToString()))
.Distinct();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment