Skip to content
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

Introduce helpers (selectors) for anonymise all a subject's records. #97

Merged
merged 3 commits into from
Mar 7, 2023

Conversation

mnbbrown
Copy link
Contributor

@mnbbrown mnbbrown commented Mar 6, 2023

These can be used to anonymise all records that relate to a specific
subject.

You first define a block for a specific subject that returns a list of
anonymisable records.

anonymise do
  selectors do
    for_subject(:user_id) { |user_id| find_all_users(user_id) }
  end
end

You can also use scopes, where, etc when defining your selectors:

anonymise do
  selectors do
    for_subject(:user_id) { |user_id| where(user_id: "user_id") }
  end
end

This can then be used to anonymise all those subject using this API:

ModelName.anonymise_for!(:user_id, "user_1234")

If you attempt to anonymise records with a selector that has not been defined it will throw an error.

@mnbbrown mnbbrown force-pushed the introduce-selectors branch from d3c30ad to eddb72f Compare March 7, 2023 09:56
Copy link

@DragosDumitrache DragosDumitrache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


describe ".anonymise_for!" do
let!(:model_b) do
klass.create!(first_name: "matt", last_name: "brown", company_name: "alpha")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# each of them. If a selector is not defined it will railse an exception.
def anonymise_for!(subject, subject_id)
anonymise_config.
select(subject, subject_id, &:anonymise!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth double checking that each subject responds to anoynmise!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do - what behaviour would you expect? An error being raised?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this 70d18ab?

These can be used to anonymise all records that relate to a specific
subject.

You first define a block for a specific subject that returns a list of
anonymisable records.

```ruby
anonymise do
  selectors do
    for_subject(:user_id) { |user_id| self.select_for_user(user_id) }
  end
end
```

This can then be used to anonymise all those subject using this API:

```ruby
ModelName.anonymise_for!(:user_id, "user_1234")
```

Attempting to use a selector that has not been defined will throw an
error.
@mnbbrown mnbbrown force-pushed the introduce-selectors branch from eddb72f to 5b9d0f2 Compare March 7, 2023 10:22
Copy link

@rliddler rliddler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good to me!

@mnbbrown mnbbrown force-pushed the introduce-selectors branch 2 times, most recently from 88b9da4 to f5bb883 Compare March 7, 2023 11:49
@mnbbrown mnbbrown force-pushed the introduce-selectors branch from f5bb883 to bbad3a0 Compare March 7, 2023 11:53
@mnbbrown mnbbrown merged commit a73da20 into master Mar 7, 2023
@mnbbrown mnbbrown deleted the introduce-selectors branch March 7, 2023 11:56
Tabby added a commit that referenced this pull request Feb 20, 2024
Seems it wasn't updated for #97 either :/
@Tabby Tabby mentioned this pull request Feb 20, 2024
Tabby added a commit that referenced this pull request Feb 20, 2024
Seems it wasn't updated for #97 either :/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants