...
 
Commits (3)
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Project.Tests is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Project.Tests")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1.0")]
[assembly: AssemblyCopyright("2019 IT Center, RWTH Aachen University")]
......@@ -85,6 +85,8 @@ namespace Coscine.Api.Project.Controllers
ProjectModel projectModel = new ProjectModel();
if (projectModel.OwnsProject(user, projectModel.GetById(projectId)))
{
_projectRoleModel.CheckIfLastOwnerWillBeRemoved(roleId, projectId);
return _projectRoleModel.Delete(_projectRoleModel.GetWhere((projectRole) =>
projectRole.ProjectId == projectId
&& projectRole.UserId == userId
......
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
......@@ -18,11 +19,13 @@ 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)
var existingRoles = GetAllWhere((dbProjectRole) => dbProjectRole.ProjectId == projectRoleObject.ProjectId && dbProjectRole.UserId == projectRoleObject.User.Id);
if (existingRoles.Count() > 0)
{
foreach(var role in existingRoles)
{
CheckIfLastOwnerWillBeRemoved(role.RoleId, projectRoleObject.ProjectId);
Delete(role);
}
}
......@@ -36,6 +39,24 @@ namespace Coscine.Api.Project.Models
return projectRole;
}
public void CheckIfLastOwnerWillBeRemoved(Guid roleId, Guid projectId)
{
RoleModel roleModel = new RoleModel();
var ownerRole = roleModel.GetOwnerRole();
if (roleId == ownerRole.Id)
{
var moreThanOneOwnerExists = GetAllWhere((projectRole) =>
projectRole.ProjectId == projectId
&& projectRole.RoleId == ownerRole.Id
).Count() > 1;
if (!moreThanOneOwnerExists)
{
throw new NotAuthorizedException("The last owner cannot be removed!");
}
}
}
public override Expression<Func<ProjectRole, Guid>> GetIdFromObject()
{
return databaseObject => databaseObject.RelationId;
......
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Project is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Project")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1.0")]
[assembly: AssemblyCopyright("2019 IT Center, RWTH Aachen University")]