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

BREAKING: Removed SharePoint from Actions (coscine/issues#1971)

parent 9c296a65
No related branches found
No related tags found
1 merge request!79BREAKING: Removed SharePoint Actions (coscine/issues#1971)
......@@ -6,8 +6,6 @@
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<!--Those here could be removed after the SharePoint problem is fixed. -->
<Reference Include="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
......
using Coscine.Action.EventArgs;
using Coscine.Api.LegacySharePoint.Models;
namespace Coscine.Action.Implementations.Project
{
internal class SharePointSiteAction : IProjectAction
{
public int Priority { get { return 1; } }
public bool Enabled { get { return true; } }
public void OnProjectCreate(ProjectEventArgs projectEventArgs)
{
SharePointEventObject sharePointEventObject = new SharePointEventObject
{
Role = "Owner",
UserId = projectEventArgs.ProjectOwner.Id.ToString(),
ProjectDescription = projectEventArgs.Project.Description,
ProjectDisplayName = projectEventArgs.Project.DisplayName,
ProjectSlug = projectEventArgs.Project.Slug
};
SharePointEventUtil.TriggerSharePointEvent(projectEventArgs.Configuration, "Site", "onProjectCreate", sharePointEventObject).Wait();
SharePointEventUtil.TriggerSharePointEvent(projectEventArgs.Configuration, "Group", "onUserSet", sharePointEventObject).Wait();
}
public void OnProjectDelete(ProjectEventArgs projectEventArgs)
{
SharePointEventObject sharePointEventObject = new SharePointEventObject
{
Role = "Owner",
UserId = projectEventArgs.ProjectOwner.Id.ToString(),
ProjectDescription = projectEventArgs.Project.Description,
ProjectDisplayName = projectEventArgs.Project.DisplayName,
ProjectSlug = projectEventArgs.Project.Slug
};
SharePointEventUtil.TriggerSharePointEvent(projectEventArgs.Configuration, "Site", "onProjectDelete", sharePointEventObject).Wait();
// Method for doing this would be to call the OnUserRemove method
// However since the site is already deleted in the SharePointSiteAction there is no need for it
}
}
}
using Coscine.Action.EventArgs;
using Coscine.Api.LegacySharePoint.Models;
namespace Coscine.Action.Implementations.User
{
internal class SPGroupAction : IUserAction
{
public int Priority { get { return 0; } }
public bool Enabled { get { return true; } }
public void OnUserSet(UserEventArgs userEventArgs)
{
SharePointEventObject sharePointEventObject = new SharePointEventObject
{
Role = userEventArgs.Role.DisplayName,
UserId = userEventArgs.User.Id.ToString(),
ProjectDescription = userEventArgs.Project.Description,
ProjectDisplayName = userEventArgs.Project.DisplayName,
ProjectSlug = userEventArgs.Project.Slug
};
SharePointEventUtil.TriggerSharePointEvent(userEventArgs.Configuration, "Group", "onUserSet", sharePointEventObject).Wait();
}
public void OnUserDelete(UserEventArgs userEventArgs)
{
SharePointEventObject sharePointEventObject = new SharePointEventObject
{
UserId = userEventArgs.User.Id.ToString(),
ProjectDescription = userEventArgs.Project.Description,
ProjectDisplayName = userEventArgs.Project.DisplayName,
ProjectSlug = userEventArgs.Project.Slug
};
SharePointEventUtil.TriggerSharePointEvent(userEventArgs.Configuration, "Group", "onUserDelete", sharePointEventObject).Wait();
}
}
}
using Coscine.Configuration;
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.LegacySharePoint.Models
{
public class SharePointEventUtil
{
private static HttpClient _httpClient = null;
private static HttpClient GetHttpClient()
{
if(_httpClient == null)
{
_httpClient = new HttpClient
{
Timeout = TimeSpan.FromMinutes(30)
};
}
return _httpClient;
}
public async static Task<HttpResponseMessage> TriggerSharePointEvent(IConfiguration configuration, string controller, string path, SharePointEventObject sharePointEventObject)
{
sharePointEventObject.SharePointSite = configuration.GetStringAndWait("coscine/local/sharepoint/additional/url");
sharePointEventObject.StsPrefix = configuration.GetStringAndWait("coscine/local/sharepoint/stsprefix");
var uri = $"http://localhost:{configuration.GetStringAndWait("coscine/apis/Coscine.Api.LegacySharePoint/port")}/{controller}/{path}";
HttpContent content = new StringContent(JsonConvert.SerializeObject(sharePointEventObject), Encoding.UTF8, "application/json");
return await GetHttpClient().PostAsync(uri, content);
}
}
public class SharePointEventObject
{
public string SharePointSite { get; set; }
public string ProjectDescription { get; set; }
public string ProjectDisplayName { get; set; }
public string ProjectSlug { get; set; }
public string StsPrefix { get; set; }
public string UserId { get; set; }
public string Role { get; set; }
public SharePointEventObject()
{
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment