Skip to content

Commit

Permalink
Merge branch 'master' into sem-dom-1
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Jan 27, 2025
2 parents 398eba8 + 6946b24 commit aafe8d6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 68 deletions.
14 changes: 4 additions & 10 deletions Backend.Tests/Otel/LocationProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Backend.Tests.Otel
{
public class LocationProviderTests
{
private readonly IPAddress TestIpAddress = new(new byte[] { 100, 0, 0, 0 });
private readonly IPAddress TestIpAddress = new([100, 0, 0, 0]);
private IHttpContextAccessor _contextAccessor = null!;
private IMemoryCache _memoryCache = null!;
private Mock<HttpMessageHandler> _handlerMock = null!;
Expand All @@ -26,15 +26,9 @@ public class LocationProviderTests
public void Setup()
{
// Set up HttpContextAccessor with mocked IP
_contextAccessor = new HttpContextAccessor();
var httpContext = new DefaultHttpContext()
{
Connection =
{
RemoteIpAddress = TestIpAddress
}
};
_contextAccessor.HttpContext = httpContext;
var httpContext = new DefaultHttpContext();
httpContext.Request.Headers["X-Original-Forwarded-For"] = TestIpAddress.ToString();
_contextAccessor = new HttpContextAccessor { HttpContext = httpContext };

// Set up MemoryCache
var services = new ServiceCollection();
Expand Down
20 changes: 7 additions & 13 deletions Backend/Otel/LocationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,18 @@ public LocationProvider(IHttpContextAccessor contextAccessor, IMemoryCache memor
// because OtelKernel calls the function for each activity
if (_contextAccessor.HttpContext is { } context)
{
var ipAddress = context.GetServerVariable("HTTP_X_FORWARDED_FOR") ?? context.Connection.RemoteIpAddress?.ToString();
var ipAddressWithoutPort = ipAddress?.Split(':')[0];
var ipAddress = context.Request.Headers["X-Original-Forwarded-For"].ToString();
if (string.IsNullOrEmpty(ipAddress))
{
return null;
}

return await _memoryCache.GetOrCreateAsync(
"location_" + ipAddressWithoutPort,
"location_" + ipAddress,
async (cacheEntry) =>
{
cacheEntry.SlidingExpiration = TimeSpan.FromHours(1);
try
{
return await GetLocationFromIp(ipAddressWithoutPort);
}
catch
{
// TODO consider what to have in catch
Console.WriteLine("Attempted to get location but exception");
throw;
}
return await GetLocationFromIp(ipAddress);
}
);
}
Expand Down
25 changes: 0 additions & 25 deletions docs/user_guide/assets/licenses/frontend_licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5254,31 +5254,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


vanilla-cookieconsent 3.0.1
MIT
MIT License

Copyright (c) 2020-2024 Orest Bida

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


void-elements 3.1.0
MIT
(The MIT License)
Expand Down
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
"redux-thunk": "^3.1.0",
"ts-key-enum": "^2.0.12",
"uuid": "^9.0.1",
"validator": "^13.11.0",
"vanilla-cookieconsent": "^3.0.1"
"validator": "^13.11.0"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
Expand Down
10 changes: 1 addition & 9 deletions src/types/Redux/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { getUserPreferences } from "vanilla-cookieconsent";

import { StoreActionTypes } from "rootRedux/actions";
import { defaultState } from "types/Redux/analyticsReduxTypes";
Expand All @@ -11,22 +10,15 @@ const analyticsSlice = createSlice({
changePageAction: (state, action) => {
state.currentPage = action.payload;
},
updateConsentAction: (state) => {
state.consent = getUserPreferences().acceptType === "all";
},
},
extraReducers: (builder) =>
builder.addCase(StoreActionTypes.RESET, () => defaultState),
});

const { changePageAction, updateConsentAction } = analyticsSlice.actions;
const { changePageAction } = analyticsSlice.actions;

export default analyticsSlice.reducer;

export function changePage(newPage: string): PayloadAction {
return changePageAction(newPage);
}

export function updateConsent(): PayloadAction {
return updateConsentAction();
}
2 changes: 0 additions & 2 deletions src/types/Redux/analyticsReduxTypes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export interface AnalyticsState {
consent: boolean;
currentPage: string;
}

export const defaultState: AnalyticsState = {
consent: false,
currentPage: "",
};

0 comments on commit aafe8d6

Please sign in to comment.