Skip to content

Commit

Permalink
[FIX] PermissionService Owned Things directly contained in Engineerin…
Browse files Browse the repository at this point in the history
…gModel and their full containment tree

* [FIX] PermissionService Owned Things directly contained in EngineeringModel and their full containment tree
* Bump version number
* Version upgrade texts
  • Loading branch information
lxatstariongroup authored Jul 12, 2024
1 parent 1e4ff16 commit 96556f4
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 39 deletions.
4 changes: 2 additions & 2 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[ADD] Implement ExceptionHandlerService
[FIX] PermissionService
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
36 changes: 35 additions & 1 deletion CDP4Dal.NetCore.Tests/Permission/PermissionServiceTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class PermissionServiceTestFixture

private PermissionService permissionService;
private CommonFileStore commonFileStore;
private File file;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -103,6 +104,7 @@ public void Setup()
this.requirementsSpecification = new RequirementsSpecification(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.requirement = new Requirement(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.commonFileStore = new CommonFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri);

this.sitedir.Model.Add(this.modelsetup);
this.sitedir.Person.Add(this.person);
Expand Down Expand Up @@ -134,6 +136,8 @@ public void Setup()
this.requirementsSpecification.Requirement.Add(this.requirement);
this.iteration.RequirementsSpecification.Add(this.requirementsSpecification);
this.model.CommonFileStore.Add(this.commonFileStore);
this.file.Owner = this.domain1;
this.commonFileStore.File.Add(this.file);

this.session.Setup(x => x.ActivePerson).Returns(this.person);
this.session.Setup(x => x.Assembler).Returns(this.assembler);
Expand Down Expand Up @@ -172,6 +176,7 @@ public void TestCanWriteFalseWithDefaultPermission()

Assert.That(this.permissionService.CanRead(this.model), Is.False);
Assert.That(this.permissionService.CanRead(this.iteration), Is.False);
Assert.That(this.permissionService.CanRead(this.file), Is.False);
}

[Test]
Expand Down Expand Up @@ -399,10 +404,39 @@ public void VerifyModifyIfOwnerForThingsThatAreDirectlyUnderEngineeringModel()

//Thing has other owner as User's participant
this.commonFileStore.Owner = this.domain2;
Assert.That(this.permissionService.CanWrite(this.commonFileStore), Is.True);
Assert.That(this.permissionService.CanWrite(this.commonFileStore), Is.False);
Assert.That(this.permissionService.CanRead(this.commonFileStore), Is.True);
}

[Test]
public void VerifyModifyIfOwnerForThingsThatContainedInThingsThatAreDirectlyUnderEngineeringModel()
{
this.session.Setup(x => x.ActivePersonParticipants).Returns(new List<Participant> { this.participant });
Assert.That(this.permissionService.CanWrite(this.model), Is.False);
Assert.That(this.permissionService.CanRead(this.model), Is.False);

var permission =
this.participantRole.ParticipantPermission.Single(x => x.ObjectClass == ClassKind.File);

permission.AccessRight = ParticipantAccessRightKind.MODIFY_IF_OWNER;

this.file.Owner = null;

//Thing has no owner
Assert.Throws<IncompleteModelException>(() => this.permissionService.CanWrite(this.file));
Assert.Throws<IncompleteModelException>(() => this.permissionService.CanRead(this.file));

//Thing has same owner as User's participant
this.file.Owner = this.domain1;
Assert.That(this.permissionService.CanWrite(this.file), Is.True);
Assert.That(this.permissionService.CanRead(this.file), Is.True);

//Thing has other owner as User's participant
this.file.Owner = this.domain2;
Assert.That(this.permissionService.CanWrite(this.file), Is.False);
Assert.That(this.permissionService.CanRead(this.file), Is.True);
}

[Test]
public void VerifySameAsSuperclassParticipantPermission()
{
Expand Down
46 changes: 40 additions & 6 deletions CDP4Dal.Tests/Permission/PermissionServiceTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// <copyright file="PermissionServiceTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2024 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov
//
// This file is part of CDP4-COMET SDK Community Edition
//
//
// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
//
// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Expand Down Expand Up @@ -70,6 +70,7 @@ public class PermissionServiceTestFixture

private PermissionService permissionService;
private CommonFileStore commonFileStore;
private File file;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -103,6 +104,7 @@ public void Setup()
this.requirementsSpecification = new RequirementsSpecification(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.requirement = new Requirement(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.commonFileStore = new CommonFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri);

this.sitedir.Model.Add(this.modelsetup);
this.sitedir.Person.Add(this.person);
Expand Down Expand Up @@ -134,6 +136,8 @@ public void Setup()
this.requirementsSpecification.Requirement.Add(this.requirement);
this.iteration.RequirementsSpecification.Add(this.requirementsSpecification);
this.model.CommonFileStore.Add(this.commonFileStore);
this.file.Owner = this.domain1;
this.commonFileStore.File.Add(this.file);

this.session.Setup(x => x.ActivePerson).Returns(this.person);
this.session.Setup(x => x.Assembler).Returns(this.assembler);
Expand Down Expand Up @@ -172,6 +176,7 @@ public void TestCanWriteFalseWithDefaultPermission()

Assert.That(this.permissionService.CanRead(this.model), Is.False);
Assert.That(this.permissionService.CanRead(this.iteration), Is.False);
Assert.That(this.permissionService.CanRead(this.file), Is.False);
}

[Test]
Expand Down Expand Up @@ -399,10 +404,39 @@ public void VerifyModifyIfOwnerForThingsThatAreDirectlyUnderEngineeringModel()

//Thing has other owner as User's participant
this.commonFileStore.Owner = this.domain2;
Assert.That(this.permissionService.CanWrite(this.commonFileStore), Is.True);
Assert.That(this.permissionService.CanWrite(this.commonFileStore), Is.False);
Assert.That(this.permissionService.CanRead(this.commonFileStore), Is.True);
}

[Test]
public void VerifyModifyIfOwnerForThingsThatContainedInThingsThatAreDirectlyUnderEngineeringModel()
{
this.session.Setup(x => x.ActivePersonParticipants).Returns(new List<Participant> { this.participant });
Assert.That(this.permissionService.CanWrite(this.model), Is.False);
Assert.That(this.permissionService.CanRead(this.model), Is.False);

var permission =
this.participantRole.ParticipantPermission.Single(x => x.ObjectClass == ClassKind.File);

permission.AccessRight = ParticipantAccessRightKind.MODIFY_IF_OWNER;

this.file.Owner = null;

//Thing has no owner
Assert.Throws<IncompleteModelException>(() => this.permissionService.CanWrite(this.file));
Assert.Throws<IncompleteModelException>(() => this.permissionService.CanRead(this.file));

//Thing has same owner as User's participant
this.file.Owner = this.domain1;
Assert.That(this.permissionService.CanWrite(this.file), Is.True);
Assert.That(this.permissionService.CanRead(this.file), Is.True);

//Thing has other owner as User's participant
this.file.Owner = this.domain2;
Assert.That(this.permissionService.CanWrite(this.file), Is.False);
Assert.That(this.permissionService.CanRead(this.file), Is.True);
}

[Test]
public void VerifySameAsSuperclassParticipantPermission()
{
Expand Down
5 changes: 2 additions & 3 deletions CDP4Dal/CDP4Dal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Dal Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,8 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[ADD] Use ExceptionHandlerService in Session
[FIX] PermissionService
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
27 changes: 22 additions & 5 deletions CDP4Dal/Permission/PermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ private bool CanWriteIfParticipantOwned(IOwnedThing ownedThing)

if (thing.Container is EngineeringModel currentModel)
{
return this.Session.OpenIterations.Where(x => x.Key.Container == currentModel).Select(x => x.Value).Any();
return this.Session.OpenIterations.Where(x => x.Key.Container == currentModel && x.Value.Item2.Domain.Contains(ownedThing.Owner)).Select(x => x.Value).Any();
}

//Check if the ownedThing domain is contained in the participant domains
Expand All @@ -669,13 +669,30 @@ private bool TryGetThingParticipant(Thing thing, out Participant participant)
var iteration = thing is Iteration it ? it : thing.GetContainerOfType<Iteration>();
participant = null;

if (iteration != null
&& this.Session.OpenIterations.TryGetValue(iteration, out var participation)
if (iteration != null)
{
if (this.Session.OpenIterations.TryGetValue(iteration, out var participation)
&& participation.Item1 != null
&& participation.Item2 != null)
{
participant = participation.Item2;
return true;
}
}
else
{
participant = participation.Item2;
return true;
// Check TopContainer, for contained Things on a non Iteration Thing directly under EngineeringModel,
// like EngineeringModel=>CommonFileStore=>File
if (thing.TopContainer is EngineeringModel currentModel)
{
var iterations = this.Session.OpenIterations.FirstOrDefault(x => x.Key.Container == currentModel);

if (iterations.Key != null)
{
participant = iterations.Value.Item2;
return true;
}
}
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions CDP4DalCommon/CDP4DalCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Starion Group S.A.</Company>
<Language>latest</Language>
<Title>CDP4DalCommon Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand All @@ -21,7 +21,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonFileDal/CDP4JsonFileDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4JsonFileDal Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Json File Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonSerializer/CDP4JsonSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4JsonSerializer Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 JSON Serialization Library</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 JSON</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4MessagePackSerializer Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 MessagePack Serialization Library</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 MessagePack</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Reporting/CDP4Reporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Reporting Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Reporting</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<LangVersion>latest</LangVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4RequirementsVerification Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Class Library that provides requirement verification</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Rules/CDP4Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Rules Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4 Class Library that provides Model Analysis and Rule Checking</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4ServicesDal/CDP4ServicesDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4ServicesDal Community Edition</Title>
<VersionPrefix>27.1.0</VersionPrefix>
<VersionPrefix>27.2.0</VersionPrefix>
<Description>CDP4ServicesDal Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.1.0
[BUMP] To CDP4Common 27.2.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 96556f4

Please sign in to comment.