Skip to content
Snippets Groups Projects
Commit 1b831330 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'dev' into 'master'

Release: Sprint/2022 17 :robot:

See merge request !92
parents eee8b2b7 70a81ba0
No related branches found
No related tags found
1 merge request!92Release: Sprint/2022 17 :robot:
...@@ -10,7 +10,7 @@ namespace Coscine.Action.Implementations.Admin ...@@ -10,7 +10,7 @@ namespace Coscine.Action.Implementations.Admin
public void OnQutaChanged(AdminEventArgs adminEventArgs) public void OnQutaChanged(AdminEventArgs adminEventArgs)
{ {
NotificationBusUtil.SendAsync(adminEventArgs.Configuration, "quota_changed", NotificationBusUtil.GetAllOwnersForProjectId(adminEventArgs.ProjectId), adminEventArgs.ProjectId.ToString(), new Newtonsoft.Json.Linq.JObject()); NotificationBusUtil.SendAsync(adminEventArgs.Configuration, "quota_changed", NotificationBusUtil.GetAllOwnersForProjectIdPacked(adminEventArgs.ProjectId), adminEventArgs.ProjectId.ToString(), new Newtonsoft.Json.Linq.JObject());
} }
} }
} }
...@@ -21,17 +21,18 @@ namespace Coscine.Action.Implementations.PID ...@@ -21,17 +21,18 @@ namespace Coscine.Action.Implementations.PID
var users = new JArray(); var users = new JArray();
string projectID = ""; string projectID = "";
string action = ""; string action = "";
// contacting owner of resource // contacting owner and creator of resource
if (pidEventArgs.Resource != null) if (pidEventArgs.Resource != null)
{ {
users = NotificationBusUtil.GetAllOwnersForResourceId(pidEventArgs.Resource.Id); users = NotificationBusUtil.GetAllOwnersAndCreatorForResourceId(pidEventArgs.Resource.Id);
projectID = NotificationBusUtil.GetProjectId(pidEventArgs.Resource.Id).ToString(); projectID = NotificationBusUtil.GetProjectId(pidEventArgs.Resource.Id).ToString();
action = "pid_contact_resource"; action = "pid_contact_resource";
} }
// contacting owner of project // contacting owner of project
else if (pidEventArgs.Project != null) else if (pidEventArgs.Project != null)
{ {
users = NotificationBusUtil.GetAllOwnersForProjectId(pidEventArgs.Project.Id); users = NotificationBusUtil.GetAllOwnersForProjectIdPacked(pidEventArgs.Project.Id);
projectID = pidEventArgs.Project.Id.ToString(); projectID = pidEventArgs.Project.Id.ToString();
action = "pid_contact_project"; action = "pid_contact_project";
} }
......
...@@ -65,9 +65,19 @@ namespace Coscine.Action.Utils ...@@ -65,9 +65,19 @@ namespace Coscine.Action.Utils
return GetAllUsersForProjectId(GetProjectId(resourceId)); return GetAllUsersForProjectId(GetProjectId(resourceId));
} }
public static JArray GetAllOwnersForResourceId(Guid resourceId) public static JArray GetAllOwnersAndCreatorForResourceId(Guid resourceId)
{ {
return GetAllOwnersForProjectId(GetProjectId(resourceId)); var owners = GetAllOwnersForProjectId(GetProjectId(resourceId)).ToList();
var resource = new ResourceModel().GetById(resourceId);
if (resource.Creator.HasValue)
{
if (!owners.Any((owner) => owner.Id == resource.Creator.Value))
{
var creator = new UserModel().GetById(resource.Creator.Value);
owners.Add(creator);
}
}
return JArray.FromObject(owners);
} }
public static JArray GetAllUsersForProjectId(Guid projectId) public static JArray GetAllUsersForProjectId(Guid projectId)
...@@ -82,17 +92,20 @@ namespace Coscine.Action.Utils ...@@ -82,17 +92,20 @@ namespace Coscine.Action.Utils
return JArray.FromObject(users.ToList()); return JArray.FromObject(users.ToList());
} }
public static JArray GetAllOwnersForProjectId(Guid projectId) public static IEnumerable<User> GetAllOwnersForProjectId(Guid projectId)
{ {
var users = new UserModel().GetAllWhere((user) => return new UserModel().GetAllWhere((user) =>
( (
from projectRole in user.ProjectRoles from projectRole in user.ProjectRoles
where projectRole.ProjectId == projectId where projectRole.ProjectId == projectId
&& projectRole.Role.DisplayName == "Owner" && projectRole.Role.DisplayName == "Owner"
select projectRole).Any() select projectRole).Any()
); );
}
return JArray.FromObject(users.ToList()); public static JArray GetAllOwnersForProjectIdPacked(Guid projectId)
{
return JArray.FromObject(GetAllOwnersForProjectId(projectId).ToList());
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment