Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Commit 4db68b64 authored by David Schimmel's avatar David Schimmel
Browse files

Resolve merge conflict

parents 97ec4c2f 0b9b1388
......@@ -55,8 +55,8 @@
<Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL">
<HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath>
</Reference>
<Reference Include="Coscine.Action, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.1.1\lib\net461\Coscine.Action.dll</HintPath>
<Reference Include="Coscine.Action, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.1.2\lib\net461\Coscine.Action.dll</HintPath>
</Reference>
<Reference Include="Coscine.ApiCommons, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ApiCommons.1.0.0\lib\net461\Coscine.ApiCommons.dll</HintPath>
......
......@@ -4,7 +4,7 @@
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" />
<package id="Castle.Core" version="4.4.0" targetFramework="net472" />
<package id="Consul" version="0.7.2.6" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.1" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.2" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.0.0" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.4.0" targetFramework="net472" />
......
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 System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class ProjectRoleController : Controller
{
private readonly Authenticator _authenticator;
private readonly ProjectRoleModel _projectRoleModel;
public ProjectRoleController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_projectRoleModel = new ProjectRoleModel();
}
[Route("[controller]/{projectId}")]
public IActionResult Index(string projectId)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
UserModel userModel = new UserModel();
RoleModel roleModel = new RoleModel();
ProjectModel projectModel = new ProjectModel();
Guid.TryParse(projectId, out Guid projectIdGuid);
if (projectModel.OwnsProject(user, projectModel.GetById(projectIdGuid)))
{
return _projectRoleModel.GetAllWhere((projectRole) =>
(projectRole.ProjectId == projectIdGuid)
).Select((projectRole) =>
{
User userInst = projectRole.User;
if (userInst == null)
{
userInst = userModel.GetById(projectRole.UserId);
}
Role role = projectRole.Role;
if (role == null)
{
role = roleModel.GetById(projectRole.RoleId);
}
return new ProjectRoleObject(projectRole.ProjectId, new UserObject(userInst.Id, userInst.DisplayName), new RoleObject(role.Id, role.DisplayName));
});
}
else
{
throw new UnauthorizedAccessException("User is not allowed to list all users to the given project!");
}
}));
}
[HttpPost("[controller]")]
public IActionResult Set()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectRoleObject projectRoleObject = ObjectFactory<ProjectRoleObject>.DeserializeFromStream(Request.Body);
ProjectModel projectModel = new ProjectModel();
if (projectModel.OwnsProject(user, projectModel.GetById(projectRoleObject.ProjectId)))
{
return _projectRoleModel.SetFromObject(projectRoleObject);
}
else
{
throw new NotAuthorizedException("The user is not authorized to store a project role to the given project!");
}
}));
}
[HttpDelete("[controller]/project/{projectId}/user/{userId}/role/{roleId}")]
public IActionResult Delete(Guid projectId, Guid userId, Guid roleId)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectModel projectModel = new ProjectModel();
if (projectModel.OwnsProject(user, projectModel.GetById(projectId)))
{
return _projectRoleModel.Delete(_projectRoleModel.GetWhere((projectRole) =>
projectRole.ProjectId == projectId
&& projectRole.UserId == userId
&& projectRole.RoleId == roleId));
}
else
{
throw new NotAuthorizedException("The user is not authorized to delete a project role for the given project!");
}
}));
}
}
}
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class RoleController : Controller
{
private readonly Authenticator _authenticator;
private readonly RoleModel _roleModel;
public RoleController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_roleModel = new RoleModel();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _roleModel.GetAll().Select((role) => new RoleObject(role.Id, role.DisplayName));
}));
}
}
}
using Coscine.ApiCommons.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Coscine.Api.Project.Models
......@@ -12,6 +14,27 @@ namespace Coscine.Api.Project.Models
{
}
public ProjectRole SetFromObject(ProjectRoleObject projectRoleObject)
{
// Remove existing roles if they exist
var existingRoles = GetAllWhere((dbProjectRole) => dbProjectRole.ProjectId == projectRoleObject.ProjectId && dbProjectRole.UserId == projectRoleObject.User.Id);
if(existingRoles.Count() > 0)
{
foreach(var role in existingRoles)
{
Delete(role);
}
}
ProjectRole projectRole = new ProjectRole()
{
ProjectId = projectRoleObject.ProjectId,
UserId = projectRoleObject.User.Id,
RoleId = projectRoleObject.Role.Id
};
Insert(projectRole);
return projectRole;
}
public override Expression<Func<ProjectRole, Guid>> GetIdFromObject()
{
......
......@@ -45,8 +45,8 @@
<Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL">
<HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath>
</Reference>
<Reference Include="Coscine.Action, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.1.1\lib\net461\Coscine.Action.dll</HintPath>
<Reference Include="Coscine.Action, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.1.2\lib\net461\Coscine.Action.dll</HintPath>
</Reference>
<Reference Include="Coscine.ApiCommons, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ApiCommons.1.0.0\lib\net461\Coscine.ApiCommons.dll</HintPath>
......@@ -566,7 +566,9 @@
<Compile Include="Controllers\ProjectController.cs" />
<Compile Include="Controllers\ResourceController.cs" />
<Compile Include="Controllers\ResourceTypeController.cs" />
<Compile Include="Controllers\RoleController.cs" />
<Compile Include="Controllers\SubProjectController.cs" />
<Compile Include="Controllers\ProjectRoleController.cs" />
<Compile Include="Models\ProjectModel.cs" />
<Compile Include="Models\ProjectResourceModel.cs" />
<Compile Include="Models\ProjectRoleModel.cs" />
......@@ -578,8 +580,11 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReturnObjects\ProjectObject.cs" />
<Compile Include="ReturnObjects\ProjectRoleObject.cs" />
<Compile Include="ReturnObjects\ResourceObject.cs" />
<Compile Include="ReturnObjects\ResourceTypeObject.cs" />
<Compile Include="ReturnObjects\RoleObject.cs" />
<Compile Include="ReturnObjects\UserObject.cs" />
<Compile Include="Startup.cs" />
</ItemGroup>
<ItemGroup>
......
using Coscine.ApiCommons.ReturnObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.ReturnObjects
{
[Serializable]
public class ProjectRoleObject : IReturnObject
{
public Guid ProjectId { get; set; }
public UserObject User { get; set; }
public RoleObject Role { get; set; }
public ProjectRoleObject(Guid projectId, UserObject user, RoleObject role)
{
ProjectId = projectId;
User = user;
Role = role;
}
}
}
using Coscine.ApiCommons.ReturnObjects;
using System;
namespace Coscine.Api.Project.ReturnObjects
{
[Serializable]
public class RoleObject : IReturnObject
{
public Guid Id { get; set; }
public string DisplayName { get; set; }
public RoleObject(Guid id, string displayName)
{
Id = id;
DisplayName = displayName;
}
}
}
\ No newline at end of file
using Coscine.ApiCommons.ReturnObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.ReturnObjects
{
[Serializable]
public class UserObject : IReturnObject
{
public Guid Id { get; set; }
public string DisplayName { get; set; }
public UserObject(Guid id, string displayName)
{
Id = id;
DisplayName = displayName;
}
}
}
......@@ -3,7 +3,7 @@
<package id="AutoMapper" version="8.0.0" targetFramework="net472" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" />
<package id="Consul" version="0.7.2.6" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.1" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.2" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.0.0" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.4.0" targetFramework="net472" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment