Select Git revision
-
Marcel Nellesen authored
New: Change the Apps in order to incorporate the bilingual compatibility (coscine/issues#432)
Marcel Nellesen authoredNew: Change the Apps in order to incorporate the bilingual compatibility (coscine/issues#432)
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ProjectController.cs 8.12 KiB
using Coscine.Action;
using Coscine.Action.EventArgs;
using Coscine.Action.Implementations.Project;
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using Coscine.Database.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using Coscine.Configuration;
namespace Coscine.Api.Project.Controllers
{
public class ProjectController : Controller
{
private readonly Authenticator _authenticator;
private readonly ProjectModel _projectModel;
private readonly IConfiguration _configuration;
private readonly Emitter _emitter;
public ProjectController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_configuration = Program.Configuration;
_projectModel = new ProjectModel();
_emitter = new Emitter(this._configuration);
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _projectModel.GetAllWhere((project) =>
(from projectRole in project.ProjectRolesProjectIdIds
where projectRole.User == user
&& projectRole.Role.DisplayName == "Owner"
select projectRole).Any()
).Select((project) => _projectModel.CreateReturnObjectFromDatabaseObject(project));
}));
}
[HttpGet("[controller]/{id}")]
public IActionResult Get(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var project = _projectModel.GetById(Guid.Parse(id));
if (_projectModel.CanSeeProject(user, project))
{
return _projectModel.CreateReturnObjectFromDatabaseObject(project);
}
else
{
throw new UnauthorizedAccessException("User is not allowed to see given project Id!");
}
}));
}
[HttpGet("[controller]/{id}/resources")]
public IActionResult GetResources(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var project = _projectModel.GetById(Guid.Parse(id));
ResourceModel resourceModel = new ResourceModel();
ResourceTypeModel resourceTypeModel = new ResourceTypeModel();