Skip to content
Snippets Groups Projects
Select Git revision
  • 62925642d4d421fdbc377cb0fb5117e3232d996b
  • master default protected
  • gitkeep
  • dev protected
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issue/2309-docs
  • Issue/2355-topLevelOrg
  • Issue/2328-noFailOnLog
  • Hotfix/2371-fixGitLabinRCV
  • Issue/2287-guestRole
  • Fix/xxxx-activateGitlab
  • Test/xxxx-enablingGitLab
  • Issue/2349-gitlabHttps
  • Issue/2259-updatePids
  • Issue/2101-gitLabResTypeUi
  • Hotfix/2202-fixNaNQuota
  • Issue/2246-quotaResoval
  • Issue/2221-projectDateCreated
  • Hotfix/2224-quotaSizeAnalytics
  • Fix/xxxx-resourceVisibility
  • Issue/2000-gitlabResourcesAPI
  • v4.4.3
  • v4.4.2
  • v4.4.1
  • v4.4.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
  • v4.3.0
  • v4.2.8
  • v4.2.7
  • v4.2.6
  • v4.2.5
  • v4.2.4
  • v4.2.3
  • v4.2.2
  • v4.2.1
  • v4.2.0
  • v4.1.1
  • v4.1.0
41 results

ProjectController.cs

Blame
  • 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();