Skip to content
Snippets Groups Projects

New: Get Project by Slug

Merged Petar Hristov requested to merge Issue/1957-resourceAppMigrationNew into uiv2
All threads resolved!
1 file
+ 66
38
Compare changes
  • Side-by-side
  • Inline
@@ -127,14 +127,42 @@ namespace Coscine.Api.Project.Controllers
@@ -127,14 +127,42 @@ namespace Coscine.Api.Project.Controllers
}
}
else
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>
/// <summary>
/// Gets the resources
/// Gets the resources
/// </summary>
/// </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>
/// <returns>JSON object or status code 401</returns>
[HttpGet("[controller]/{id}/resources")]
[HttpGet("[controller]/{id}/resources")]
public ActionResult<IEnumerable<ResourceObject>> GetResources(string id)
public ActionResult<IEnumerable<ResourceObject>> GetResources(string id)
@@ -160,30 +188,30 @@ namespace Coscine.Api.Project.Controllers
@@ -160,30 +188,30 @@ namespace Coscine.Api.Project.Controllers
}
}
else
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>
/// <summary>
/// Retrieves the quota for the selected project.
/// Retrieves the quota for the selected project.
/// </summary>
/// </summary>
/// <param name="projectId">Id of the project.</param>
/// <param name="id">Id of the project</param>
/// <returns>List of project quotas</returns>
/// <returns>List of project quotas</returns>
[HttpGet("[controller]/{projectId}/quota/-/all")]
[HttpGet("[controller]/{id}/quota/-/all")]
public ActionResult<IEnumerable<ProjectQuota>> Quotas(string projectId)
public ActionResult<IEnumerable<ProjectQuota>> Quotas(string id)
{
{
var user = _authenticator.GetUser();
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);
var project = _projectModel.GetById(projectGuid);
if (project == null)
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))
if (!_projectModel.HasAccess(user, project, UserRoles.Member, UserRoles.Owner))
@@ -234,24 +262,24 @@ namespace Coscine.Api.Project.Controllers
@@ -234,24 +262,24 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// <summary>
/// Retrieves the quota for the selected project and resource Type.
/// Retrieves the quota for the selected project and resource Type.
/// </summary>
/// </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>
/// <param name="resourceTypeId">Id of the resource type</param>
/// <returns>The project quota for the resource type.</returns>
/// <returns>The project quota for the resource type.</returns>
[HttpGet("[controller]/{projectId}/quota/{resourceTypeId}")]
[HttpGet("[controller]/{id}/quota/{resourceTypeId}")]
public ActionResult<ProjectQuotaReturnObject> Quota(string projectId, string resourceTypeId)
public ActionResult<ProjectQuotaReturnObject> Quota(string id, string resourceTypeId)
{
{
var user = _authenticator.GetUser();
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);
var project = _projectModel.GetById(projectGuid);
if (project == null)
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))
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -291,24 +319,24 @@ namespace Coscine.Api.Project.Controllers
@@ -291,24 +319,24 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// <summary>
/// Get the max quota for a resource type.
/// Get the max quota for a resource type.
/// </summary>
/// </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="resourceTypeId">Id of the resource</param>
/// <returns>The maximum value for the quota.</returns>
/// <returns>The maximum value for the quota.</returns>
[HttpGet("[controller]/{projectId}/quota/{resourceTypeId}/max")]
[HttpGet("[controller]/{id}/quota/{resourceTypeId}/max")]
public ActionResult<MaxProjectQuota> GetQuotaMax(string projectId, string resourceTypeId)
public ActionResult<MaxProjectQuota> GetQuotaMax(string id, string resourceTypeId)
{
{
var user = _authenticator.GetUser();
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);
var project = _projectModel.GetById(projectGuid);
if (project == null)
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))
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -334,25 +362,25 @@ namespace Coscine.Api.Project.Controllers
@@ -334,25 +362,25 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// <summary>
/// Update the project quota.
/// Update the project quota.
/// </summary>
/// </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="resourceTypeId">Id of the resource.</param>
/// <param name="updateProjectQuotaObject">Object containing the update values.</param>
/// <param name="updateProjectQuotaObject">Object containing the update values.</param>
/// <returns>NoContent (204).</returns>
/// <returns>NoContent (204).</returns>
[HttpPost("[controller]/{projectId}/quota/{resourceTypeId}")]
[HttpPost("[controller]/{id}/quota/{resourceTypeId}")]
public IActionResult UpdateQuota(string projectId, string resourceTypeId, [FromBody] UpdateProjectQuotaObject updateProjectQuotaObject)
public IActionResult UpdateQuota(string id, string resourceTypeId, [FromBody] UpdateProjectQuotaObject updateProjectQuotaObject)
{
{
var user = _authenticator.GetUser();
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);
var project = _projectModel.GetById(projectGuid);
if (project == null)
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))
if (!_projectModel.HasAccess(user, project, UserRoles.Owner))
@@ -619,7 +647,7 @@ namespace Coscine.Api.Project.Controllers
@@ -619,7 +647,7 @@ namespace Coscine.Api.Project.Controllers
/// <summary>
/// <summary>
/// List all invitations of a project.
/// List all invitations of a project.
/// </summary>
/// </summary>
/// <param name="projectId">Project id of the project</param>
/// <param name="projectId">Id of the project</param>
/// <returns>List of invitations</returns>
/// <returns>List of invitations</returns>
[HttpGet("[controller]/invitation/list/{projectId}")]
[HttpGet("[controller]/invitation/list/{projectId}")]
public ActionResult<IEnumerable<InvitationReturnObject>> ListInvitations(Guid projectId)
public ActionResult<IEnumerable<InvitationReturnObject>> ListInvitations(Guid projectId)
@@ -653,9 +681,9 @@ namespace Coscine.Api.Project.Controllers
@@ -653,9 +681,9 @@ namespace Coscine.Api.Project.Controllers
}
}
/// <summary>
/// <summary>
/// Create and send an invitation to specified mail.
/// Create and send a project invitation to a specified mail.
/// </summary>
/// </summary>
/// <param name="sendInvitationObject">Informations for sending an invitation</param>
/// <param name="sendInvitationObject">Informations for sending an invitation. The invitation token is stored inside the URL under ".../?invitationtoken={token}".</param>
/// <returns>NoContent</returns>
/// <returns>NoContent</returns>
[HttpPost("[controller]/invitation")]
[HttpPost("[controller]/invitation")]
public IActionResult SendInvitation([FromBody] SendInvitationObject sendInvitationObject)
public IActionResult SendInvitation([FromBody] SendInvitationObject sendInvitationObject)
@@ -714,7 +742,7 @@ namespace Coscine.Api.Project.Controllers
@@ -714,7 +742,7 @@ namespace Coscine.Api.Project.Controllers
{
{
["placeholder"] = new JObject()
["placeholder"] = new JObject()
{
{
["confirmation_link"] = $"{_configuration.GetString("coscine/local/api/additional/url")}/SitePages/Home.aspx?token={token}"
["confirmation_link"] = $"{_configuration.GetString("coscine/local/api/additional/url")}/?invitationtoken={token}"
}
}
}
}
};
};
@@ -725,9 +753,9 @@ namespace Coscine.Api.Project.Controllers
@@ -725,9 +753,9 @@ namespace Coscine.Api.Project.Controllers
}
}
/// <summary>
/// <summary>
/// Deletes an invitation.
/// Deletes a project invitation.
/// </summary>
/// </summary>
/// <param name="invitationId">Id of a invitation</param>
/// <param name="invitationId">Id of an invitation</param>
/// <returns>NoContent</returns>
/// <returns>NoContent</returns>
[HttpDelete("[controller]/invitation/{invitationId}")]
[HttpDelete("[controller]/invitation/{invitationId}")]
public IActionResult DeleteInvitation(Guid invitationId)
public IActionResult DeleteInvitation(Guid invitationId)
@@ -752,16 +780,16 @@ namespace Coscine.Api.Project.Controllers
@@ -752,16 +780,16 @@ namespace Coscine.Api.Project.Controllers
}
}
/// <summary>
/// <summary>
/// Resolve an invitation for the current user.
/// Resolve a project invitation for the current user.
/// </summary>
/// </summary>
/// <param name="token">Token of a invitation</param>
/// <param name="invitationToken">Token for a project invitation stored inside the URL under ".../?invitationtoken={token}"</param>
/// <returns>NoContent</returns>
/// <returns>NoContent</returns>
[HttpGet("[controller]/invitation/resolve/{token}")]
[HttpGet("[controller]/invitation/resolve/{invitationtoken}")]
public IActionResult ResolveInvitation(Guid token)
public IActionResult ResolveInvitation(Guid invitationToken)
{
{
var user = _authenticator.GetUser();
var user = _authenticator.GetUser();
var invitation = _invitationModel.GetByToken(token);
var invitation = _invitationModel.GetByToken(invitationToken);
if (invitation == null)
if (invitation == null)
{
{
Loading