Skip to content
Snippets Groups Projects
Commit 12cd6b0a authored by Benedikt Heinrichs's avatar Benedikt Heinrichs Committed by Petar Hristov
Browse files

Update: Overhaul PID handling

parent 91f0ea59
Branches
Tags
2 merge requests!38Release: Sprint/2022 17 :robot:,!37Update: Overhaul PID handling
......@@ -48,6 +48,64 @@ namespace Coscine.Api.Pid.Controllers
_visibilityModel = new VisibilityModel();
}
/// <summary>
/// Returns a 200, if a PID is valid.
/// </summary>
/// <param name="pid">PID</param>
/// <returns>200 if successful, 400 if pid is badly formatted, 403 if project or resource is deleted, 404 if not exists.</returns>
[HttpGet("[controller]/valid/{pid}")]
public IActionResult IsValid(string pid)
{
var id = Uri.UnescapeDataString(pid);
if (id.Contains('/'))
{
id = id[(id.IndexOf("/") + 1)..];
}
else
{
return BadRequest($"PID {pid} is badly formatted.");
}
if (id.Contains('@'))
{
id = id[..id.IndexOf("@")];
}
if (id.Contains('/'))
{
id = id[..id.IndexOf("/")];
}
Resource resource = null;
try
{
resource = _resourceModel.GetByIdIncludingDeleted(new Guid(id));
}
catch
{
}
Project project = null;
try
{
project = _projectModel.GetByIdIncludingDeleted(new Guid(id));
}
catch
{
}
if (resource == null && project == null)
{
return NotFound($"No project/resource with PID {pid} exists.");
}
if ((resource != null && resource.Deleted) || (project != null && project.Deleted))
{
return Forbid();
}
return Ok();
}
/// <summary>
/// Sends a request to the pid owner.
/// </summary>
......@@ -56,8 +114,38 @@ namespace Coscine.Api.Pid.Controllers
[HttpPost("[controller]/sendMailToOwner")]
public IActionResult SendMailToOwner([FromBody] MessageObject messageObject)
{
var resource = _resourceModel.GetById(new Guid(messageObject.Guid));
var project = _projectModel.GetById(new Guid(messageObject.Guid));
Resource resource = null;
try
{
resource = _resourceModel.GetByIdIncludingDeleted(new Guid(messageObject.Guid));
}
catch
{
}
Project project = null;
try
{
project = _projectModel.GetByIdIncludingDeleted(new Guid(messageObject.Guid));
}
catch
{
}
if (resource == null && project == null)
{
// Log the error.
// ProjectId and ResourceId will be null and indicate an error in the logs.
LogAnalyticsPidEnquiry(null, null, null, null, null, null, null, null);
return NotFound($"No project/resource with PID {messageObject.Pid} exists.");
}
if ((resource != null && resource.Deleted) || (project != null && project.Deleted))
{
return Forbid();
}
var user = new User()
{
DisplayName = messageObject.Name,
......@@ -108,13 +196,6 @@ namespace Coscine.Api.Pid.Controllers
var ownerId = _roleModel.GetAllWhere((x) => (x.DisplayName == "owner")).First().Id;
projectOwners = _projectRoleModel.GetAllWhere((x) => x.RoleId == ownerId && x.ProjectId == project.Id);
}
else
{
// Log the error.
// ProjectId and ResourceId will be null and indicate an error in the logs.
LogAnalyticsPidEnquiry(null, null, null, null, null, null, null, null);
return BadRequest("No project/resource with this pid exists.");
}
if (CoscineLoggerConfiguration.IsLogLevelActivated(LogType.Analytics))
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Pid.Models
namespace Coscine.Api.Pid.Models
{
/// <summary>
/// Message Object.
......
......@@ -17,7 +17,7 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coscine.Action" Version="2.*-*" />
<PackageReference Include="Coscine.Action" Version="3.*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
......
using Coscine.ApiCommons;
using Coscine.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Pid
{
......
using Coscine.ApiCommons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Pid
{
/// <summary>
/// Standard Startup class.
/// </summary>
public class Startup : AbstractDefaultStartup
public class Startup : AbstractStartup
{
/// <summary>
/// Standard Startup constructor.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment