-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contact): display Altinn Servicedesk contact if user belongs to …
…org (#14371) Co-authored-by: Nina Kylstad <nkylstad@gmail.com>
- Loading branch information
1 parent
60ea6c6
commit e33453d
Showing
17 changed files
with
281 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Altinn.Studio.Designer.Helpers; | ||
using Altinn.Studio.Designer.Services.Interfaces; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Altinn.Studio.Designer.Controllers | ||
{ | ||
[Route("designer/api/[controller]")] | ||
[ApiController] | ||
public class ContactController : ControllerBase | ||
{ | ||
private readonly IGitea _giteaService; | ||
|
||
public ContactController(IGitea giteaService) | ||
{ | ||
_giteaService = giteaService; | ||
} | ||
|
||
[AllowAnonymous] | ||
[HttpGet("belongs-to-org")] | ||
public async Task<IActionResult> BelongsToOrg() | ||
{ | ||
bool isNotAuthenticated = !AuthenticationHelper.IsAuthenticated(HttpContext); | ||
if (isNotAuthenticated) | ||
{ | ||
return Ok(new BelongsToOrgDto { BelongsToOrg = false }); | ||
} | ||
|
||
try | ||
{ | ||
var organizations = await _giteaService.GetUserOrganizations(); | ||
return Ok(new BelongsToOrgDto { BelongsToOrg = organizations.Count > 0 }); | ||
} | ||
catch (Exception) | ||
{ | ||
return Ok(new BelongsToOrgDto { BelongsToOrg = false }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
public class BelongsToOrgDto | ||
{ | ||
[JsonPropertyName("belongsToOrg")] | ||
public bool BelongsToOrg { get; set; } | ||
} |
66 changes: 66 additions & 0 deletions
66
backend/tests/Designer.Tests/Controllers/ContactController/FetchBelongsToOrgTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Designer.Tests.Controllers.ApiTests; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Controllers.ContactController; | ||
|
||
public class FetchBelongsToOrgTests : DesignerEndpointsTestsBase<FetchBelongsToOrgTests>, | ||
IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
public FetchBelongsToOrgTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task UsersThatBelongsToOrg_ShouldReturn_True() | ||
{ | ||
string url = "/designer/api/contact/belongs-to-org"; | ||
|
||
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, url); | ||
|
||
var response = await HttpClient.SendAsync(httpRequestMessage); | ||
var responseContent = await response.Content.ReadAsAsync<BelongsToOrgDto>(); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.True(responseContent.BelongsToOrg); | ||
} | ||
|
||
[Fact] | ||
public async Task UsersThatDoNotBelongsToOrg_ShouldReturn_False_IfAnonymousUser() | ||
{ | ||
string configPath = GetConfigPath(); | ||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddJsonFile(configPath, false, false) | ||
.AddJsonStream(GenerateJsonOverrideConfig()) | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
var anonymousClient = Factory.WithWebHostBuilder(builder => | ||
{ | ||
builder.UseConfiguration(configuration); | ||
builder.ConfigureTestServices(services => | ||
{ | ||
services.AddAuthentication("Anonymous") | ||
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("Anonymous", options => { }); | ||
}); | ||
}).CreateDefaultClient(); | ||
|
||
string url = "/designer/api/contact/belongs-to-org"; | ||
|
||
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, url); | ||
|
||
var response = await anonymousClient.SendAsync(httpRequestMessage); | ||
var responseContent = await response.Content.ReadAsAsync<BelongsToOrgDto>(); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.False(responseContent.BelongsToOrg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
frontend/packages/shared/src/getInTouch/providers/PhoneContactProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { type GetInTouchProvider } from '../interfaces/GetInTouchProvider'; | ||
|
||
type PhoneChannel = 'phone' | 'emergencyPhone'; | ||
|
||
const phoneChannelMap: Record<PhoneChannel, string> = { | ||
phone: 'tel:75006299', | ||
emergencyPhone: 'tel:94490002', | ||
}; | ||
|
||
export class PhoneContactProvider implements GetInTouchProvider<PhoneChannel> { | ||
public buildContactUrl(selectedChannel: PhoneChannel): string { | ||
return phoneChannelMap[selectedChannel]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
frontend/studio-root/components/ContactServiceDesk/ContactServiceDesk.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { type ReactElement } from 'react'; | ||
import { GetInTouchWith } from 'app-shared/getInTouch'; | ||
import { EmailContactProvider } from 'app-shared/getInTouch/providers'; | ||
import { StudioList, StudioLink } from '@studio/components'; | ||
import { Trans } from 'react-i18next'; | ||
import { PhoneContactProvider } from 'app-shared/getInTouch/providers/PhoneContactProvider'; | ||
|
||
export const ContactServiceDesk = (): ReactElement => { | ||
const contactByEmail = new GetInTouchWith(new EmailContactProvider()); | ||
const contactByPhone = new GetInTouchWith(new PhoneContactProvider()); | ||
return ( | ||
<StudioList.Root> | ||
<StudioList.Unordered> | ||
<StudioList.Item> | ||
<Trans | ||
i18nKey='contact.serviceDesk.phone' | ||
components={{ | ||
b: <b />, | ||
a: <StudioLink href={contactByPhone.url('phone')}>{null}</StudioLink>, | ||
}} | ||
/> | ||
</StudioList.Item> | ||
|
||
<StudioList.Item> | ||
<Trans | ||
i18nKey='contact.serviceDesk.emergencyPhone' | ||
values={{ phoneNumber: contactByPhone.url('phone') }} | ||
components={{ | ||
b: <b />, | ||
a: <StudioLink href={contactByPhone.url('emergencyPhone')}>{null}</StudioLink>, | ||
}} | ||
/> | ||
</StudioList.Item> | ||
|
||
<StudioList.Item> | ||
<Trans | ||
i18nKey='contact.serviceDesk.email' | ||
values={{ phoneNumber: contactByPhone.url('phone') }} | ||
components={{ | ||
b: <b />, | ||
a: <StudioLink href={contactByEmail.url('serviceOwner')}>{null}</StudioLink>, | ||
}} | ||
/> | ||
</StudioList.Item> | ||
</StudioList.Unordered> | ||
</StudioList.Root> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ContactServiceDesk } from './ContactServiceDesk'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.