Commit ae5ddfa5 authored by David Schimmel's avatar David Schimmel

add subsite creation (coscine/issues#180)

parent bd1ed418
......@@ -64,6 +64,7 @@ namespace Coscine.Api.Project.Tests
}
[Test]
public void TestControllerUpdate()
{
......@@ -138,6 +139,69 @@ namespace Coscine.Api.Project.Tests
projectModel.Delete(project);
}
[Test]
public void TestControllerStoreWithSubProject()
{
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", "NewOrganisation", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3");
var stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
FakeControllerContext(Users[0], stream);
var actionResult = Controller.Store();
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
ProjectObject createdProjectObject = (ProjectObject)okObjectResult.Value;
ProjectObject newSubProjectObject = new ProjectObject(Guid.NewGuid(), "NewSubProject", "NewDisplayNameSub", "NewOrganisation", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", createdProjectObject.Id);
var subStream = ObjectFactory<ProjectObject>.SerializeToStream(newSubProjectObject);
FakeControllerContext(Users[0], subStream);
var subActionResult = Controller.Store();
OkObjectResult okSubObjectResult = (OkObjectResult)subActionResult;
ProjectObject createdSubProjectObject = (ProjectObject)okSubObjectResult.Value;
SubProjectModel subProjectModel = new SubProjectModel();
var subProjects = subProjectModel.GetAllWhere((x) => x.ProjectId == createdProjectObject.Id);
foreach(var subProject in subProjects)
{
Assert.IsTrue(subProject.SubProjectId == createdSubProjectObject.Id);
Assert.IsTrue(subProject.ProjectId == createdProjectObject.Id);
}
// Cleanup
stream.Close();
subStream.Close();
ProjectModel projectModel = new ProjectModel();
var project = projectModel.GetById(createdProjectObject.Id);
SubProjectModel subProjectModel1 = new SubProjectModel();
var subProjects1 = subProjectModel1.GetAllWhere((x) => x.ProjectId == project.Id);
foreach (var subProject in subProjects1)
{
subProjectModel1.Delete(subProject);
}
ProjectRoleModel projectRoleModel = new ProjectRoleModel();
var projectRoles = projectRoleModel.GetAllWhere((x) => x.ProjectId == project.Id);
foreach (var projectRole in projectRoles)
{
projectRoleModel.Delete(projectRole);
}
projectModel.Delete(project);
ProjectModel projectModel2 = new ProjectModel();
var project2 = projectModel2.GetById(createdSubProjectObject.Id);
ProjectRoleModel projectRoleModel2 = new ProjectRoleModel();
var projectRoles2 = projectRoleModel2.GetAllWhere((x) => x.ProjectId == project2.Id);
foreach (var projectRole in projectRoles2)
{
projectRoleModel2.Delete(projectRole);
}
projectModel2.Delete(project2);
}
[Test]
public void CountTest()
{
......
......@@ -83,6 +83,14 @@ namespace Coscine.Api.Project.Controllers
ProjectModel projectModel = new ProjectModel();
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
{
SubProjectModel subProjectModel = new SubProjectModel();
subProjectModel.LinkSubProject(projectObject.ParentId, project.Id);
}
FireEvents((projectAction, projectEventArgs) => projectAction.OnProjectCreate(project, projectEventArgs));
return new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords);
......
<?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;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
namespace Coscine.Api.Project.Models
{
public class SubProjectModel : DatabaseModel<Coscine.Database.Model.SubProject>
{
public SubProjectModel() : base(Program.Configuration)
{
}
public override Expression<Func<SubProject, Guid>> GetIdFromObject()
{
return databaseObject => databaseObject.RelationId;
}
public override ITable<SubProject> GetITableFromDatabase(CoscineDB db)
{
return db.SubProjects;
}
public void LinkSubProject(Guid parentId, Guid childId)
{
Coscine.Database.Model.SubProject subProject = new Coscine.Database.Model.SubProject()
{
ProjectId = parentId,
SubProjectId = childId,
};
Insert(subProject);
return;
}
public override void SetObjectId(SubProject databaseObject, Guid id)
{
databaseObject.RelationId = id;
}
}
}
......@@ -572,6 +572,7 @@
<Compile Include="Models\ResourceModel.cs" />
<Compile Include="Models\ResourceTypeModel.cs" />
<Compile Include="Models\RoleModel.cs" />
<Compile Include="Models\SubProjectModel.cs" />
<Compile Include="Models\UserModel.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
......@@ -587,6 +588,12 @@
<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>
......
......@@ -16,7 +16,9 @@ namespace Coscine.Api.Project.ReturnObjects
public DateTime EndDate { get; set; }
public string Keywords { get; set; }
public ProjectObject(Guid id, string description, string displayName, string organisation, DateTime startDate, DateTime endDate, string keywords)
public Guid ParentId { get; set; }
public ProjectObject(Guid id, string description, string displayName, string organisation, DateTime startDate, DateTime endDate, string keywords, Guid parentId = new Guid())
{
Id = id;
Description = description;
......@@ -25,7 +27,7 @@ namespace Coscine.Api.Project.ReturnObjects
StartDate = startDate;
EndDate = endDate;
Keywords = keywords;
ParentId = parentId;
}
}
}
<?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
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