-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Implement API to GDPR delete users #3224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Janis4411
merged 1 commit into
main
from
jv/SODEV-2997-Implement-API-to-GDPR-delete-users
Apr 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| INTERNAL_API_TOKEN=supersecrettoken |
This file contains hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Api | ||
| class ApiController < ActionController::API | ||
| include ActionController::HttpAuthentication::Token::ControllerMethods | ||
|
|
||
| before_action :authenticate! | ||
|
|
||
| def authenticate! | ||
| authenticate_or_request_with_http_token do |token, _options| | ||
| ActiveSupport::SecurityUtils.secure_compare( | ||
| token, | ||
| ENV.fetch('INTERNAL_API_TOKEN', nil) | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Api | ||
| module Internal | ||
| class UsersController < Api::ApiController | ||
| def destroy | ||
| user = ExternalUser.where(external_id: params[:id]).first | ||
|
|
||
| return head :not_found unless user | ||
|
|
||
| user.soft_delete | ||
| head :ok | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
db/migrate/20260421114010_add_deleted_at_to_external_users.rb
This file contains hidden or 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 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToExternalUsers < ActiveRecord::Migration[8.0] | ||
| def change | ||
| add_column :external_users, :deleted_at, :datetime, null: true, default: nil | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Api::ApiController do | ||
| controller(described_class) do | ||
| def index | ||
| head :ok | ||
| end | ||
| end | ||
|
|
||
| before do | ||
| routes.draw do | ||
| get 'index' => 'api/api#index' | ||
| end | ||
| end | ||
|
|
||
| describe 'authentication' do | ||
| context 'with valid token' do | ||
| it 'allows the request' do | ||
|
Janis4411 marked this conversation as resolved.
|
||
| request.headers['Authorization'] = 'Bearer supersecrettoken' | ||
|
|
||
| get :index | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| end | ||
| end | ||
|
|
||
| context 'with invalid token' do | ||
| it 'returns 401 Unauthorized' do | ||
| request.headers['Authorization'] = 'Bearer invalid_token' | ||
|
|
||
| get :index | ||
|
|
||
| expect(response).to have_http_status(:unauthorized) | ||
| end | ||
| end | ||
|
|
||
| context 'without token' do | ||
|
arkirchner marked this conversation as resolved.
|
||
| it 'returns 401 Unauthorized' do | ||
| get :index | ||
|
|
||
| expect(response).to have_http_status(:unauthorized) | ||
| end | ||
| end | ||
|
|
||
| context 'without the INTERNAL_API_TOKEN being set' do | ||
| it 'returns 401 Unauthorized' do | ||
| allow(ENV) | ||
| .to receive(:fetch) | ||
| .with('INTERNAL_API_TOKEN', nil) | ||
| .and_return(nil) | ||
|
|
||
| request.headers['Authorization'] = "Bearer #{ENV.fetch('INTERNAL_API_TOKEN', nil)}" | ||
| get :index | ||
|
|
||
| expect(response).to have_http_status(:unauthorized) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,26 @@ | ||
| # frozen_string_literal: true | ||
|
arkirchner marked this conversation as resolved.
|
||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe 'DELETE Users API', type: :request do | ||
| include ActiveSupport::Testing::TimeHelpers | ||
|
|
||
| let(:headers) { {'Authorization' => 'Bearer supersecrettoken'} } | ||
|
|
||
| describe 'DELETE /api/internal/users' do | ||
| it 'soft deletes a user' do | ||
| user = create(:external_user, external_id: '123456') | ||
|
|
||
| freeze_time | ||
|
|
||
| expect { delete '/api/internal/users/123456', headers: headers } | ||
| .to change { user.reload.deleted_at }.to(Time.zone.now) | ||
| end | ||
|
|
||
| it 'returns an error if the user is not found' do | ||
| delete '/api/internal/users/123456', | ||
| headers: headers | ||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.