generated from espoo-dev/rails_boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Adds endpoint to delete users account #300
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
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2caebb6
Adds endpoint to delete users account
mattfeg 26b97d6
Adds specs for User account deletion
mattfeg a71726d
Makes the relation deletion be on model level. Refacts destroy_self t…
mattfeg 17e84cb
Fixes migrations conflicts
mattfeg 2a1f8a0
Adds specs for destroy_self User policy
mattfeg ef28fea
Adds new context on destroy_self requests tests
mattfeg f38508a
Fixes spec descripton
mattfeg ed6908f
Uses att_reader on destroy_self operation user attribute
mattfeg 939429c
Refacts destroy_self operation to inhirit from Actor
mattfeg 8b4d202
Removes unecessary destroy calls on destroy_self
mattfeg 318d796
Removes dependent associations recovery for User's model
mattfeg 075b33e
Refacts destroy_self to use attr_reader for password
mattfeg e9a8e4c
Refacts Users destroy_self specs to use Shared Context
mattfeg 055f4ff
Refacts User model and controller to be able to real delete a user re…
mattfeg 843b1c2
Refacts destroy_self for the requested changes
mattfeg 1692c4d
Remove rescues from destroy_self controller. Makes requested changes
mattfeg ea6c3b1
Refacts destroy_self on user controller to reduce unacessary coding
mattfeg 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
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
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
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,62 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Users | ||
| class DestroySelf | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Result = Struct.new(:success?, :error) | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def initialize(user, password) | ||
| @user = user | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @password = password | ||
| end | ||
|
|
||
| def call | ||
| return Result.new(false, "Wrong password") unless valid_password? | ||
|
|
||
| ActiveRecord::Base.transaction do | ||
| destroy_event_procedures! | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| destroy_medical_shifts! | ||
| destroy_patients! | ||
| destroy_procedures! | ||
| destroy_health_insurances! | ||
|
|
||
| @user.destroy | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| Result.new(true, nil) | ||
| rescue StandardError => e | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Result.new(false, e.message) | ||
mattfeg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def valid_password? | ||
| @user.valid_password?(@password) | ||
| end | ||
|
|
||
| def destroy_event_procedures! | ||
| @user.event_procedures.destroy_all | ||
| end | ||
|
|
||
| def destroy_medical_shifts! | ||
| @user.medical_shifts.destroy_all | ||
| end | ||
|
|
||
| def destroy_health_insurances! | ||
| @user.health_insurances.destroy_all | ||
| end | ||
|
|
||
| def destroy_procedures! | ||
| @user.procedures.destroy_all | ||
| end | ||
|
|
||
| def destroy_patients! | ||
| @user.patients.each do |patient| | ||
| if patient.event_procedures.exists?(deleted_at: nil) | ||
| raise ActiveRecord::InvalidForeignKey, "Patient ##{patient.id} has associated procedures" | ||
| end | ||
|
|
||
| patient.destroy | ||
| 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
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 was deleted.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToPatients < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :patients, :deleted_at, :datetime | ||
| add_index :patients, :deleted_at | ||
| end | ||
| end |
8 changes: 8 additions & 0 deletions
8
db/migrate/20250512170525_add_deleted_at_to_health_insurances.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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToHealthInsurances < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :health_insurances, :deleted_at, :datetime | ||
| add_index :health_insurances, :deleted_at | ||
| end | ||
| end |
8 changes: 8 additions & 0 deletions
8
db/migrate/20250512170622_add_deleted_at_to_medical_shifts.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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToMedicalShifts < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :medical_shifts, :deleted_at, :datetime | ||
| add_index :medical_shifts, :deleted_at | ||
| 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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToProcedures < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :procedures, :deleted_at, :datetime | ||
| add_index :procedures, :deleted_at | ||
| 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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToHospitals < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :hospitals, :deleted_at, :datetime | ||
| add_index :hospitals, :deleted_at | ||
| 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,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddDeletedAtToUsers < ActiveRecord::Migration[7.1] | ||
| def change | ||
| add_column :users, :deleted_at, :datetime | ||
| add_index :users, :deleted_at | ||
| end | ||
| end |
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
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
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.