Skip to content
Snippets Groups Projects

Sprint/2020-02

Merged Marcel Nellesen requested to merge Product/441-createProjectPage into Sprint/2020-02
1 file
+ 27
0
Compare changes
  • Side-by-side
  • Inline
@@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
using Coscine.ApiCommons;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
 
using Newtonsoft.Json.Linq;
using System;
using System;
using System.Linq;
using System.Linq;
@@ -47,5 +48,31 @@ namespace Coscine.Api.Project.Controllers
@@ -47,5 +48,31 @@ namespace Coscine.Api.Project.Controllers
return Unauthorized("User is not allowed to create a subproject for the given project id!");
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!");
 
}
 
}
}
}
}
}
Loading