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

Feat: create generic strip_struct_metadata to remove surplus fields from Struct #54

Open
4 tasks
nelsonic opened this issue Aug 26, 2023 · 0 comments
Open
4 tasks
Assignees
Labels
chore a tedious but necessary task often paying technical debt discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or request help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Aug 26, 2023

At present we have a strip_struct_metadata/1 function is hidden in:
https://github.com/dwyl/auth_plug/blob/da40aca75d5ecc0fc016023f4a61eb6f4b7cfb6f/lib/auth_plug_helpers.ex#L18C1-L33C6

@doc """
`strip_struct_metadata/1` removes the Ecto Struct metadata from a struct.
This is essential before attempting to create a JWT as `Jason.encode/2`
chokes on any invalid data. See: github.com/dwyl/auth_plug/issues/16
"""
def strip_struct_metadata(struct) do
  struct
  |> Map.delete(:__meta__)
  |> Map.delete(:__struct__)
  # association
  |> Map.delete(:statuses)
  # association
  |> Map.delete(:login_logs)
  # binary
  |> Map.delete(:email_hash)
end

We can easily make this function generic and reusable by accepting a second argument field_list.

Todo

  • Create the tests (borrow from auth_plug and extend with field_list)
  • " function definition
  • " PR
  • Publish new version of package to hex.pm
@nelsonic nelsonic added enhancement New feature or request help wanted Extra attention is needed chore a tedious but necessary task often paying technical debt priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished discuss Share your constructive thoughts on how to make progress with this issue T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies labels Aug 26, 2023
@nelsonic nelsonic self-assigned this Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore a tedious but necessary task often paying technical debt discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or request help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
Status: More ToDo ThanCanEver Be Done
Status: No status
Development

No branches or pull requests

1 participant