Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature/clean-old-tokens

jobs:
dev-deploy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private async Task AnonymizeUserAsync(User user)
user.DateUpdated = DateTime.UtcNow;
user.PrivacyActivated = true;
user.UserState = UserState.Deleted;
await _tokenServiceV2.DeleteTokensByUserAsync(user);
await _context.SaveChangesAsync();
}

Expand Down
6 changes: 6 additions & 0 deletions coffeecard/CoffeeCard.Library/Services/v2/ITokenService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using CoffeeCard.Models.Entities;

Expand All @@ -8,5 +10,9 @@ public interface ITokenService
Task<string> GenerateMagicLinkToken(User user);
Task<string> GenerateRefreshTokenAsync(User user);
Task<Token> GetValidTokenByHashAsync(string tokenString);

Task DeleteTokenAsync(Token token);

Task DeleteTokensByUserAsync(User user);
}
}
14 changes: 14 additions & 0 deletions coffeecard/CoffeeCard.Library/Services/v2/TokenService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using CoffeeCard.Common.Errors;
Expand Down Expand Up @@ -51,4 +53,16 @@ public async Task<Token> GetValidTokenByHashAsync(string tokenString)
}
return foundToken;
}

public async Task DeleteTokensByUserAsync(User user)
{
var tokens = await _context.Tokens.Where(t => t.UserId == user.Id).ExecuteDeleteAsync();
await _context.SaveChangesAsync();
}

public async Task DeleteTokenAsync(Token token)
{
_context.Tokens.Remove(token);
await _context.SaveChangesAsync();
}
}
12 changes: 12 additions & 0 deletions infrastructure/core.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ module webapp 'modules/webapp.bicep' = {
}
}

module functionApp 'modules/functionApp.bicep' = {
name: '${deployment().name}-function-app'
scope: resourceGroup(sharedResourceGroupName)
params: {
environment: environment
location: location
organizationPrefix: organizationPrefix
sharedResourcesAbbreviation: sharedResourcesAbbreviation
hostingPlanId: appservicePlan.id
}
}

module sqlDb 'modules/sqldatabase.bicep' = {
name: '${deployment().name}-${applicationPrefix}-sqldb'
params: {
Expand Down
34 changes: 34 additions & 0 deletions infrastructure/modules/functionApp.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@allowed(['dev', 'prd'])
param environment string
param location string

param organizationPrefix string
param sharedResourcesAbbreviation string
param hostingPlanId string

resource functionApp 'Microsoft.Web/sites@2021-03-01' = {
name: 'func-${organizationPrefix}-${sharedResourcesAbbreviation}-${environment}'
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlanId
siteConfig: {
appSettings: [
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'dotnet'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
]
ftpsState: 'FtpsOnly'
minTlsVersion: '1.2'
}
httpsOnly: true
}
}
Loading