Skip to content
Snippets Groups Projects
Commit 65ef3468 authored by Marius Politze's avatar Marius Politze
Browse files

fixes reference to new action emitter

parent 7405e79c
No related branches found
No related tags found
3 merge requests!33Sprint/201920,!32New: Modify SPGroups on User changes,!29Modify SPGroups on User changes (coscine/issues#430)
......@@ -11,25 +11,22 @@ 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 List<IProjectAction> _projectActions;
private readonly ProjectModel _projectModel;
private readonly IConfiguration _configuration;
private readonly Emitter _emitter;
public ProjectController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_projectActions = new List<IProjectAction>()
{
new PIDAction(),
new SharePointSiteAction(),
new SPGroupAction()
};
_configuration = Program.Configuration;
_projectModel = new ProjectModel();
_emitter = new Emitter(this._configuration);
}
[Route("[controller]")]
......@@ -165,17 +162,10 @@ namespace Coscine.Api.Project.Controllers
projectInstituteModel.Delete(projectInstitute);
}
FireEvents((projectAction, projectEventArgs) =>
_emitter.EmitProjectDelete(new ProjectEventArgs(_configuration)
{
try
{
projectAction.OnProjectDelete(project, projectEventArgs);
}
catch (Exception)
{
// Filter exception, because sometimes the PID or SharePoint site might not be generated in e.g. tests
}
}, null);
Project = project
});
_projectModel.Delete(project);
}
......@@ -196,19 +186,14 @@ namespace Coscine.Api.Project.Controllers
subProjectModel.LinkSubProject(projectObject.ParentId, project.Id);
}
FireEvents((projectAction, projectEventArgs) => projectAction.OnProjectCreate(project, projectEventArgs), user);
_emitter.EmitProjectCreate(new ProjectEventArgs(_configuration)
{
Project = project,
ProjectOwner = user
});
return _projectModel.CreateReturnObjectFromDatabaseObject(project);
}));
}
private void FireEvents(Action<IProjectAction, ProjectEventArgs> eventAction, User user)
{
ProjectEventArgs projectEventArgs = new ProjectEventArgs(Program.Configuration, new object[] { user });
foreach (var projectAction in _projectActions)
{
eventAction(projectAction, projectEventArgs);
}
}
}
}
......@@ -19,17 +19,16 @@ namespace Coscine.Api.Project.Controllers
public class ProjectRoleController : Controller
{
private readonly Authenticator _authenticator;
private readonly List<IUserAction> _userActions;
private readonly ProjectRoleModel _projectRoleModel;
private readonly Emitter _emitter;
private readonly Coscine.Configuration.IConfiguration _configuration;
public ProjectRoleController()
{
_emitter = new Emitter(Program.Configuration);
_authenticator = new Authenticator(this, Program.Configuration);
_userActions = new List<IUserAction>()
{
new SPGroupAction()
};
_projectRoleModel = new ProjectRoleModel();
_configuration = Program.Configuration;
}
[Route("[controller]/{projectId}")]
......@@ -104,7 +103,12 @@ namespace Coscine.Api.Project.Controllers
var userToAdd = userModel.GetById(projectRoleObject.User.Id);
if (projectModel.OwnsProject(user, project))
{
FireEvents((userAction, userEventArgs) => userAction.OnUserSet(userToAdd, project, role, userEventArgs));
_emitter.EmitUserAdd(new UserEventArgs(this._configuration)
{
Project = project,
Role = role,
User = userToAdd
});
return _projectRoleModel.SetFromObject(projectRoleObject);
}
else
......@@ -127,7 +131,12 @@ namespace Coscine.Api.Project.Controllers
var project = projectModel.GetById(projectId);
UserModel userModel = new UserModel();
var userToRemove = userModel.GetById(userId);
FireEvents((userAction, userEventArgs) => userAction.OnUserDelete(userToRemove, project, userEventArgs));
_emitter.EmitUserRemove(new UserEventArgs(this._configuration)
{
Project = project,
User = userToRemove
});
return _projectRoleModel.Delete(_projectRoleModel.GetWhere((projectRole) =>
projectRole.ProjectId == projectId
......@@ -140,14 +149,5 @@ namespace Coscine.Api.Project.Controllers
}
}));
}
private void FireEvents(Action<IUserAction, UserEventArgs> eventAction)
{
UserEventArgs userEventArgs = new UserEventArgs(Program.Configuration, new object[0]);
foreach (var userAction in _userActions)
{
eventAction(userAction, userEventArgs);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment