Skip to content
Snippets Groups Projects
Commit b8cbeaf9 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Topic/628-createProjectPage' into 'Product/441-createProjectPage'

New: Included function to get Id of ParentProject

See merge request coscine/api/project!67
parents 9c7c9a56 6a3dd5c7
No related branches found
No related tags found
2 merge requests!68Sprint/2020-02,!67New: Included function to get Id of ParentProject
......@@ -2,6 +2,7 @@
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
......@@ -47,5 +48,31 @@ namespace Coscine.Api.Project.Controllers
return Unauthorized("User is not allowed to create a subproject for the given project id!");
}
}
[HttpGet("[controller]/{childId}/accessibleParent")]
public IActionResult GetAccessibleParent(string childId)
{
var childGuid = new Guid(childId);
var projectModel = new ProjectModel();
var projectRoleModel = new ProjectRoleModel();
var user = _authenticator.GetUser();
string[] allowedRoles = { UserRoles.Owner, UserRoles.Member };
allowedRoles = allowedRoles.Select(x => x.ToLower().Trim()).ToArray();
if (projectModel.HasAccess(user, projectModel.GetById(childGuid), allowedRoles))
{
var subProjects = _subProjectModel.GetAllWhere((subProjectM) => (subProjectM.SubProjectId == childGuid)).ToArray();
var json = new JObject();
json["id"] = "00000000-0000-0000-0000-000000000000";
if (subProjects.Count() == 1 && projectModel.HasAccess(user, projectModel.GetById(subProjects[0].ProjectId), allowedRoles))
{
json["id"] = subProjects[0].ProjectId;
}
return Json(json);
}
else
{
return Unauthorized("User is not allowed to create a subproject for the given project id!");
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment