Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Fix/xxxx-activateGitlab
  • Fix/xxxx-resourceVisibility
  • Hotfix/1262-fixStatuscode
  • Hotfix/1308-versionConflict
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/1383-topLevel
  • Hotfix/1433-defaultQuota
  • Hotfix/1466-projectCreationTimeout
  • Hotfix/1584-fixResourceLoader
  • Hotfix/1590-quotaFix
  • Hotfix/1615-membersCreatingProject
  • Hotfix/1668-versionResourceConfigDepVersion
  • Hotfix/1669-RDS-S3QuotaManagement
  • Hotfix/1704-FixingArchiveFlag
  • Hotfix/1796-projectDdos
  • Hotfix/1917-PublicFilesVisibility
  • Hotfix/2015-PublicFilesVisibility
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2202-fixNaNQuota
  • Hotfix/2203-quotaMembersFix
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2371-fixGitLabinRCV
  • Hotfix/64-releaseUDE
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1825-codeQualityPipelines
  • Issue/1825-codeQualityPipelinesNew
  • Issue/1860-searchScoping
  • Issue/1861-searchMetadata
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1927-projectAppMigration
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/1957-resourceAppMigrationNew
  • Issue/1971-projectEditCreateMigration
  • Issue/1971-projectForDev
  • Issue/2000-gitlabResourcesAPI
  • Issue/2001-extendAnalyticsLogger
  • Issue/2008-quotaManagement
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2101-gitLabResTypeUi
  • Issue/2221-projectDateCreated
  • Issue/2246-quotaResoval
  • Issue/2259-updatePids
  • Issue/2287-guestRole
  • Issue/2309-docs
  • Issue/2328-noFailOnLog
  • Issue/2349-gitlabHttps
  • Issue/2355-topLevelOrg
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issues/0028-maxQuotaFix
  • Product/1100-fdsS3
  • Product/1154-resourceTypeDefinition
  • Product/1188-LoggingExtended
  • Product/1215-gitlabCleanUp
  • Product/1287-dotnet5Sharepoint
  • Product/1414-fhPrivileges
  • Product/1442-projectInviteMngmnt
  • Product/1548-projectInviteMngmnt
  • Product/1600-rdsS3QuotaManagement
  • Product/1629-onboardingOtherUniversities
  • Product/202-userInvitation
  • Product/588-quotaManagement
  • Product/932-docuProjectApi
  • Sprint/2020-20
  • Sprint/2020-21
  • Sprint/2020-22
  • Sprint/2021-01
  • Sprint/2021-02
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-09
  • Sprint/2021-10
  • Sprint/2021-11
  • Sprint/2021-12
  • Sprint/2021-13
  • Sprint/2021-15
  • Sprint/2021-19
  • Sprint/2021-2022
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Test/xxxx-enablingGitLab
  • Topic/1115-docuProjectApi
  • Topic/1159-rtdApi
  • Topic/1221-LogginExtendedNew
  • Topic/1221-LoggingExtended
  • Topic/1279-quotaManagement
  • Topic/1292-FdsS3
  • Topic/1335-dotnet5Apis
  • Topic/1425-fhPrivileges
  • Topic/1453-userInvitation
  • Topic/1529-HandleExternalUserInvitation
  • Topic/1530-invitationUserManagement
  • Topic/1531-UseMangmntTableView
  • v1.0.0
  • v1.1.0
  • v1.10.0
  • v1.11.0
  • v1.11.1
  • v1.12.0
  • v1.13.0
  • v1.13.1
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.17.1
  • v1.18.0
  • v1.19.0
  • v1.2.0
  • v1.2.1
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.23.3
  • v1.24.0
  • v1.24.1
  • v1.25.0
  • v1.25.1
  • v1.3.0
  • v1.4.0
  • v1.4.1
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.6.2
  • v1.7.0
  • v1.7.1
  • v1.8.0
  • v1.9.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.1.0
  • v2.1.1
  • v2.1.2
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.2.3
  • v2.2.4
  • v2.2.5
  • v2.3.0
  • v2.4.0
  • v2.4.1
  • v2.4.2
  • v2.4.3
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v2.6.2
  • v2.7.0
  • v2.8.0
  • v2.8.1
  • v2.8.2
  • v2.8.3
  • v2.8.4
  • v2.9.0
  • v3.0.0
  • v3.0.1
  • v4.0.0
  • v4.0.1
  • v4.0.2
  • v4.0.3
  • v4.1.0
  • v4.1.1
  • v4.2.0
  • v4.2.1
  • v4.2.2
  • v4.2.3
  • v4.2.4
  • v4.2.5
  • v4.2.6
  • v4.2.7
  • v4.2.8
  • v4.3.0
  • v4.3.1
  • v4.3.2
  • v4.3.3
  • v4.3.4
  • v4.4.0
200 results

Target

Select target project
  • coscine/backend/apis/project
1 result
Select Git revision
  • Fix/xxxx-activateGitlab
  • Fix/xxxx-resourceVisibility
  • Hotfix/1262-fixStatuscode
  • Hotfix/1308-versionConflict
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/1383-topLevel
  • Hotfix/1433-defaultQuota
  • Hotfix/1466-projectCreationTimeout
  • Hotfix/1584-fixResourceLoader
  • Hotfix/1590-quotaFix
  • Hotfix/1615-membersCreatingProject
  • Hotfix/1668-versionResourceConfigDepVersion
  • Hotfix/1669-RDS-S3QuotaManagement
  • Hotfix/1704-FixingArchiveFlag
  • Hotfix/1796-projectDdos
  • Hotfix/1917-PublicFilesVisibility
  • Hotfix/2015-PublicFilesVisibility
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2202-fixNaNQuota
  • Hotfix/2203-quotaMembersFix
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2371-fixGitLabinRCV
  • Hotfix/64-releaseUDE
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1825-codeQualityPipelines
  • Issue/1825-codeQualityPipelinesNew
  • Issue/1860-searchScoping
  • Issue/1861-searchMetadata
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1927-projectAppMigration
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/1957-resourceAppMigrationNew
  • Issue/1971-projectEditCreateMigration
  • Issue/1971-projectForDev
  • Issue/2000-gitlabResourcesAPI
  • Issue/2001-extendAnalyticsLogger
  • Issue/2008-quotaManagement
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2101-gitLabResTypeUi
  • Issue/2221-projectDateCreated
  • Issue/2246-quotaResoval
  • Issue/2259-updatePids
  • Issue/2287-guestRole
  • Issue/2309-docs
  • Issue/2328-noFailOnLog
  • Issue/2349-gitlabHttps
  • Issue/2355-topLevelOrg
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issues/0028-maxQuotaFix
  • Product/1100-fdsS3
  • Product/1154-resourceTypeDefinition
  • Product/1188-LoggingExtended
  • Product/1215-gitlabCleanUp
  • Product/1287-dotnet5Sharepoint
  • Product/1414-fhPrivileges
  • Product/1442-projectInviteMngmnt
  • Product/1548-projectInviteMngmnt
  • Product/1600-rdsS3QuotaManagement
  • Product/1629-onboardingOtherUniversities
  • Product/202-userInvitation
  • Product/588-quotaManagement
  • Product/932-docuProjectApi
  • Sprint/2020-20
  • Sprint/2020-21
  • Sprint/2020-22
  • Sprint/2021-01
  • Sprint/2021-02
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-09
  • Sprint/2021-10
  • Sprint/2021-11
  • Sprint/2021-12
  • Sprint/2021-13
  • Sprint/2021-15
  • Sprint/2021-19
  • Sprint/2021-2022
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Test/xxxx-enablingGitLab
  • Topic/1115-docuProjectApi
  • Topic/1159-rtdApi
  • Topic/1221-LogginExtendedNew
  • Topic/1221-LoggingExtended
  • Topic/1279-quotaManagement
  • Topic/1292-FdsS3
  • Topic/1335-dotnet5Apis
  • Topic/1425-fhPrivileges
  • Topic/1453-userInvitation
  • Topic/1529-HandleExternalUserInvitation
  • Topic/1530-invitationUserManagement
  • Topic/1531-UseMangmntTableView
  • v1.0.0
  • v1.1.0
  • v1.10.0
  • v1.11.0
  • v1.11.1
  • v1.12.0
  • v1.13.0
  • v1.13.1
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.17.1
  • v1.18.0
  • v1.19.0
  • v1.2.0
  • v1.2.1
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.23.3
  • v1.24.0
  • v1.24.1
  • v1.25.0
  • v1.25.1
  • v1.3.0
  • v1.4.0
  • v1.4.1
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.6.2
  • v1.7.0
  • v1.7.1
  • v1.8.0
  • v1.9.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.1.0
  • v2.1.1
  • v2.1.2
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.2.3
  • v2.2.4
  • v2.2.5
  • v2.3.0
  • v2.4.0
  • v2.4.1
  • v2.4.2
  • v2.4.3
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v2.6.2
  • v2.7.0
  • v2.8.0
  • v2.8.1
  • v2.8.2
  • v2.8.3
  • v2.8.4
  • v2.9.0
  • v3.0.0
  • v3.0.1
  • v4.0.0
  • v4.0.1
  • v4.0.2
  • v4.0.3
  • v4.1.0
  • v4.1.1
  • v4.2.0
  • v4.2.1
  • v4.2.2
  • v4.2.3
  • v4.2.4
  • v4.2.5
  • v4.2.6
  • v4.2.7
  • v4.2.8
  • v4.3.0
  • v4.3.1
  • v4.3.2
  • v4.3.3
  • v4.3.4
  • v4.4.0
200 results
Show changes
Commits on Source (3)
Showing
with 636 additions and 111 deletions
using Coscine.Api.Project.Models;
using Coscine.Api.Project.Controllers;
using Coscine.Api.Project.Models;
using Coscine.ApiCommons.Utils;
using Coscine.Database.Model;
using Microsoft.AspNetCore.Http;
......@@ -24,6 +25,13 @@ namespace Coscine.Api.Project.Tests
protected readonly List<ProjectRole> ProjectRoles = new List<ProjectRole>();
protected readonly List<ResourceType> ResourceTypes = new List<ResourceType>();
protected readonly List<Resource> Resources = new List<Resource>();
protected readonly List<ResourceDiscipline> ResourceDisciplines = new List<ResourceDiscipline>();
protected Discipline Discipline { get; set; }
protected Institute Institute { get; set; }
protected Visibility Visibility { get; set; }
protected License License { get; set; }
protected RDSResourceType RdsResourceType { get; set; }
protected int Previous;
......@@ -35,6 +43,32 @@ namespace Coscine.Api.Project.Tests
[OneTimeSetUp]
public void Setup()
{
DisciplineModel disciplineModel = new DisciplineModel();
Discipline = new Discipline()
{
DisplayName = "TestDiscipline",
Url = "http://rwth-aachen.de"
};
disciplineModel.Insert(Discipline);
InstituteModel instituteModel = new InstituteModel();
Institute = new Institute()
{
DisplayName = "TestInstitute",
IKZ = "022000"
};
instituteModel.Insert(Institute);
VisibilityModel visibilityModel = new VisibilityModel();
Visibility = visibilityModel.GetWhere((visibility) => visibility.DisplayName == "Public");
LicenseModel licenseModel = new LicenseModel();
License = new License()
{
DisplayName = "MIT"
};
licenseModel.Insert(License);
ProjectModel projectModel = new ProjectModel();
Previous = projectModel.GetAll().ToArray().Length;
......@@ -54,63 +88,120 @@ namespace Coscine.Api.Project.Tests
var project = new Coscine.Database.Model.Project()
{
Description = "Description",
Organization = "Organization",
ProjectName = "TestProject",
DisplayName = "TestProject",
StartDate = DateTime.Now,
EndDate = DateTime.Now.AddYears(1),
Keywords = "Test1;Test2"
Keywords = "Test1;Test2",
GrantId = "testid",
PrincipleInvestigators = "TestInvestigator",
VisibilityId = Visibility.Id
};
projectModel.Insert(project);
var projectRole = projectModel.SetOwner(project, user);
ProjectRoles.Add(projectRole);
ProjectDisciplineModel projectDisciplineModel = new ProjectDisciplineModel();
projectDisciplineModel.Insert(new ProjectDiscipline()
{
DisciplineId = Discipline.Id,
ProjectId = project.Id
});
ProjectInstituteModel projectInstituteModel = new ProjectInstituteModel();
projectInstituteModel.Insert(new ProjectInstitute()
{
InstituteId = Institute.Id,
ProjectId = project.Id
});
Projects.Add(projectModel.GetById(project.Id));
var project2 = new Coscine.Database.Model.Project()
{
Description = "Description2",
Organization = "Organization2",
ProjectName = "TestProject",
DisplayName = "TestProject2",
StartDate = DateTime.Now,
EndDate = DateTime.Now.AddYears(1),
Keywords = "Test1;Test2"
Keywords = "Test1;Test2",
GrantId = "testid",
PrincipleInvestigators = "TestInvestigator",
VisibilityId = Visibility.Id
};
projectModel.Insert(project2);
Projects.Add(projectModel.GetById(project2.Id));
ResourceTypeModel resourceTypeModel = new ResourceTypeModel();
var resourceType = new ResourceType()
var resourceType = resourceTypeModel.GetWhere((dbResourceType) => dbResourceType.DisplayName == "rds");
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
RdsResourceType = new RDSResourceType()
{
DisplayName = "TestType"
AccessKey = "a",
SecretKey = "b",
BucketName = "c",
};
resourceTypeModel.Insert(resourceType);
ResourceTypes.Add(resourceType);
rdsResourceTypeModel.Insert(RdsResourceType);
ResourceModel resourceModel = new ResourceModel();
var resource = new Resource()
{
ExternalId = "123",
Url = "http://rwth-aachen.de/test",
DisplayName = "ResourceTest1",
ResourceName = "ResourceTest1",
Keywords = "ResourceTest1",
UsageRights = "ResourceTest1",
TypeId = resourceType.Id,
Type = resourceType
Type = resourceType,
Visibility = Visibility,
VisibilityId = Visibility.Id,
LicenseId = License.Id,
ResourceTypeOptionId = RdsResourceType.Id
};
resourceModel.Insert(resource);
projectModel.AddResource(project, resource);
Resources.Add(resource);
resourceType = resourceTypeModel.GetWhere((dbResourceType) => dbResourceType.DisplayName == "gitlab");
var resource2 = new Resource()
{
ExternalId = "12345",
Url = "http://rwth-aachen.de/test2",
DisplayName = "ResourceTest2",
ResourceName = "ResourceTest2",
Keywords = "ResourceTest2",
UsageRights = "ResourceTest2",
TypeId = resourceType.Id,
Type = resourceType
Type = resourceType,
Visibility = Visibility,
VisibilityId = Visibility.Id,
LicenseId = License.Id
};
resourceModel.Insert(resource2);
projectModel.AddResource(project2, resource2);
Resources.Add(resource2);
ResourceDisciplineModel resourceDisciplineModel = new ResourceDisciplineModel();
ResourceDiscipline resourceDiscipline = new ResourceDiscipline()
{
DisciplineId = Discipline.Id,
ResourceId = resource.Id
};
resourceDisciplineModel.Insert(resourceDiscipline);
ResourceDisciplines.Add(resourceDiscipline);
resourceDiscipline = new ResourceDiscipline()
{
DisciplineId = Discipline.Id,
ResourceId = resource2.Id
};
resourceDisciplineModel.Insert(resourceDiscipline);
ResourceDisciplines.Add(resourceDiscipline);
}
......@@ -193,26 +284,43 @@ namespace Coscine.Api.Project.Tests
{
projectResourceModel.Delete(projectResource);
}
ProjectModel projectModel = new ProjectModel();
ProjectController projectController = new ProjectController();
foreach (var project in Projects)
{
projectModel.Delete(project);
projectController.DeleteProject(project);
}
UserModel userModel = new UserModel();
foreach (var user in Users)
{
userModel.Delete(user);
}
ResourceDisciplineModel resourceDisciplineModel = new ResourceDisciplineModel();
foreach (var resourceDiscipline in ResourceDisciplines)
{
resourceDisciplineModel.Delete(resourceDiscipline);
}
ResourceModel resourceModel = new ResourceModel();
foreach (var resource in Resources)
{
resourceModel.Delete(resource);
resourceModel.DeleteResource(resource);
}
ResourceTypeModel resourceTypeModel = new ResourceTypeModel();
foreach (var resourceType in ResourceTypes)
{
resourceTypeModel.Delete(resourceType);
}
DisciplineModel disciplineModel = new DisciplineModel();
disciplineModel.Delete(Discipline);
InstituteModel instituteModel = new InstituteModel();
instituteModel.Delete(Institute);
LicenseModel licenseModel = new LicenseModel();
licenseModel.Delete(License);
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
rdsResourceTypeModel.Delete(RdsResourceType);
}
}
}
\ No newline at end of file
......@@ -64,8 +64,8 @@
<Reference Include="Coscine.Configuration, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Configuration.1.4.0\lib\net461\Coscine.Configuration.dll</HintPath>
</Reference>
<Reference Include="Coscine.Database, Version=1.5.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.5.0\lib\net461\Coscine.Database.dll</HintPath>
<Reference Include="Coscine.Database, Version=1.6.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.6.0\lib\net461\Coscine.Database.dll</HintPath>
</Reference>
<Reference Include="Coscine.ProxyApi, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ProxyApi.1.2.0\lib\net461\Coscine.ProxyApi.dll</HintPath>
......@@ -565,6 +565,7 @@
<Compile Include="ProjectControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceControllerTests.cs" />
<Compile Include="ResourceTypeControllerTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
......
......@@ -8,6 +8,7 @@ using System.IO;
using System;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using System.Collections.Generic;
#region DupFinder Exclusion
namespace Coscine.Api.Project.Tests
......@@ -57,7 +58,6 @@ namespace Coscine.Api.Project.Tests
Assert.IsTrue(projectObject.Id == Projects[0].Id);
Assert.IsTrue(projectObject.Description == Projects[0].Description);
Assert.IsTrue(projectObject.DisplayName == Projects[0].DisplayName);
Assert.IsTrue(projectObject.Organization == Projects[0].Organization);
Assert.IsTrue(projectObject.StartDate == Projects[0].StartDate);
Assert.IsTrue(projectObject.EndDate == Projects[0].EndDate);
Assert.IsTrue(projectObject.Keywords == Projects[0].Keywords);
......@@ -104,7 +104,10 @@ namespace Coscine.Api.Project.Tests
[Test]
public void TestControllerStore()
{
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", "NewOrganisation", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3");
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName));
var stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
......@@ -120,7 +123,6 @@ namespace Coscine.Api.Project.Tests
Assert.IsTrue(createdProjectObject.Description == newProjectObject.Description);
Assert.IsTrue(createdProjectObject.DisplayName == newProjectObject.DisplayName);
Assert.IsTrue(createdProjectObject.Organization == newProjectObject.Organization);
Assert.IsTrue(createdProjectObject.StartDate == newProjectObject.StartDate);
Assert.IsTrue(createdProjectObject.EndDate == newProjectObject.EndDate);
Assert.IsTrue(createdProjectObject.Keywords == newProjectObject.Keywords);
......@@ -130,19 +132,94 @@ namespace Coscine.Api.Project.Tests
ProjectModel projectModel = new ProjectModel();
var project = projectModel.GetById(createdProjectObject.Id);
ProjectRoleModel projectRoleModel = new ProjectRoleModel();
var projectRoles = projectRoleModel.GetAllWhere((x) => x.ProjectId == project.Id);
foreach (var projectRole in projectRoles)
Controller.DeleteProject(project);
}
[Test]
public void TestControllerDelete()
{
projectRoleModel.Delete(projectRole);
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName));
var stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
FakeControllerContext(Users[0], stream);
var actionResult = Controller.Store();
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
Assert.IsTrue(okObjectResult.Value.GetType() == typeof(ProjectObject));
ProjectObject createdProjectObject = (ProjectObject)okObjectResult.Value;
stream.Close();
stream = ObjectFactory<ProjectObject>.SerializeToStream(createdProjectObject);
FakeControllerContext(Users[0], stream);
actionResult = Controller.Delete(createdProjectObject.Id.ToString());
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
okObjectResult = (OkObjectResult)actionResult;
Assert.IsTrue(okObjectResult.Value.GetType() == typeof(ProjectObject));
stream.Close();
}
projectModel.Delete(project);
[Test]
public void TestControllerDeleteWithSubProjects()
{
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName));
var stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
FakeControllerContext(Users[0], stream);
var actionResult = Controller.Store();
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
ProjectObject createdProjectObject = (ProjectObject)okObjectResult.Value;
stream.Close();
newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName),
createdProjectObject.Id);
stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
FakeControllerContext(Users[0], stream);
actionResult = Controller.Store();
stream = ObjectFactory<ProjectObject>.SerializeToStream(createdProjectObject);
FakeControllerContext(Users[0], stream);
actionResult = Controller.Delete(createdProjectObject.Id.ToString());
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
okObjectResult = (OkObjectResult)actionResult;
Assert.IsTrue(okObjectResult.Value.GetType() == typeof(ProjectObject));
stream.Close();
}
[Test]
public void TestControllerStoreWithSubProject()
{
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", "NewOrganisation", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3");
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName));
var stream = ObjectFactory<ProjectObject>.SerializeToStream(newProjectObject);
FakeControllerContext(Users[0], stream);
......@@ -151,7 +228,11 @@ namespace Coscine.Api.Project.Tests
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);
ProjectObject newSubProjectObject = new ProjectObject(Guid.NewGuid(), "NewSubProject", "NewDisplayNameSub", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new List<InstituteObject>() { new InstituteObject(Institute.Id, Institute.IKZ, Institute.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName),
createdProjectObject.Id);
var subStream = ObjectFactory<ProjectObject>.SerializeToStream(newSubProjectObject);
FakeControllerContext(Users[0], subStream);
......@@ -174,32 +255,7 @@ namespace Coscine.Api.Project.Tests
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);
Controller.DeleteProject(project);
}
[Test]
......
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Project.Tests is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Project.Tests")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0.0")]
[assembly: AssemblyCopyright("2019 IT Center, RWTH Aachen University")]
......@@ -4,8 +4,10 @@ using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
namespace Coscine.Api.Project.Tests
......@@ -33,13 +35,13 @@ namespace Coscine.Api.Project.Tests
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
Assert.IsTrue(okObjectResult.Value.GetType() == typeof(ResourceObject));
ResourceObject projectObject = (ResourceObject)okObjectResult.Value;
ResourceObject resourceObject = (ResourceObject)okObjectResult.Value;
Assert.IsTrue(projectObject.Id == Resources[0].Id);
Assert.IsTrue(projectObject.ExternalId == Resources[0].ExternalId);
Assert.IsTrue(projectObject.Type.Id == Resources[0].Type.Id);
Assert.IsTrue(projectObject.Type.DisplayName == Resources[0].Type.DisplayName);
Assert.IsTrue(projectObject.Url == Resources[0].Url);
Assert.IsTrue(resourceObject.Id == Resources[0].Id);
Assert.IsTrue(resourceObject.DisplayName == Resources[0].DisplayName);
Assert.IsTrue(resourceObject.Visibility.DisplayName == Resources[0].Visibility.DisplayName);
Assert.IsTrue(resourceObject.Type.Id == Resources[0].Type.Id);
Assert.IsTrue(resourceObject.Type.DisplayName == Resources[0].Type.DisplayName);
}
......@@ -50,7 +52,8 @@ namespace Coscine.Api.Project.Tests
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
ResourceObject resourceObject = (ResourceObject)okObjectResult.Value;
resourceObject.ExternalId = "ChangedExternalId";
resourceObject.DisplayName = "OtherName";
resourceObject.ResourceTypeOption = JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", "accesskey", "secretkey"));
Stream stream = ObjectFactory<ResourceObject>.SerializeToStream(resourceObject);
......@@ -83,7 +86,18 @@ namespace Coscine.Api.Project.Tests
[Test]
public void TestControllerStoreToProject()
{
ResourceObject resourceObject = new ResourceObject(Guid.NewGuid(), "externalId", "http://rwth-aachen.de/newTest", "TestResource", new ResourceTypeObject(ResourceTypes[0].Id, ResourceTypes[0].DisplayName));
ResourceObject resourceObject = new ResourceObject(
Guid.NewGuid(),
"Test",
"testR",
"keys",
"usageR",
new ResourceTypeObject(Resources[0].Type.Id, Resources[0].Type.DisplayName),
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayName) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName),
new LicenseObject(License.Id, License.DisplayName),
JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", "accesskey", "secretkey"))
);
Stream stream = ObjectFactory<ResourceObject>.SerializeToStream(resourceObject);
......@@ -97,16 +111,14 @@ namespace Coscine.Api.Project.Tests
// Cleanup
stream.Close();
ResourceModel resourceModel = new ResourceModel();
var resource = resourceModel.GetById(resourceObject.Id);
stream = ObjectFactory<ResourceObject>.SerializeToStream(resourceObject);
ProjectResourceModel projectResourceModel = new ProjectResourceModel();
foreach(var projectResource in projectResourceModel.GetAllWhere((projectResource) => projectResource.ProjectId == Projects[0].Id && projectResource.ResourceId == resource.Id))
{
projectResourceModel.Delete(projectResource);
}
FakeControllerContext(Users[0], stream);
actionResult = Controller.Delete(resourceObject.Id.ToString());
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
resourceModel.Delete(resource);
stream.Close();
}
}
}
using Coscine.Api.Project.Controllers;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Tests
{
[TestFixture]
public class ResourceTypeControllerTests : DefaultControllerTests<ResourceTypeController>
{
public ResourceTypeControllerTests() : base(new ResourceTypeController())
{
}
[Test]
public void TestGettingFields()
{
var actionResult = Controller.Fields(Resources[0].Type.Id.ToString());
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
List<string> fields = (List<string>) okObjectResult.Value;
if(fields.Count() == 3)
{
Assert.IsTrue(fields[0] == "BucketName");
Assert.IsTrue(fields[1] == "AccessKey");
Assert.IsTrue(fields[2] == "SecretKey");
}
else
{
Assert.Fail("Wrong field count!");
}
}
}
}
......@@ -88,7 +88,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.0.0" newVersion="1.5.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.6.0.0" newVersion="1.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
......
......@@ -7,7 +7,7 @@
<package id="Coscine.Action" version="1.3.0" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.2.1" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.5.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.6.0" targetFramework="net472" />
<package id="Coscine.ProxyApi" version="1.2.0" targetFramework="net472" />
<package id="Coscine.SharePoint.Webparts.Vue" version="1.4.0" targetFramework="net472" />
<package id="EntityFramework" version="6.2.0" targetFramework="net472" />
......
......@@ -91,7 +91,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.0.0" newVersion="1.5.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.6.0.0" newVersion="1.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
......
......@@ -75,11 +75,17 @@ namespace Coscine.Api.Project.Controllers
if (resource.Type.DisplayName.ToLower() == "rds")
{
authHeader = BuildRdsAuthHeader(resource.ExternalId);
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
var rdsResourceType = rdsResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
authHeader = BuildRdsAuthHeader(rdsResourceType);
}
else if (resource.Type.DisplayName.ToLower() == "gitlab")
{
authHeader = BuildGitlabAuthHeader(resource.ExternalId, resource.Url);
GitlabResourceTypeModel gitlabResourceTypeModel = new GitlabResourceTypeModel();
var gitlabResourceType = gitlabResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
authHeader = BuildGitlabAuthHeader(gitlabResourceType);
}
if (authHeader != null)
......@@ -146,39 +152,39 @@ namespace Coscine.Api.Project.Controllers
return _jwtHandler.GenerateJwtToken(payload);
}
private string BuildRdsAuthHeader(string bucketname)
private string BuildRdsAuthHeader(RDSResourceType rdsResourceType)
{
var auth = new Dictionary<string, object>();
var credentials = new Dictionary<string, object>
{
{ "access_key", _configuration.GetString("coscine/global/rds_access_key") },
{ "secret_key", _configuration.GetString("coscine/global/rds_secret_key") }
{ "access_key", rdsResourceType.AccessKey },
{ "secret_key", rdsResourceType.SecretKey }
};
var settings = new Dictionary<string, object>
{
{ "bucket", bucketname }
{ "bucket", rdsResourceType.BucketName }
};
return BuildWaterbutlerPayload(auth, credentials, settings);
}
private string BuildGitlabAuthHeader(string externalId, string url)
private string BuildGitlabAuthHeader(GitlabResourceType gitlabResourceType)
{
var auth = new Dictionary<string, object>();
var credentials = new Dictionary<string, object>
{
{ "token", _configuration.GetString("coscine/global/gitlabtoken") }
{ "token", gitlabResourceType.Token }
};
var settings = new Dictionary<string, object>
{
{"owner", "Tester"},
{"repo", url},
{ "repo_id", externalId},
{ "repo", gitlabResourceType.RepositoryUrl},
{ "repo_id", gitlabResourceType.RepositoryNumber},
{ "host", "https://git.rwth-aachen.de"}
};
......
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class DisciplineController : Controller
{
private readonly Authenticator _authenticator;
private readonly DisciplineModel _disciplineModel;
public DisciplineController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_disciplineModel = new DisciplineModel();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _disciplineModel.GetAll().Select((discipline) => new DisciplineObject(discipline.Id, discipline.Url, discipline.DisplayName));
}));
}
}
}
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class InstituteController : Controller
{
private readonly Authenticator _authenticator;
private readonly InstituteModel _instituteModel;
public InstituteController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_instituteModel = new InstituteModel();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _instituteModel.GetAll().Select((institute) => new InstituteObject(institute.Id, institute.IKZ, institute.DisplayName));
}));
}
}
}
......@@ -41,7 +41,7 @@ namespace Coscine.Api.Project.Controllers
where projectRole.User == user
&& projectRole.Role.DisplayName == "Owner"
select projectRole).Any()
).Select((project) => new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords));
).Select((project) => _projectModel.CreateReturnObjectFromDatabaseObject(project));
}));
}
......@@ -53,7 +53,7 @@ namespace Coscine.Api.Project.Controllers
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);
return _projectModel.CreateReturnObjectFromDatabaseObject(project);
}
else
{
......@@ -78,12 +78,7 @@ namespace Coscine.Api.Project.Controllers
select projectResource).Any())
.Select((resource) =>
{
ResourceType resourceType = resource.Type;
if (resourceType == null)
{
resourceType = resourceTypeModel.GetById(resource.TypeId);
}
return new ResourceObject(resource.Id, resource.ExternalId, resource.Url, resource.DisplayName, new ResourceTypeObject(resourceType.Id, resourceType.DisplayName));
return resourceModel.CreateReturnObjectFromDatabaseObject(resource);
});
}
else
......@@ -111,6 +106,79 @@ namespace Coscine.Api.Project.Controllers
}));
}
[HttpDelete("[controller]/{id}")]
public IActionResult Delete(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var project = _projectModel.GetById(Guid.Parse(id));
if (_projectModel.OwnsProject(user, project))
{
DeleteProject(project);
return _projectModel.CreateReturnObjectFromDatabaseObject(project);
}
else
{
throw new NotAuthorizedException("The user is not authorized to perform an update on the selected project!");
}
}));
}
public void DeleteProject(Coscine.Database.Model.Project project)
{
SubProjectModel subProjectModel = new SubProjectModel();
foreach(var subProject in subProjectModel.GetAllWhere((subProject) => subProject.ProjectId == project.Id))
{
subProjectModel.Delete(subProject);
DeleteProject(_projectModel.GetById(subProject.SubProjectId));
}
foreach (var subProject in subProjectModel.GetAllWhere((subProject) => subProject.SubProjectId == project.Id))
{
subProjectModel.Delete(subProject);
}
ProjectResourceModel projectResourceModel = new ProjectResourceModel();
ResourceModel resourceModel = new ResourceModel();
foreach (var projectResource in projectResourceModel.GetAllWhere((projectResource) => projectResource.ProjectId == project.Id))
{
projectResourceModel.Delete(projectResource);
resourceModel.Delete(resourceModel.GetById(projectResource.ResourceId));
}
ProjectRoleModel projectRoleModel = new ProjectRoleModel();
foreach (var projectRole in projectRoleModel.GetAllWhere((projectRole) => projectRole.ProjectId == project.Id))
{
projectRoleModel.Delete(projectRole);
}
ProjectDisciplineModel projectDisciplineModel = new ProjectDisciplineModel();
foreach (var projectDiscipline in projectDisciplineModel.GetAllWhere((projectDiscipline) => projectDiscipline.ProjectId == project.Id))
{
projectDisciplineModel.Delete(projectDiscipline);
}
ProjectInstituteModel projectInstituteModel = new ProjectInstituteModel();
foreach (var projectInstitute in projectInstituteModel.GetAllWhere((projectInstitute) => projectInstitute.ProjectId == project.Id))
{
projectInstituteModel.Delete(projectInstitute);
}
FireEvents((projectAction, projectEventArgs) =>
{
try
{
projectAction.OnProjectDelete(project, projectEventArgs);
}
catch (Exception)
{
// Filter exception, because sometimes the PID or SharePoint site might not be generated in e.g. tests
}
});
_projectModel.Delete(project);
}
[HttpPost("[controller]")]
public IActionResult Store()
{
......@@ -121,7 +189,7 @@ namespace Coscine.Api.Project.Controllers
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.IsMemberOrHigher(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);
......@@ -129,7 +197,7 @@ namespace Coscine.Api.Project.Controllers
FireEvents((projectAction, projectEventArgs) => projectAction.OnProjectCreate(project, projectEventArgs));
return new ProjectObject(project.Id, project.Description, project.DisplayName, project.Organization, project.StartDate, project.EndDate, project.Keywords);
return _projectModel.CreateReturnObjectFromDatabaseObject(project);
}));
}
......
......@@ -59,6 +59,29 @@ namespace Coscine.Api.Project.Controllers
}));
}
//Get all roles for current user and given project
[HttpGet("[controller]/project/{projectId}")]
public IActionResult Get(string projectId)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
RoleModel roleModel = new RoleModel();
Guid.TryParse(projectId, out Guid projectIdGuid);
UserObject userObject = new UserObject(user.Id, user.DisplayName, user.EmailAddress);
return _projectRoleModel.GetAllWhere((projectRole) =>
(projectRole.UserId == user.Id &&
projectRole.ProjectId == projectIdGuid)
).Select((projectRole) => {
if(projectRole.Role == null)
{
projectRole.Role = roleModel.GetById(projectRole.RoleId);
}
return new ProjectRoleObject(projectRole.RelationId, userObject, new RoleObject(projectRole.Role.Id, projectRole.Role.DisplayName));
});
}));
}
[HttpPost("[controller]")]
public IActionResult Set()
{
......
......@@ -3,6 +3,7 @@ using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using Coscine.Database.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
......@@ -32,7 +33,7 @@ namespace Coscine.Api.Project.Controllers
&& projectRole.Role.DisplayName == "Owner"
select projectRole).Any()
select projectResource).Any()
).Select((resource) => new ResourceObject(resource.Id, resource.ExternalId, resource.Url, resource.DisplayName, new ResourceTypeObject(resource.Type.Id, resource.Type.DisplayName)));
).Select((resource) => _resourceModel.CreateReturnObjectFromDatabaseObject(resource));
}));
}
......@@ -45,13 +46,8 @@ namespace Coscine.Api.Project.Controllers
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)
{
ResourceTypeModel resourceTypeModel = new ResourceTypeModel();
resource.Type = resourceTypeModel.GetById(resource.TypeId);
}
return new ResourceObject(resource.Id, resource.ExternalId, resource.Url, resource.DisplayName, new ResourceTypeObject(resource.Type.Id, resource.Type.DisplayName));
_resourceModel.SetType(resource);
return _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
}
else
{
......@@ -78,6 +74,25 @@ namespace Coscine.Api.Project.Controllers
}));
}
[HttpDelete("[controller]/{id}")]
public IActionResult Delete(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var resource = _resourceModel.GetById(Guid.Parse(id));
if (_resourceModel.OwnsResource(user, resource))
{
var returnObject = _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
_resourceModel.DeleteResource(resource);
return returnObject;
}
else
{
throw new NotAuthorizedException("The user is not authorized to perform an update on the selected resource!");
}
}));
}
[HttpPost("[controller]/project/{projectId}")]
public IActionResult StoreToProject(string projectId)
{
......@@ -93,7 +108,7 @@ namespace Coscine.Api.Project.Controllers
projectModel.AddResource(project, resource);
return new ResourceObject(resource.Id, resource.ExternalId, resource.Url, resource.DisplayName, new ResourceTypeObject(resource.Type.Id, resource.Type.DisplayName));
return _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
}
else
{
......
......@@ -31,5 +31,33 @@ namespace Coscine.Api.Project.Controllers
}));
}
[Route("[controller]/{id}/fields")]
public IActionResult Fields(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var resourceType = _resourceTypeModel.GetById(Guid.Parse(id));
if(resourceType.DisplayName == "rds")
{
return Type.GetType("Coscine.Api.Project.ReturnObjects.RDSResourceTypeObject").GetProperties()
.Where((property) => property.Name != "Id")
.Select((property) => property.Name)
.ToList();
}
else if(resourceType.DisplayName == "gitlab")
{
return Type.GetType("Coscine.Api.Project.ReturnObjects.GitlabResourceTypeObject").GetProperties()
.Where((property) => property.Name != "Id")
.Select((property) => property.Name)
.ToList();
}
else
{
throw new ArgumentException("Invalid Resource Type!");
}
}));
}
}
}
......@@ -29,7 +29,7 @@ namespace Coscine.Api.Project.Controllers
{
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));
.Select((project) => projectModel.CreateReturnObjectFromDatabaseObject(project, parentGuid));
return subProjects;
}
else
......
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class VisibilityController : Controller
{
private readonly Authenticator _authenticator;
private readonly VisibilityModel _visibilityModel;
public VisibilityController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_visibilityModel = new VisibilityModel();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _visibilityModel.GetAll().Select((visibility) => new VisibilityObject(visibility.Id, visibility.DisplayName));
}));
}
}
}
using Coscine.ApiCommons.Models;
using Coscine.Configuration;
using Coscine.Database.Model;
using LinqToDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Models
{
public class DisciplineModel : DatabaseModel<Discipline>
{
public DisciplineModel() : base(Program.Configuration)
{
}
public override Expression<Func<Discipline, Guid>> GetIdFromObject()
{
return (discipline) => discipline.Id;
}
public override ITable<Discipline> GetITableFromDatabase(CoscineDB db)
{
return db.Disciplines;
}
public override void SetObjectId(Discipline databaseObject, Guid id)
{
databaseObject.Id = id;
}
}
}
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Models
{
public class GitlabResourceTypeModel : DatabaseModel<GitlabResourceType>
{
public GitlabResourceTypeModel() : base(Program.Configuration)
{
}
public override Expression<Func<GitlabResourceType, Guid>> GetIdFromObject()
{
return (gitlabResourceType) => gitlabResourceType.Id;
}
public override ITable<GitlabResourceType> GetITableFromDatabase(CoscineDB db)
{
return db.GitlabResourceTypes;
}
public override void SetObjectId(GitlabResourceType databaseObject, Guid id)
{
databaseObject.Id = id;
}
}
}