Commit 40f96fc8 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs

Update: Little Cleanup

parent a400c668
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
\ No newline at end of file
.ms-breadcrumb-top,
#SearchBox,
#suiteBarButtons,
#globalNavBox {
display: none !important;
}
#welcomeMenuBox {
margin-top: 5px;
}
body.rwth-seattle #s4-titlerow, .ms-breadcrumb-box {
height: auto !important;
}
......@@ -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.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.0.0\lib\net461\Coscine.Action.dll</HintPath>
<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>
<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>
......@@ -580,12 +580,6 @@
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.2\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.2\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="Features\Feature1\Feature1.Template.xml" />
<Content Include="Layouts\Coscine.SharePoint.Webparts.Vue\css\remove-sharepoint-controls.css" />
<Content Include="VueComponent\Elements.xml" />
<Content Include="VueComponent\VueComponentUserControl.ascx" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Module Name="VueComponent" List="113" Url="_catalogs/wp">
<File Path="VueComponent\VueComponent.webpart" Url="Coscine.SharePoint.Webparts.Vue_VueComponent.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="Custom" />
</File>
</Module>
</Elements>
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VueComponentUserControl.ascx.cs" Inherits="Coscine.SharePoint.Webparts.Vue.VueComponent.VueComponentUserControl" %>
<script type="text/javascript">
var coscine = coscine || {};
coscine.authorization = coscine.authorization || {};
coscine.authorization.bearer = "<%= GetUserJWT() %>";
window.component = "<%= GetComponent() %>";
</script>
\ No newline at end of file
......@@ -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.0.0" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.1" 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" />
......
......@@ -16,16 +16,18 @@ namespace Coscine.Api.Project.Controllers
public class ProjectController : Controller
{
private readonly Authenticator _authenticator;
private readonly List<IProjectAction> projectActions;
private readonly List<IProjectAction> _projectActions;
private readonly ProjectModel _projectModel;
public ProjectController()
{
_authenticator = new Authenticator(this, Program.Configuration);
projectActions = new List<IProjectAction>()
_projectActions = new List<IProjectAction>()
{
new PIDAction(),
new SharePointSiteAction()
};
_projectModel = new ProjectModel();
}
[Route("[controller]")]
......@@ -33,8 +35,7 @@ namespace Coscine.Api.Project.Controllers
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectModel projectModel = new ProjectModel();
return projectModel.GetAllWhere((project) =>
return _projectModel.GetAllWhere((project) =>
(from projectRole in project.ProjectRolesProjectIdIds
where projectRole.User == user
&& projectRole.Role.DisplayName == "Owner"
......@@ -48,9 +49,15 @@ namespace Coscine.Api.Project.Controllers
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectModel projectModel = new ProjectModel();
var project = projectModel.GetById(Guid.Parse(id));
return new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords);
var project = _projectModel.GetById(Guid.Parse(id));
if (_projectModel.CanSeeProject(user, project))
{
return new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords);
}
else
{
throw new UnauthorizedAccessException("User is not allowed to see given project Id!");
}
}));
}
......@@ -60,11 +67,10 @@ namespace Coscine.Api.Project.Controllers
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectObject projectObject = ObjectFactory<ProjectObject>.DeserializeFromStream(Request.Body);
ProjectModel projectModel = new ProjectModel();
var project = projectModel.GetById(Guid.Parse(id));
if(projectModel.OwnsProject(user, project))
var project = _projectModel.GetById(Guid.Parse(id));
if(_projectModel.OwnsProject(user, project))
{
return projectModel.UpdateByObject(project, projectObject);
return _projectModel.UpdateByObject(project, projectObject);
}
else
{
......@@ -79,12 +85,11 @@ namespace Coscine.Api.Project.Controllers
return base.Ok(_authenticator.ValidateAndExecute((user) =>
{
ProjectObject projectObject = ObjectFactory<ProjectObject>.DeserializeFromStream(Request.Body);
ProjectModel projectModel = new ProjectModel();
var project = projectModel.StoreFromObject(projectObject, user);
var project = _projectModel.StoreFromObject(projectObject, user);
if (projectObject.ParentId != null
&& projectObject.ParentId != new Guid()
&& projectModel.OwnsProject(user, projectModel.GetById(projectObject.ParentId))) // for now, only an owner can add subprojects to projects
&& _projectModel.OwnsProject(user, _projectModel.GetById(projectObject.ParentId))) // for now, only an owner can add subprojects to projects
{
SubProjectModel subProjectModel = new SubProjectModel();
subProjectModel.LinkSubProject(projectObject.ParentId, project.Id);
......@@ -99,7 +104,7 @@ namespace Coscine.Api.Project.Controllers
private void FireEvents(Action<IProjectAction, ProjectEventArgs> eventAction)
{
ProjectEventArgs projectEventArgs = new ProjectEventArgs(Program.Configuration, new object[0]);
foreach (var projectAction in projectActions)
foreach (var projectAction in _projectActions)
{
eventAction(projectAction, projectEventArgs);
}
......
......@@ -12,10 +12,12 @@ namespace Coscine.Api.Project.Controllers
public class ResourceController : Controller
{
private readonly Authenticator _authenticator;
private readonly ResourceModel _resourceModel;
public ResourceController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_resourceModel = new ResourceModel();
}
[Route("[controller]")]
......@@ -23,8 +25,7 @@ namespace Coscine.Api.Project.Controllers
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ResourceModel resourceModel = new ResourceModel();
return resourceModel.GetAllWhere((resource) =>
return _resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResourceResourceIdIds
where (from projectRole in projectResource.Project.ProjectRolesProjectIdIds
where projectRole.User == user
......@@ -41,9 +42,8 @@ namespace Coscine.Api.Project.Controllers
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ResourceModel resourceModel = new ResourceModel();
var resource = resourceModel.GetById(Guid.Parse(id));
if (resourceModel.OwnsResource(user, resource))
var resource = _resourceModel.GetById(Guid.Parse(id));
if (_resourceModel.OwnsResource(user, resource))
{
//TODO: Find out why resource.Type is not set
if(resource.Type == null)
......@@ -66,11 +66,10 @@ namespace Coscine.Api.Project.Controllers
return Ok(_authenticator.ValidateAndExecute((user) =>
{
ResourceObject resourceObject = ObjectFactory<ResourceObject>.DeserializeFromStream(Request.Body);
ResourceModel resourceModel = new ResourceModel();
var resource = resourceModel.GetById(Guid.Parse(id));
if (resourceModel.OwnsResource(user, resource))
var resource = _resourceModel.GetById(Guid.Parse(id));
if (_resourceModel.OwnsResource(user, resource))
{
return resourceModel.UpdateByObject(resource, resourceObject);
return _resourceModel.UpdateByObject(resource, resourceObject);
}
else
{
......@@ -90,8 +89,7 @@ namespace Coscine.Api.Project.Controllers
var project = projectModel.GetById(Guid.Parse(projectId));
if (projectModel.OwnsProject(user, project))
{
ResourceModel resourceModel = new ResourceModel();
var resource = resourceModel.StoreFromObject(resourceObject);
var resource = _resourceModel.StoreFromObject(resourceObject);
projectModel.AddResource(project, resource);
......
......@@ -10,25 +10,32 @@ namespace Coscine.Api.Project.Controllers
public class SubProjectController : Controller
{
private readonly Authenticator _authenticator;
private readonly SubProjectModel _subProjectModel;
public SubProjectController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_subProjectModel = new SubProjectModel();
}
[HttpGet("[controller]/{parentId}")]
public IActionResult Get(string parentId)
{
Guid parentGuid = new Guid(parentId);
return Ok(_authenticator.ValidateAndExecute((user) =>
{
Guid parentGuid = new Guid(parentId);
ProjectModel projectModel = new ProjectModel();
SubProjectModel subProjectModel = new SubProjectModel();
var subProjects = subProjectModel.GetAllWhere((subProjectM) => (subProjectM.ProjectId == parentGuid))
.Select((subProject) => projectModel.GetById(subProject.SubProjectId))
.Select((project) => new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords, parentGuid));
return subProjects;
if (projectModel.CanSeeProject(user, projectModel.GetById(parentGuid)))
{
var subProjects = _subProjectModel.GetAllWhere((subProjectM) => (subProjectM.ProjectId == parentGuid))
.Select((subProject) => projectModel.GetById(subProject.SubProjectId))
.Select((project) => new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords, parentGuid));
return subProjects;
}
else
{
throw new UnauthorizedAccessException("User is not allowed to create a subproject for the given project id!");
}
}));
}
}
......
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
\ No newline at end of file
.ms-breadcrumb-top,
#SearchBox,
#suiteBarButtons,
#globalNavBox {
display: none !important;
}
#welcomeMenuBox {
margin-top: 5px;
}
body.rwth-seattle #s4-titlerow, .ms-breadcrumb-box {
height: auto !important;
}
......@@ -47,6 +47,16 @@ namespace Coscine.Api.Project.Models
return projectRole;
}
public bool CanSeeProject(User user, Coscine.Database.Model.Project project)
{
return DatabaseConnection.ConnectToDatabase((db) => (from relation in db.ProjectRoles
where relation.Project == project
&& relation.User == user
&& (relation.Role.DisplayName == "Owner"
|| relation.Role.DisplayName == "Member")
select relation).Any());
}
public bool OwnsProject(User user, Coscine.Database.Model.Project project)
{
return DatabaseConnection.ConnectToDatabase((db) => (from relation in db.ProjectRoles
......
......@@ -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.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Action.1.0.0\lib\net461\Coscine.Action.dll</HintPath>
<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>
<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>
......@@ -588,12 +588,6 @@
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<Content Include="Features\Feature1\Feature1.Template.xml" />
<Content Include="Layouts\Coscine.SharePoint.Webparts.Vue\css\remove-sharepoint-controls.css" />
<Content Include="VueComponent\Elements.xml" />
<Content Include="VueComponent\VueComponentUserControl.ascx" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Module Name="VueComponent" List="113" Url="_catalogs/wp">
<File Path="VueComponent\VueComponent.webpart" Url="Coscine.SharePoint.Webparts.Vue_VueComponent.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="Custom" />
</File>
</Module>
</Elements>
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VueComponentUserControl.ascx.cs" Inherits="Coscine.SharePoint.Webparts.Vue.VueComponent.VueComponentUserControl" %>
<script type="text/javascript">
var coscine = coscine || {};
coscine.authorization = coscine.authorization || {};
coscine.authorization.bearer = "<%= GetUserJWT() %>";
window.component = "<%= GetComponent() %>";
</script>
\ No newline at end of file
......@@ -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.0.0" targetFramework="net472" />
<package id="Coscine.Action" version="1.1.1" 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