diff --git a/COMETwebapp.Tests/SessionManagement/AuthenticationServiceTestFixture.cs b/COMETwebapp.Tests/SessionManagement/AuthenticationServiceTestFixture.cs index 4f384a4c..0c8cf4bf 100644 --- a/COMETwebapp.Tests/SessionManagement/AuthenticationServiceTestFixture.cs +++ b/COMETwebapp.Tests/SessionManagement/AuthenticationServiceTestFixture.cs @@ -114,6 +114,23 @@ public async Task Verify_that_when_the_server_returns_an_error_the_login_fails() Assert.That(loginResult, Is.EqualTo(AuthenticationStateKind.Fail)); } + [Test] + public async Task Verify_that_when_the_server_cannot_be_reached_the_login_fails() + { + this.session.Setup(x => x.Open(It.IsAny())).Throws(new DalReadException()); + + var authenticationService = new AuthenticationService(this.sessionAnchor.Object, this.cometWebAuthStateProvider); + var authenticationDto = new AuthenticationDto + { + SourceAddress = "https://www.rheagroup", + UserName = "John Doe", + Password = "secret" + }; + var loginResult = await authenticationService.Login(authenticationDto); + + Assert.That(loginResult, Is.EqualTo(AuthenticationStateKind.Fail)); + } + [Test] public async Task Verify_that_a_nonauthorized_user_cannot_login() { diff --git a/COMETwebapp.Tests/SessionManagement/SessionAnchorTest.cs b/COMETwebapp.Tests/SessionManagement/SessionAnchorTest.cs index 0adb1ab6..dddb319e 100644 --- a/COMETwebapp.Tests/SessionManagement/SessionAnchorTest.cs +++ b/COMETwebapp.Tests/SessionManagement/SessionAnchorTest.cs @@ -113,13 +113,17 @@ public void Setup() new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = this.domain } } }; + this.engineeringSetup.IterationSetup.Add(this.iteration.IterationSetup); this.openIteration = new ConcurrentDictionary>( new List>>() { new KeyValuePair>(this.iteration, new Tuple(this.domain, this.participant)) }); - this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri); + this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri) + { + Model = { this.engineeringSetup } + }; this.siteDirectory.Person.Add(this.person); this.siteDirectory.Domain.Add(this.domain); @@ -229,5 +233,13 @@ public void VerifyUpdateThings() thingsToUpdate.Add(clone); Assert.DoesNotThrow(() => this.sessionAnchor.UpdateThings(thingsToUpdate)); } + + [Test] + public void VerifyGetParticipant() + { + this.sessionAnchor.IsSessionOpen = true; + this.sessionAnchor.ReadIteration(this.iteration.IterationSetup); + Assert.That(this.sessionAnchor.GetParticipant(), Is.EqualTo(this.participant)); + } } } diff --git a/COMETwebapp/Components/Login.razor b/COMETwebapp/Components/Login.razor index 8ee3f9ff..d5739584 100644 --- a/COMETwebapp/Components/Login.razor +++ b/COMETwebapp/Components/Login.razor @@ -21,6 +21,8 @@ -------------------------------------------------------------------------------> + +
@@ -40,6 +42,22 @@
+ + + @if (this.AuthenticationState == AuthenticationStateKind.Fail) + { +
+ +
+ } + + @if (this.AuthenticationState == AuthenticationStateKind.ServerFail) + { +
+ +
+ } +
@@ -52,19 +70,13 @@ break; case AuthenticationStateKind.Fail: + case AuthenticationStateKind.ServerFail: break; }
- @if (this.AuthenticationState == AuthenticationStateKind.Fail) - { -
- -
- } -
@code{ @@ -101,12 +113,12 @@ this.AuthenticationState = AuthenticationStateKind.Authenticating; StateHasChanged(); - if (AuthenticationService != null) + if (this.AuthenticationService != null) { this.AuthenticationState = await AuthenticationService.Login(AuthenticationDto); } - if (NavigationManager != null && this.AuthenticationState == AuthenticationStateKind.Success) + if (this.NavigationManager != null && this.AuthenticationState == AuthenticationStateKind.Success) { NavigationManager.NavigateTo("/"); } diff --git a/COMETwebapp/Components/ModelDashboard/ElementDashboard.razor b/COMETwebapp/Components/ModelDashboard/Elements/ElementDashboard.razor similarity index 98% rename from COMETwebapp/Components/ModelDashboard/ElementDashboard.razor rename to COMETwebapp/Components/ModelDashboard/Elements/ElementDashboard.razor index 071e7d62..687d0694 100644 --- a/COMETwebapp/Components/ModelDashboard/ElementDashboard.razor +++ b/COMETwebapp/Components/ModelDashboard/Elements/ElementDashboard.razor @@ -29,12 +29,11 @@ Copyright (c) 2022 RHEA System S.A. - @code { /// /// ElementDefinition represented in graphs /// - public List Data { get; set; } + public List? Data { get; set; } /// /// Listeners for the components to update it with ISession diff --git a/COMETwebapp/Components/ModelDashboard/Elements/ElementDomainProgress.razor b/COMETwebapp/Components/ModelDashboard/Elements/ElementDomainProgress.razor new file mode 100644 index 00000000..aae8f47f --- /dev/null +++ b/COMETwebapp/Components/ModelDashboard/Elements/ElementDomainProgress.razor @@ -0,0 +1,57 @@ + + +@if (this.Data != null) +{ + var identifiedElements = Math.Round((double)this.IdentifiedElements.Count * 100 / this.Data.Count); + var otherElements = 100 - identifiedElements; +
+
+ + + @otherElements % + + + @identifiedElements % + + +
+ + +
+} + +@code { + /// + /// s owned by the active domain + /// + [Parameter] + public List? Data { get; set; } + + + /// + /// s identified as unused or unreferenced + /// + [Parameter] + public List IdentifiedElements { get; set; } + +} diff --git a/COMETwebapp/Components/ModelDashboard/Elements/ElementTable.razor b/COMETwebapp/Components/ModelDashboard/Elements/ElementTable.razor new file mode 100644 index 00000000..dd3c6ef6 --- /dev/null +++ b/COMETwebapp/Components/ModelDashboard/Elements/ElementTable.razor @@ -0,0 +1,56 @@ + + +@if(this.Elements != null && this.Elements.Count != 0) +{ +
+ + + + Element + + + + @foreach(var element in this.Elements) + { + + @element.Name + + } + + +
+} else +{ +
+ No Task to do. +
+} + + +@code { + /// + /// All to complete + /// + [Parameter] + public List? Elements { get; set; } +} diff --git a/COMETwebapp/Components/ModelDashboard/UnreferencedElements.razor b/COMETwebapp/Components/ModelDashboard/Elements/UnreferencedElements.razor similarity index 63% rename from COMETwebapp/Components/ModelDashboard/UnreferencedElements.razor rename to COMETwebapp/Components/ModelDashboard/Elements/UnreferencedElements.razor index 48e99584..e07431c5 100644 --- a/COMETwebapp/Components/ModelDashboard/UnreferencedElements.razor +++ b/COMETwebapp/Components/ModelDashboard/Elements/UnreferencedElements.razor @@ -26,38 +26,51 @@ Copyright (c) 2022 RHEA System S.A. @inject IIterationService IterationService @implements IDisposable -
-
-
-

Unreferenced Elements

+@if (this.Data != null && this.UnReferencedElements != null) +{ +
+
+
+

Unreferenced Elements

+
+
+ + + +
-
- - - -
-
- - + - - - - - - + + + + + +
-
- -
-
+ + + + } + else if(participantRole != null && participantRole.Name.Equals("Domain Expert")) + { + + } +
+} @code { /// @@ -130,4 +143,13 @@ Copyright (c) 2022 RHEA System S.A. { this.NavigationManager.NavigateTo($"ModelDashboard/ElementsDetails?criteria={criteria}&domain={domain}"); } + + /// + /// Gets owned by the current domain + /// + /// s to filter + public List? FilterDomain(List? elements) + { + return elements?.FindAll(e => e.Owner == this.ISessionAnchor.CurrentDomainOfExpertise); + } } diff --git a/COMETwebapp/Components/ModelDashboard/UnusedElements.razor b/COMETwebapp/Components/ModelDashboard/Elements/UnusedElements.razor similarity index 57% rename from COMETwebapp/Components/ModelDashboard/UnusedElements.razor rename to COMETwebapp/Components/ModelDashboard/Elements/UnusedElements.razor index 1b2f374a..320591cb 100644 --- a/COMETwebapp/Components/ModelDashboard/UnusedElements.razor +++ b/COMETwebapp/Components/ModelDashboard/Elements/UnusedElements.razor @@ -26,50 +26,63 @@ Copyright (c) 2022 RHEA System S.A. @inject IIterationService IterationService @implements IDisposable -
-
-
-

Unused Elements

+@if(this.Data != null && this.UnUsedElements != null) +{ +
+
+
+

Unused Elements

+
+
+ + + +
-
- - - -
-
- - - - - + - - - -
- -
-
- -
-
+ + + + + + +
+ +
+
+ + + } + else if(participantRole != null && participantRole.Name.Equals("Domain Expert")) + { + + } +
+} @code { /// /// Data in the graph /// [Parameter] - public List Data { get; set; } + public List? Data { get; set; } /// /// List of unused element defintion from the opened definition /// - private List UnUsedElements { get; set; } + private List? UnUsedElements { get; set; } /// /// Listeners for the components to update it with ISession @@ -130,4 +143,13 @@ Copyright (c) 2022 RHEA System S.A. { this.NavigationManager.NavigateTo($"ModelDashboard/ElementsDetails?criteria={criteria}&domain={domain}"); } + + /// + /// Gets owned by the current domain + /// + /// s to filter + public List? FilterDomain(List? elements) + { + return elements?.FindAll(e => e.Owner == this.ISessionAnchor.CurrentDomainOfExpertise); + } } diff --git a/COMETwebapp/Components/ModelDashboard/DefaultValues.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/DefaultValues.razor similarity index 100% rename from COMETwebapp/Components/ModelDashboard/DefaultValues.razor rename to COMETwebapp/Components/ModelDashboard/ParameterValues/DefaultValues.razor diff --git a/COMETwebapp/Components/ModelDashboard/DonutDashboard.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/DonutDashboard.razor similarity index 100% rename from COMETwebapp/Components/ModelDashboard/DonutDashboard.razor rename to COMETwebapp/Components/ModelDashboard/ParameterValues/DonutDashboard.razor diff --git a/COMETwebapp/Components/ModelDashboard/ParameterDashboard.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDashboard.razor similarity index 71% rename from COMETwebapp/Components/ModelDashboard/ParameterDashboard.razor rename to COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDashboard.razor index b1706424..3a7f991e 100644 --- a/COMETwebapp/Components/ModelDashboard/ParameterDashboard.razor +++ b/COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDashboard.razor @@ -23,19 +23,31 @@ Copyright (c) 2022 RHEA System S.A. @inject IIterationService IterationService @implements IDisposable -
-
- -
-
-
- +@{ + var participantRole = this.ISessionAnchor.GetParticipant()?.Role; +} +@if(participantRole != null && participantRole.Name.Equals("Model Administrator")) +{ +
+
+
-
- +
+
+ +
+
+ +
-
+} else if(participantRole != null && participantRole.Name.Equals("Domain Expert")) +{ +
+ +
+} + @code { /// @@ -70,7 +82,7 @@ Copyright (c) 2022 RHEA System S.A. /// Filter data to show in the graph /// /// List of all data in the project - /// The list of filtered + /// The list of filtered public List Filter(List? data) { var result = new List(); @@ -108,6 +120,16 @@ Copyright (c) 2022 RHEA System S.A. return result; } + /// + /// Filter data for the active domain to show in the graph + /// + /// List of all data in the iteration + /// The list of filtered + public List FilterDomain(List? data) + { + return this.Filter(data?.FindAll(d => d.Owner == this.ISessionAnchor.CurrentDomainOfExpertise)); + } + /// /// Initialize component at first render and after session update /// @@ -123,6 +145,15 @@ Copyright (c) 2022 RHEA System S.A. this.StateHasChanged(); })); } + + if (!this.listeners.TryGetValue("DomainChanged", out listener)) + { + this.listeners.Add("DomainChanged", CDPMessageBus.Current.Listen().Subscribe(x => + { + this.InitializeData(); + this.StateHasChanged(); + })); + } } /// diff --git a/COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDomainProgress.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDomainProgress.razor new file mode 100644 index 00000000..34239b6e --- /dev/null +++ b/COMETwebapp/Components/ModelDashboard/ParameterValues/ParameterDomainProgress.razor @@ -0,0 +1,93 @@ + + +
+
+
+
+

Publishable Parameters

+
+
+ + + +
+
+ @if(this.Data != null) + { + var publishedValues = Math.Round((double)this.Data.FindAll(d => d.Published.SequenceEqual(d.ActualValue)).Count * 100 / this.Data.Count); + var publishableValues = 100 - publishedValues; +
+ + + @publishedValues % + + + @publishableValues % + + +
+ + + } + +
+
+
+
+

Actual Values as Default

+
+
+ + + +
+
+ @if(this.Data != null) + { + var defaultValues = Math.Round((double)this.Data.FindAll(d => d.ActualValue.Count(el => !el.Equals("-")) == 0).Count * 100 / this.Data.Count); + var notDefaultValues = 100 - defaultValues; + var parameterValueSets = this.Data.FindAll(d => d.ActualValue.Count(el => !el.Equals("-")) == 0); +
+ + + @notDefaultValues % + + + @defaultValues % + + +
+ + + } +
+
+ +@code { + /// + /// s owned by the active domain + /// + [Parameter] + public List? Data { get; set; } + +} diff --git a/COMETwebapp/Components/ModelDashboard/PublishedParameters.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/PublishedParameters.razor similarity index 100% rename from COMETwebapp/Components/ModelDashboard/PublishedParameters.razor rename to COMETwebapp/Components/ModelDashboard/ParameterValues/PublishedParameters.razor diff --git a/COMETwebapp/Components/ModelDashboard/ParameterValues/ToDoTable.razor b/COMETwebapp/Components/ModelDashboard/ParameterValues/ToDoTable.razor new file mode 100644 index 00000000..2fcc2a18 --- /dev/null +++ b/COMETwebapp/Components/ModelDashboard/ParameterValues/ToDoTable.razor @@ -0,0 +1,76 @@ + + +@if(this.ParameterValueSets != null && this.ParameterValueSets.Count != 0) +{ +
+ + + + Element + Parameter + Option + State + + + + @foreach(var parameterValueSet in this.ParameterValueSets) + { + var parameter = (Parameter)parameterValueSet.Container; + var element = (ElementDefinition)parameter.Container; + + @element.Name + @parameter.ParameterType.Name + @if(parameterValueSet.ActualOption != null) + { + @parameterValueSet.ActualOption?.Name + } else + { + - + } + @if(parameterValueSet.ActualState != null) + { + @parameterValueSet.ActualState?.Name + } else + { + - + } + + } + + +
+} else +{ +
+ No Task to do. +
+} + + +@code { + /// + /// All to complete + /// + [Parameter] + public List? ParameterValueSets { get; set; } +} diff --git a/COMETwebapp/Components/ParameterValueSetRender/CompoundParameter.razor b/COMETwebapp/Components/ParameterValueSetRender/CompoundParameter.razor index e3ebbb5f..7bc01377 100644 --- a/COMETwebapp/Components/ParameterValueSetRender/CompoundParameter.razor +++ b/COMETwebapp/Components/ParameterValueSetRender/CompoundParameter.razor @@ -22,10 +22,10 @@ Copyright (c) 2022 RHEA System S.A.
-
+
@Component?.ShortName
-
+
@if(this.Component != null) { @if(this.Component.ParameterType.NumberOfValues == 1) diff --git a/COMETwebapp/Components/ParameterValueSetRender/ScalarParameter.razor b/COMETwebapp/Components/ParameterValueSetRender/ScalarParameter.razor index 9f0e9886..b358bf3e 100644 --- a/COMETwebapp/Components/ParameterValueSetRender/ScalarParameter.razor +++ b/COMETwebapp/Components/ParameterValueSetRender/ScalarParameter.razor @@ -34,9 +34,13 @@ Copyright (c) 2022 RHEA System S.A. { @if(this.IsManualEditable == true || this.IsReferenceEditable == true) { -
- - [@Scale] +
+
+ +
+
+ [@Scale] +
} else { diff --git a/COMETwebapp/Components/Tooltip.razor.css b/COMETwebapp/Components/Tooltip.razor.css index 5c3946b6..0fe09696 100644 --- a/COMETwebapp/Components/Tooltip.razor.css +++ b/COMETwebapp/Components/Tooltip.razor.css @@ -12,6 +12,10 @@ bottom: 10%; } +.bottom-15 { + bottom: 15%; +} + .bottom-25 { bottom: -25%; } diff --git a/COMETwebapp/Components/UserPreferences.razor b/COMETwebapp/Components/UserPreferences.razor index adaae841..f6e3b5ea 100644 --- a/COMETwebapp/Components/UserPreferences.razor +++ b/COMETwebapp/Components/UserPreferences.razor @@ -35,7 +35,7 @@ Copyright (c) 2022 RHEA System S.A. @numberUpdates } - +
@@ -54,18 +54,21 @@ Copyright (c) 2022 RHEA System S.A.
-
- @if(this.ISessionAnchor.OpenIteration is not null) - { - var IterationDomains = this.ISessionAnchor.Session.QueryDomainOfExpertise(this.ISessionAnchor.OpenIteration).OrderBy(i => i.Name); - - } -
+ @if(this.ISessionAnchor.GetParticipant()?.Domain.Count > 1) + { +
+ @if(this.ISessionAnchor.OpenIteration is not null) + { + var IterationDomains = this.ISessionAnchor.Session.QueryDomainOfExpertise(this.ISessionAnchor.OpenIteration).OrderBy(i => i.Name); + + } +
+ } @if(this.numberUpdates != 0) { @@ -124,6 +127,11 @@ Copyright (c) 2022 RHEA System S.A. ///
private int numberUpdates { get; set; } = 0; + /// + /// for user preferences + /// + private BSPopover? bSPopover; + /// /// Listeners for the components to update it with ISession /// @@ -228,4 +236,14 @@ Copyright (c) 2022 RHEA System S.A. { this.NavigationManager.NavigateTo("/SubscriptionDashboard"); } + + /// + /// Close Popover component when the mouse leaves the area + /// + /// from onmouseleave event + private async Task ClosePopover(MouseEventArgs e) + { + if (bSPopover != null) + await bSPopover.ToggleAsync(); + } } diff --git a/COMETwebapp/Pages/ModelDashboard/ModelDashboard.razor b/COMETwebapp/Pages/ModelDashboard/ModelDashboard.razor index fa6d9d8a..fd8e1a78 100644 --- a/COMETwebapp/Pages/ModelDashboard/ModelDashboard.razor +++ b/COMETwebapp/Pages/ModelDashboard/ModelDashboard.razor @@ -71,17 +71,24 @@ Copyright (c) 2022 RHEA System S.A. FilteringMode="DataGridFilteringMode.Contains"/>
} - @if(iteration != null && this.ParameterTypeNames.Count != 0){ -
-
Filter on Parameter Type:
- +
Filter on Parameter Type:
+ -
+
+ } }
diff --git a/COMETwebapp/Pages/ParameterEditor/ParameterEditor.razor b/COMETwebapp/Pages/ParameterEditor/ParameterEditor.razor index e547bf4d..bec8ec33 100644 --- a/COMETwebapp/Pages/ParameterEditor/ParameterEditor.razor +++ b/COMETwebapp/Pages/ParameterEditor/ParameterEditor.razor @@ -97,11 +97,11 @@ Copyright (c) 2022 RHEA System S.A.
}
-
+
- Edition Mode + Edit Mode
diff --git a/COMETwebapp/SessionManagement/AuthenticationDto.cs b/COMETwebapp/SessionManagement/AuthenticationDto.cs index be8cbaf7..2e9137cb 100644 --- a/COMETwebapp/SessionManagement/AuthenticationDto.cs +++ b/COMETwebapp/SessionManagement/AuthenticationDto.cs @@ -24,6 +24,8 @@ namespace COMETwebapp.SessionManagement { + using System.ComponentModel.DataAnnotations; + /// /// Authentication information to connect to an E-TM-10-25 data source /// @@ -32,16 +34,20 @@ public class AuthenticationDto /// /// Gets or sets the address of the datasource to connect to /// + [Required] + [Url] public string? SourceAddress { get; set; } /// /// Gets or sets the username to authenticate with /// + [Required] public string? UserName { get; set; } /// /// Gets or sets the password to authenticate with /// + [Required] public string? Password { get; set; } } diff --git a/COMETwebapp/SessionManagement/AuthenticationService.cs b/COMETwebapp/SessionManagement/AuthenticationService.cs index 2823e833..fb9ba874 100644 --- a/COMETwebapp/SessionManagement/AuthenticationService.cs +++ b/COMETwebapp/SessionManagement/AuthenticationService.cs @@ -1,131 +1,131 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2022 RHEA System S.A. -// -// Author: Justine Veirier d'aiguebonne, Sam Gerené, Alex Vorobiev, Alexander van Delft -// -// This file is part of COMET WEB Community Edition -// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. -// -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The COMET WEB 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 -// Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace COMETwebapp.SessionManagement -{ - using System; - using CDP4Dal; - using CDP4Dal.DAL; +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2022 RHEA System S.A. +// +// Author: Justine Veirier d'aiguebonne, Sam Gerené, Alex Vorobiev, Alexander van Delft +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB 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 +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.SessionManagement +{ + using System; + using CDP4Dal; + using CDP4Dal.DAL; using CDP4Dal.Exceptions; - using CDP4ServicesDal; - - using Microsoft.AspNetCore.Components.Authorization; - - /// - /// The purpose of the is to authenticate against - /// a E-TM-10-25 Annex C.2 data source - /// - public class AuthenticationService : IAuthenticationService - { - /// - /// The (injected) - /// - private readonly AuthenticationStateProvider authStateProvider; - - /// - /// The (injected) that provides access to the - /// - private readonly ISessionAnchor sessionAnchor; - - /// - /// Initializes a new instance of the class. - /// - /// - /// The (injected) that provides access to the - /// - /// - /// The (injected) - /// - public AuthenticationService(ISessionAnchor sessionAnchor, AuthenticationStateProvider authenticationStateProvider) - { - this.authStateProvider = authenticationStateProvider; - this.sessionAnchor = sessionAnchor; - } - - /// - /// Login (authenticate) with authentication information to a data source - /// - /// - /// The authentication information with data source, username and password - /// - /// - /// when the authentication is done and the ISession opened - /// - public async Task Login(AuthenticationDto authenticationDto) - { - if(authenticationDto.SourceAddress != null) - { - var uri = new Uri(authenticationDto.SourceAddress); - var dal = new CdpServicesDal(); - var credentials = new Credentials(authenticationDto.UserName, authenticationDto.Password, uri); - - this.sessionAnchor.Session = new Session(dal, credentials); + using Microsoft.AspNetCore.Components.Authorization; + + /// + /// The purpose of the is to authenticate against + /// a E-TM-10-25 Annex C.2 data source + /// + public class AuthenticationService : IAuthenticationService + { + /// + /// The (injected) + /// + private readonly AuthenticationStateProvider authStateProvider; + + /// + /// The (injected) that provides access to the + /// + private readonly ISessionAnchor sessionAnchor; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The (injected) that provides access to the + /// + /// + /// The (injected) + /// + public AuthenticationService(ISessionAnchor sessionAnchor, AuthenticationStateProvider authenticationStateProvider) + { + this.authStateProvider = authenticationStateProvider; + this.sessionAnchor = sessionAnchor; + } + + /// + /// Login (authenticate) with authentication information to a data source + /// + /// + /// The authentication information with data source, username and password + /// + /// + /// when the authentication is done and the ISession opened + /// + public async Task Login(AuthenticationDto authenticationDto) + { + if(authenticationDto.SourceAddress != null) + { + var uri = new Uri(authenticationDto.SourceAddress); + var dal = new CdpServicesDal(); + var credentials = new Credentials(authenticationDto.UserName, authenticationDto.Password, uri); + + this.sessionAnchor.Session = new Session(dal, credentials); } - else - { - return AuthenticationStateKind.Fail; - } - - try - { - await this.sessionAnchor.Session.Open(); - this.sessionAnchor.IsSessionOpen = this.sessionAnchor.GetSiteDirectory() != null; - ((CometWebAuthStateProvider)this.authStateProvider).NotifyAuthenticationStateChanged(); - - if (this.sessionAnchor.IsSessionOpen) - { - return AuthenticationStateKind.Success; - } - else - { - return AuthenticationStateKind.Fail; - } - } - catch (DalReadException ex) - { - Console.WriteLine(ex); - - this.sessionAnchor.IsSessionOpen = false; - return AuthenticationStateKind.Fail; - } - } - - /// - /// Logout from the data source - /// - /// - /// a - /// - public async Task Logout() - { - if (this.sessionAnchor.Session != null) - { - await this.sessionAnchor.Close(); - } - - ((CometWebAuthStateProvider)this.authStateProvider).NotifyAuthenticationStateChanged(); - } - } -} + else + { + return AuthenticationStateKind.Fail; + } + + try + { + await this.sessionAnchor.Session.Open(); + this.sessionAnchor.IsSessionOpen = this.sessionAnchor.GetSiteDirectory() != null; + ((CometWebAuthStateProvider)this.authStateProvider).NotifyAuthenticationStateChanged(); + + if (this.sessionAnchor.IsSessionOpen) + { + return AuthenticationStateKind.Success; + } + else + { + return AuthenticationStateKind.Fail; + } + } + catch (DalReadException) + { + this.sessionAnchor.IsSessionOpen = false; + return AuthenticationStateKind.Fail; + } catch(HttpRequestException) + { + this.sessionAnchor.IsSessionOpen = false; + return AuthenticationStateKind.ServerFail; + } + } + + /// + /// Logout from the data source + /// + /// + /// a + /// + public async Task Logout() + { + if (this.sessionAnchor.Session != null) + { + await this.sessionAnchor.Close(); + } + + ((CometWebAuthStateProvider)this.authStateProvider).NotifyAuthenticationStateChanged(); + } + } +} diff --git a/COMETwebapp/SessionManagement/AuthenticationStateKind.cs b/COMETwebapp/SessionManagement/AuthenticationStateKind.cs index 788ed63c..a4ac44fc 100644 --- a/COMETwebapp/SessionManagement/AuthenticationStateKind.cs +++ b/COMETwebapp/SessionManagement/AuthenticationStateKind.cs @@ -34,6 +34,11 @@ public enum AuthenticationStateKind ///
None, + /// + /// Indicates that the given source address is impossible to fetch + /// + ServerFail, + /// /// Indicates that authentication is in progress /// diff --git a/COMETwebapp/SessionManagement/CometWebAuthStateProvider.cs b/COMETwebapp/SessionManagement/CometWebAuthStateProvider.cs index 8ff7c1fc..d6683e77 100644 --- a/COMETwebapp/SessionManagement/CometWebAuthStateProvider.cs +++ b/COMETwebapp/SessionManagement/CometWebAuthStateProvider.cs @@ -1,116 +1,116 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2022 RHEA System S.A. -// -// Author: Justine Veirier d'aiguebonne, Sam Gerené, Alex Vorobiev, Alexander van Delft -// -// This file is part of COMET WEB Community Edition -// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. -// -// The COMET WEB Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The COMET WEB 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 -// Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace COMETwebapp.SessionManagement -{ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2022 RHEA System S.A. +// +// Author: Justine Veirier d'aiguebonne, Sam Gerené, Alex Vorobiev, Alexander van Delft +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB 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 +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.SessionManagement +{ using System.Security.Claims; - + using CDP4Common.SiteDirectoryData; - - using Microsoft.AspNetCore.Components.Authorization; - - /// - /// Provides information about the authentication state of the current user. - /// - public class CometWebAuthStateProvider : AuthenticationStateProvider - { - /// - /// The used to get access to the - /// - private readonly ISessionAnchor sessionAnchor; - - /// - /// Initializes a new instance of the - /// - /// - /// The (injected) used to get access to the - /// - public CometWebAuthStateProvider(ISessionAnchor sessionAnchor) - { - this.sessionAnchor = sessionAnchor; - } - - /// - /// Asynchronously gets an that describes the current user. - /// - /// - /// A that, when resolved, gives an instance that describes the current user. - /// - public override async Task GetAuthenticationStateAsync() - { - ClaimsIdentity identity; - if (!this.sessionAnchor.IsSessionOpen) - { - identity = new ClaimsIdentity(); + + using Microsoft.AspNetCore.Components.Authorization; + + /// + /// Provides information about the authentication state of the current user. + /// + public class CometWebAuthStateProvider : AuthenticationStateProvider + { + /// + /// The used to get access to the + /// + private readonly ISessionAnchor sessionAnchor; + + /// + /// Initializes a new instance of the + /// + /// + /// The (injected) used to get access to the + /// + public CometWebAuthStateProvider(ISessionAnchor sessionAnchor) + { + this.sessionAnchor = sessionAnchor; + } + + /// + /// Asynchronously gets an that describes the current user. + /// + /// + /// A that, when resolved, gives an instance that describes the current user. + /// + public override async Task GetAuthenticationStateAsync() + { + ClaimsIdentity identity; + if (!this.sessionAnchor.IsSessionOpen) + { + identity = new ClaimsIdentity(); } - else - { - var person = this.sessionAnchor.Session.ActivePerson; - identity = CreateClaimsIdentity(person); - } - - return await Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity))); - } - - /// - /// Creates a based on a - /// - /// - /// The on the basis of which the is created - /// - /// - /// an instance of - /// - /// - /// When the is null an anonymous is returned - /// - private static ClaimsIdentity CreateClaimsIdentity(Person person) - { - ClaimsIdentity identity; - - if (person.Name == null) - { - identity = new ClaimsIdentity(); - } else - { - var claim = new List - { - new Claim(ClaimTypes.Name, person.Name) - }; - - identity = new ClaimsIdentity(claim, "10-25 Authenticated"); - } - - return identity; - } - - /// - /// Force the event to be raised - /// - public void NotifyAuthenticationStateChanged() - { - this.NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); - } - } -} + else + { + var person = this.sessionAnchor.Session.ActivePerson; + identity = CreateClaimsIdentity(person); + } + + return await Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity))); + } + + /// + /// Creates a based on a + /// + /// + /// The on the basis of which the is created + /// + /// + /// an instance of + /// + /// + /// When the is null an anonymous is returned + /// + private static ClaimsIdentity CreateClaimsIdentity(Person person) + { + ClaimsIdentity identity; + + if (person.Name == null) + { + identity = new ClaimsIdentity(); + } else + { + var claim = new List + { + new Claim(ClaimTypes.Name, person.Name) + }; + + identity = new ClaimsIdentity(claim, "10-25 Authenticated"); + } + + return identity; + } + + /// + /// Force the event to be raised + /// + public void NotifyAuthenticationStateChanged() + { + this.NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); + } + } +} diff --git a/COMETwebapp/SessionManagement/ISessionAnchor.cs b/COMETwebapp/SessionManagement/ISessionAnchor.cs index 8da4406c..dead5835 100644 --- a/COMETwebapp/SessionManagement/ISessionAnchor.cs +++ b/COMETwebapp/SessionManagement/ISessionAnchor.cs @@ -121,5 +121,10 @@ public interface ISessionAnchor /// /// List of Things to update in the session Task UpdateThings(IEnumerable thingsToUpdate); + + /// + /// Gets ths in the opened iteration + /// + Participant? GetParticipant(); } } diff --git a/COMETwebapp/SessionManagement/SessionAnchor.cs b/COMETwebapp/SessionManagement/SessionAnchor.cs index d6bd06fe..e6896524 100644 --- a/COMETwebapp/SessionManagement/SessionAnchor.cs +++ b/COMETwebapp/SessionManagement/SessionAnchor.cs @@ -166,7 +166,7 @@ public IEnumerable GetParticipantModels() public IEnumerable GetModelDomains(EngineeringModelSetup? modelSetup) { var domains = new List(); - modelSetup?.Participant.FindAll(p => p.Person.Name.Equals(this.Session.ActivePerson.Name)).ForEach(p => p.Domain.ForEach(d => domains.Add(d))); + modelSetup?.Participant.FindAll(p => p.Person.Iid.Equals(this.Session.ActivePerson.Iid)).ForEach(p => p.Domain.ForEach(d => domains.Add(d))); return domains.DistinctBy(d => d.Name).OrderBy(d => d.Name); } @@ -284,5 +284,14 @@ public async Task UpdateThings(IEnumerable thingsToUpdate) Console.WriteLine($"The update operation failed: {ex.Message}"); } } + + /// + /// Gets the in the opened iteration + /// + public Participant? GetParticipant() + { + return this.GetSiteDirectory().Model.Find(m => m.IterationSetup.Contains(this.OpenIteration?.IterationSetup))? + .Participant.Find(p => p.Person.Iid == this.Session.ActivePerson.Iid); + } } } \ No newline at end of file diff --git a/COMETwebapp/Shared/Header.razor b/COMETwebapp/Shared/Header.razor index 5316c31b..07b93a5a 100644 --- a/COMETwebapp/Shared/Header.razor +++ b/COMETwebapp/Shared/Header.razor @@ -26,15 +26,17 @@