Skip to content
Snippets Groups Projects

Update: ProjectUpdate Method

Merged Petar Hristov requested to merge Issue/1971-projectForDev into dev
2 files
+ 77
49
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -127,14 +127,42 @@ namespace Coscine.Api.Project.Controllers
}
else
{
return Unauthorized($"User is not allowed to see given the project {id}");
return Unauthorized($"User has no access to a project with id: {id}");
}
}
/// <summary>
/// This returns the project if the user has access to it
/// </summary>
/// <param name="slug">Slug of the project</param>
/// <returns>OK or status code 401</returns>
[HttpGet("[controller]/slug/{slug}")]
public ActionResult<ProjectObject> GetBySlug(string slug)
{
var user = _authenticator.GetUser();
var project = _projectModel.GetBySlug(slug);
if (_projectModel.HasAccess(user, project, UserRoles.Member, UserRoles.Owner))
{
SubProjectModel subProjectModel = new SubProjectModel();
var subProjectRel = subProjectModel.GetAllWhere((subProject) => subProject.SubProjectId == project.Id && !project.Deleted);
var parentProjectRelation = subProjectRel.FirstOrDefault();
if (parentProjectRelation != null && _projectModel.HasAccess(user, parentProjectRelation.ProjectId, UserRoles.Member, UserRoles.Owner))
{
return Ok(_projectModel.CreateReturnObjectFromDatabaseObject(project, parentProjectRelation.ProjectId));
}
return Ok(_projectModel.CreateReturnObjectFromDatabaseObject(project));
}
else
{
return Unauthorized($"User has no access to a project with slug: {slug}");
}
}
/// <summary>
/// Gets the resources
/// </summary>
/// <param name="id">Id of the resource</param>
/// <param name="id">Id of the project</param>
/// <returns>JSON object or status code 401</returns>
[HttpGet("[controller]/{id}/resources")]
public ActionResult<IEnumerable<ResourceObject>> GetResources(string id)
@@ -160,30 +188,30 @@ namespace Coscine.Api.Project.Controllers
}
else
{
return Unauthorized($"User is not allowed to see given the project {id}");
return Unauthorized($"User has no access to a project with id: {id}");
}
}
/// <summary>
/// Retrieves the quota for the selected project.
/// </summary>
/// <param name="projectId">Id of the project.</param>
/// <param name="id">Id of the project</param>
/// <returns>List of project quotas</returns>
[HttpGet("[controller]/{projectId}/quota/-/all")]
public ActionResult<IEnumerable<ProjectQuotaReturnObject>> Quotas(string projectId)
[HttpGet("[controller]/{id}/quota/-/all")]
public ActionResult<IEnumerable<ProjectQuotaReturnObject>> Quotas(string id)
{
var user = _authenticator.GetUser();
if (!Guid.TryParse(projectId, out Guid projectGuid))
if (!Guid.TryParse(id, out Guid projectGuid))
{
return BadRequest($"{projectId} is not a GUID.");
return BadRequest($"{id} is not a GUID.");
}
var project = _projectModel.GetById(projectGuid);
if (project == null)
{
return NotFound($"Could not find project with id: {projectId}");
return NotFound($"Could not find project with id: {id}");
}
if (!_projectModel.HasAccess(user, project, UserRoles.Member, UserRoles.Owner))
@@ -234,24 +262,24 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Retrieves the quota for the selected project and resource Type.
/// </summary>
/// <param name="projectId">Id of the project</param>
/// <param name="id">Id of the project</param>
/// <param name="resourceTypeId">Id of the resource type</param>
/// <returns>The project quota for the resource type.</returns>
[HttpGet("[controller]/{projectId}/quota/{resourceTypeId}")]
public ActionResult<ProjectQuotaReturnObject> Quota(string projectId, string resourceTypeId)
[HttpGet("[controller]/{id}/quota/{resourceTypeId}")]
public ActionResult<ProjectQuotaReturnObject> Quota(string id, string resourceTypeId)
{
var user = _authenticator.GetUser();
if (!Guid.TryParse(projectId, out Guid projectGuid))
if (!Guid.TryParse(id, out Guid projectGuid))
{
return BadRequest($"{projectId} is not a GUID.");
return BadRequest($"{id} is not a GUID.");
}
var project = _projectModel.GetById(projectGuid);
if (project == null)
{
return NotFound($"Could not find project with id: {projectId}");
return NotFound($"Could not find project with id: {id}");
}
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -291,24 +319,24 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Get the max quota for a resource type.
/// </summary>
/// <param name="projectId">Id of the project.</param>
/// <param name="id">Id of the project.</param>
/// <param name="resourceTypeId">Id of the resource</param>
/// <returns>The maximum value for the quota.</returns>
[HttpGet("[controller]/{projectId}/quota/{resourceTypeId}/max")]
public ActionResult<MaxProjectQuota> GetQuotaMax(string projectId, string resourceTypeId)
[HttpGet("[controller]/{id}/quota/{resourceTypeId}/max")]
public ActionResult<MaxProjectQuota> GetQuotaMax(string id, string resourceTypeId)
{
var user = _authenticator.GetUser();
if (!Guid.TryParse(projectId, out Guid projectGuid))
if (!Guid.TryParse(id, out Guid projectGuid))
{
return BadRequest($"{projectId} is not a GUID.");
return BadRequest($"{id} is not a GUID.");
}
var project = _projectModel.GetById(projectGuid);
if (project == null)
{
return NotFound($"Could not find project with id: {projectId}");
return NotFound($"Could not find project with id: {id}");
}
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -334,25 +362,25 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Update the project quota.
/// </summary>
/// <param name="projectId">Id of the project.</param>
/// <param name="id">Id of the project.</param>
/// <param name="resourceTypeId">Id of the resource.</param>
/// <param name="updateProjectQuotaObject">Object containing the update values.</param>
/// <returns>NoContent (204).</returns>
[HttpPost("[controller]/{projectId}/quota/{resourceTypeId}")]
public IActionResult UpdateQuota(string projectId, string resourceTypeId, [FromBody] UpdateProjectQuotaObject updateProjectQuotaObject)
[HttpPost("[controller]/{id}/quota/{resourceTypeId}")]
public IActionResult UpdateQuota(string id, string resourceTypeId, [FromBody] UpdateProjectQuotaObject updateProjectQuotaObject)
{
var user = _authenticator.GetUser();
if (!Guid.TryParse(projectId, out Guid projectGuid))
if (!Guid.TryParse(id, out Guid projectGuid))
{
return BadRequest($"{projectId} is not a GUID.");
return BadRequest($"{id} is not a GUID.");
}
var project = _projectModel.GetById(projectGuid);
if (project == null)
{
return NotFound($"Could not find project with id: {projectId}");
return NotFound($"Could not find project with id: {id}");
}
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -434,14 +462,14 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Updates the selected project
/// </summary>
/// <param name="id">Id of the resource</param>
/// <param name="id">Id of the project</param>
/// <param name="projectObject">A Project Object</param>
/// <returns>OK or status code 401</returns>
[HttpPost("[controller]/{id}")]
public IActionResult Update(string id)
public IActionResult Update(Guid id, [FromBody] ProjectObject projectObject)
{
var user = _authenticator.GetUser();
var projectObject = ObjectFactory<ProjectObject>.DeserializeFromStream(Request.Body);
var project = _projectModel.GetById(Guid.Parse(id));
var project = _projectModel.GetById(id);
if (_projectModel.HasAccess(user, project, UserRoles.Owner))
{
LogAnalyticsEditProject(project, _projectModel.GetMetadataCompleteness(projectObject), projectObject.Disciplines, projectObject.Organizations, user);
@@ -456,7 +484,7 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Deletes the selected project
/// </summary>
/// <param name="id">Id of the resource</param>
/// <param name="id">Id of the project</param>
/// <returns>JSON object or status code 401</returns>
[HttpDelete("[controller]/{id}")]
public IActionResult Delete(string id)
@@ -575,14 +603,14 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// Creates a project
/// </summary>
/// <param name="projectObject">A Project Object</param>
/// <returns>JSON object or status code 401</returns>
[HttpPost("[controller]")]
public IActionResult Store()
public IActionResult Store([FromBody] ProjectObject projectObject)
{
var user = _authenticator.GetUser();
var projectObject = ObjectFactory<ProjectObject>.DeserializeFromStream(Request.Body);
if (projectObject?.ParentId != new Guid()
if (projectObject.ParentId != new Guid()
&& !_projectModel.HasAccess(user, _projectModel.GetById(projectObject.ParentId), UserRoles.Member, UserRoles.Owner))
{
return Unauthorized("User is not allowed to create SubProjects.");
@@ -754,14 +782,11 @@ namespace Coscine.Api.Project.Controllers
NotificationBusUtil.Send(Program.Configuration, "user_invitation", NotificationBusUtil.GetUserList(new User { EmailAddress = sendInvitationObject.Email }), sendInvitationObject.Project.ToString(), body);
if (Request.Query != null && Request.Query["noanalyticslog"] != "true")
{
LogAnalyticsInviteExternalUser(project, user);
}
return NoContent();
}
/// <summary>
/// Deletes an invitation.
/// </summary>
Loading