GithubHelp home page GithubHelp logo

ash-project / ash_paper_trail Goto Github PK

View Code? Open in Web Editor NEW
25.0 8.0 11.0 959 KB

The extension for keeping an audit log of changes to your Ash resources.

Home Page: https://hexdocs.pm/ash_paper_trail

License: MIT License

Elixir 100.00%
ash audit-log elixir paper-trail

ash_paper_trail's Introduction

ash_paper_trail's People

Contributors

dependabot[bot] avatar hwuethrich avatar jechol avatar jimsynz avatar nallwhy avatar pshoukry avatar rgraff avatar zachdaniel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ash_paper_trail's Issues

Optionally associate the change with the actor

Request for feedback: I'd like to associated each version with the actor making the change.

The most straightforward approach IMHO would be to create an :actor relationship and manage it automatically. The syntax could be:

paper_trail do
  belongs_to_actor Users.User, api: Users, allow_nil?: false
end

An alternative approach would follow the builtin change relate_actor and leave relationship itself to be added via mixin.

paper_trail do
  relate_actor :relationship, allow_nil?: false, field: :id
end

Optionally store the name of the action that created the versions

Request for feedback: To provide a more meaningful log of changes, it would be helpful in some instance to record the name of the action that resulted in the creation of the new version.

The syntax that I'm proposing:

paper_trail do 
  store_action_name? true # default is false
end

When enabled an action_name attribute would be added to the version's attributes. This attribute would be allow_nil?: true

Support bulk action

Is your feature request related to a problem? Please describe.

Bulk actions are used for high performance when creating/modifying a large number of records, but ash papertrail does not support bulk actions, so using bulk actions does not result in good performance.

Describe the solution you'd like

If bulk actions are executed, ash papertrail also runs as a bulk action.

Describe alternatives you've considered

I don't have any alternatives.

Express the feature either with a change to resource syntax, or with a change to the resource interface

No syntax changes.

Additional context

Allow changes_only tracking of embedded resources

Embedded resources always contain a complete snapshot of the new embedded resource. First it should abide by the change_tracking_mode and when set to :changes_only should only include the change. It should also be configurable to be overridden if you want changes only for the resource but snapshots for the embedded resource.

paper_trail do
  embedded_resources_change_tracking_mode :changes_only # defaults to the value of change_tracking_mode
end

protocol Jason.Encoder not implemented for embedded resource

One of my resources has attribute :variants, {:array, MyApp.Feature.EmbeddedType}, allow_nil?: false which is a union type. What's the preferred Ashy way to derive the Jason.Encoder?

     ** (EXIT from #PID<0.3411.0>) an exception was raised:
         ** (Ash.Error.Unknown) Context: resolving data on commit MyApp.Feature.update
     
     Unknown Error
     
     Context: resolving data on perform MyApp.Feature.Version.create
     * Context: resolving data on perform MyApp.Feature.Version.create
     
     ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for #MyApp.Feature.EmbeddedTypeA<__meta__: #Ecto.Schema.Metadata<:built, "">, id: "025f3cb7-bbb0-419d-b5df-7971a8deef94", key: #Ash.CiString<"true">,  ...> of type MyApp.Feature.EmbeddedTypeA (a struct), Jason.Encoder protocol must always be explicitly implemented.
     
     If you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:
     
         @derive {Jason.Encoder, only: [....]}
         defstruct ...
     
     It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
     
         @derive Jason.Encoder
         defstruct ...
     
     Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
     
         Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
         Protocol.derive(Jason.Encoder, NameOfTheStruct)
     . This protocol is implemented for the following type(s): Any, Ash.CiString, Ash.Union, Atom, BitString, Date, DateTime, Decimal, Ecto.Association.NotLoaded, Ecto.Schema.Metadata, Float, Integer, Jason.Fragment, Jason.OrderedObject, List, Map, NaiveDateTime, Time

Error with missing `changed?` in context with `bulk_destroy`

Describe the bug

Ash.bulk_destroy!(records, :destroy, %{},
  strategy: [:stream, :atomic, :atomic_batches],
  return_errors?: true
)

** (KeyError) key :changed? not found in: %{private: %{authorize?: true}, bulk_destroy: %{index: 0}}

crashes on
https://github.com/nallwhy/ash_paper_trail/blob/cc5f2c4385f9120ef570b552da505dfd7df941fa/lib/resource/changes/create_new_version.ex#L21

ash_archive uses bulk_destroy.

https://github.com/ash-project/ash_archival/blob/d0763dc10f99d5db8567341fe3e68acdfcbf4a63/lib/ash_archival/resource/changes/archive_related.ex#L52

To Reproduce

nallwhy@cc5f2c4

Expected behavior

no error

** Runtime

  • Elixir version
  • Erlang version
  • OS
  • Ash version: 3.0.0-rc.33
  • any related extension versions
    • Ash PaperTrail: head
    • Ash Archival: 1.0.0-rc1

Additional context

Cannot create migration with AshPostgres

The following error occurs when trying to run mix ash_postgres.generate_migrations --name add_paper_trail_to_ticket.

** (ArgumentError) No such entity nil found.

    nil.spark_dsl_config()
    (spark 0.3.7) lib/spark/dsl/extension.ex:129: Spark.Dsl.Extension.dsl!/1
    (spark 0.3.7) lib/spark/dsl/extension.ex:147: Spark.Dsl.Extension.get_entities/2
    (ash 2.5.8) lib/ash/resource/info.ex:564: Ash.Resource.Info.attribute/2
    (ash_postgres 1.3.3) lib/migration_generator/migration_generator.ex:2135: anonymous fn/4 in AshPostgres.MigrationGenerator.find_reference/3
    (elixir 1.14.3) lib/enum.ex:4239: Enum.find_value_list/3
    (ash_postgres 1.3.3) lib/migration_generator/migration_generator.ex:2125: anonymous fn/3 in AshPostgres.MigrationGenerator.attributes/2
    (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2

You can see the setup here:
scflode/ash_playground#3

Error with missing `changed?` in context with `bulk_update`

Describe the bug

Ash.bulk_update!(records, :update, %{field: value},
  strategy: [:stream, :atomic, :atomic_batches],
  return_errors?: true
)

** (KeyError) key :changed? not found in: %{private: %{authorize?: true}, bulk_update: %{index: 0}}

crashes on
https://github.com/nallwhy/ash_paper_trail/blob/cc5f2c4385f9120ef570b552da505dfd7df941fa/lib/resource/changes/create_new_version.ex#L21

To Reproduce

nallwhy@fbebbeb

Expected behavior

no error

** Runtime

  • Elixir version
  • Erlang version
  • OS
  • Ash version: 3.0.0-rc.46
  • any related extension versions
    • Ash PaperTrail: head

Additional context

feat: support atomic bulk actions

Is your feature request related to a problem? Please describe.

I have a number of bulk actions that require auditing and atomic actions w/ rollback. For example, a packing list form which updates the ownership of a number of scanned items.

The trouble is that AshPaperTrail currently interferes with atomicity. :full_diff tracking mode may not be possible currently, but :changes_only should be possible to support atomically.

Describe the solution you'd like

The change for create_new_version should be refactored for support of bulk/atomic operations where possible. Currently, this would probably exclude :full_diff tracking mode, supporting only :snapshot and :changes_only.

Describe alternatives you've considered

  • Mixins aren't capable of adding this as an escape hatch.
  • Currently using a custom changeset to store changes in a []json column, which is pretty hacky.

Error with GraphQL models

I am having some issues with using ash_papertrail and on a model that uses GraphQL. I copied the example from the README, and this is the issue I am seeing

The following code gives me this error:

== Compilation error in file lib/myapp/myapi/resources/sample.ex ==
** (Spark.Error.DslError) [MyApp.Sample]
Multiple values for key :action
deps/ash_paper_trail/lib/resource/transformers/create_version_resource.ex:157: anonymous fn/4 in :elixir_compiler_10.MODULE/1
(elixir 1.15.4) lib/keyword.ex:1048: Keyword.do_merge/6
deps/ash_paper_trail/lib/resource/transformers/create_version_resource.ex:157: (module)
(spark 1.1.22) .../resources/sample.ex:20: Spark.Dsl.before_compile/1

If I remove the mixin, I get this error:

** (Absinthe.Schema.Error) Compilation failed:

Locations

/Users/danieljacobs/git/api/deps/ash_graphql/lib/resource/resource.ex:2326

In field Paper_trail_versions, :_filter_input is not defined in your schema.

Types must exist if referenced.

`
defmodule MyApp.Sample.PaperTrailMixin do

defmacro using(_) do
quote do
graphql do
type :sample_versions

    queries do
      list :list_versions, action: :read
    end
  end



end

end
end

defmodule MyApp.Sample do
use Scribble.Resource,
api: MyApp,
extensions: [AshGraphql.Resource, AshPaperTrail.Resource],
authorizers: [Ash.Policy.Authorizer]

attributes do
  uuid_primary_key :id
  attribute :name, :uuid, allow_nil?: false
  create_timestamp :inserted_at
  update_timestamp :updated_at
end

graphql do
  type :sample
end

paper_trail do
  mixin MyApp.Sample.PaperTrailMixin

  version_extensions extensions: [AshGraphql.Resource]

end

actions do
defaults [:read]
end

end
`

Does this look familiar?

Remove mixin support, allow extension on the Version instead

Instead of using mixins to customize the Version add something like this:

defmodule MyApp.Post.Version do # this is the version
  use Ash.Resource,
    data_layer: Ash.DataLayer.Ets,
    extensions: [AshPaperTrail.Version]

  ets do
    private? true
  end

  paper_trail do
    source MyApp.Post # add this
    attributes_as_attributes [:subject, :body, :tenant]
    change_tracking_mode :changes_only
    store_action_name? true
  end
end

This allows you to have add graphql, policies, relationships, etc and data layers that differ from the source.

Spark requirement version looks out of date?

Hi,

I was trying to get this package working, and it looks like maybe it's locked to an ancient version of spark? I ended up forking the project, and removing the dependency ( because, in my particular case, I have ash installed, which already has spark as a dependency ).

Not sure what the right path forward is - or if you are even still supporting this code - but wanted to make you aware. Thanks for the nice software!

feat: allow adding metadata to versions

Is your feature request related to a problem? Please describe.

I have a requirement to add various metadata to each version, e.g. reason_for_change for auditing compliance.

Describe the solution you'd like

Ideally, the DSL of AshPaperTrail would allow specifying metadata arguments to accept from the action to merge into the version.

Describe alternatives you've considered

  • Mixins don't seem capable of handling this as an escape hatch.
  • Storing the metadata directly on the primary resource is a leaky abstraction.

Express the feature either with a change to resource syntax, or with a change to the resource interface

Simple example:

paper_trail do
  metadata [:reason_for_change] # <-- will pull the value from that argument of action
end

It may be important to support more advanced uses, like pulling a nested field from the context and naming the key:

paper_trail do
  metadata [client_ip: ^context([:client, :remote_ip])]
end

Additional context

For implementation, perhaps we could use a special context to store the metadata:

paper_trail: %{reason_for_change: "fix typo"}

which could then be encoded on each version.

Introduce `mix check` through CI Github action

mix check is used on this project locally.
We can use a mix check within a github action to ensure minimum baseline for each PR is reached.
I think we should do this.

Currently the codebase isn't compliant with mix check, see the output from my local machine below:

โฏ mix deps.get
Resolving Hex dependencies...
Resolution completed in 0.193s
Unchanged:
  ash 2.14.12
.......
* Getting typable (Hex package)
โฏ mix check
==> earmark_parser
........
Compiling lib/ash/resource/dsl.ex (it's taking more than 10s)
warning: * IMPORTANT *

The configuration `use_all_identities_in_manage_relationship` was not set.
It is defaulting to `true` for backwards compatibility.

This configuration must now be manually set, and it should be set to `false`.
If you have just started a new project, or haven't used `manage_relationship` yet, just set the following config:

config :ash, :use_all_identities_in_manage_relationship?, false

If you are currently using `manage_relationship`, please read https://github.com/ash-project/ash/issues/469 before proceeding

  lib/ash/actions/managed_relationships.ex:16: (module)
  (elixir 1.14.1) src/elixir_compiler.erl:65: :elixir_compiler.dispatch/4
  (elixir 1.14.1) src/elixir_compiler.erl:50: :elixir_compiler.compile/3
  (elixir 1.14.1) src/elixir_module.erl:379: :elixir_module.eval_form/6
  (elixir 1.14.1) src/elixir_module.erl:105: :elixir_module.compile/5
  (elixir 1.14.1) src/elixir_lexical.erl:15: :elixir_lexical.run/3

Generated ash app
==> ash_paper_trail
=> running compiler

Compiling 14 files (.ex)
Generated ash_paper_trail app

=> running formatter

** (Mix) mix format failed due to --check-formatted.
The following files are not formatted:

  * test/ash_paper_trail_test.exs
  * lib/resource/transformers/create_version_resource.ex
  * lib/resource/changes/create_new_version.ex


=> running credo

Checking 27 source files ...

  Software Design                                                               
โ”ƒ 
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:62:22 #(AshPaperTrail.Resource.Info.version_resource)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:54:5 #(AshPaperTrail.Resource.Info.version_extensions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:49:5 #(AshPaperTrail.Resource.Info.store_action_name?)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:44:5 #(AshPaperTrail.Resource.Info.reference_source?)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:37:10 #(AshPaperTrail.Resource.Info.on_actions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:35:5 #(AshPaperTrail.Resource.Info.on_actions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:30:5 #(AshPaperTrail.Resource.Info.mixin)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:25:5 #(AshPaperTrail.Resource.Info.ignore_attributes)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:20:5 #(AshPaperTrail.Resource.Info.change_tracking_mode)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:11:5 #(AshPaperTrail.Resource.Info.belongs_to_actor)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:6:5 #(AshPaperTrail.Resource.Info.attributes_as_attributes)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/transformers/validate_belongs_to_actor.ex:6:22 #(AshPaperTrail.Resource.Transformers.ValidateBelongsToActor.transform)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/transformers/relate_version_resource.ex:11:27 #(AshPaperTrail.Resource.Transformers.RelateVersionResource.transform)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/api/transformers/allow_resource_versions.ex:13:26 #(AshPaperTrail.Api.Transformers.AllowResourceVersions.transform)

  Code Readability                                                              
โ”ƒ 
โ”ƒ [R] โ†’ `with` contains only one <- clause and an `else` branch, consider using 
โ”ƒ       `case` instead
โ”ƒ       lib/resource/transformers/relate_version_resource.ex:8 #(AshPaperTrail.Resource.Transformers.RelateVersionResource.transform)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/tenant.ex:1:11 #(AshPaperTrail.Test.Tenant)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/tag.ex:1:11 #(AshPaperTrail.Test.Posts.Tag)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/post.ex:1:11 #(AshPaperTrail.Test.Posts.Post)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/author.ex:1:11 #(AshPaperTrail.Test.Posts.Author)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/api.ex:1:11 #(AshPaperTrail.Test.Posts.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/registry.ex:1:11 #(AshPaperTrail.Test.Articles.Registry)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/article.ex:1:11 #(AshPaperTrail.Test.Articles.Article)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/api.ex:1:11 #(AshPaperTrail.Test.Articles.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/user.ex:1:11 #(AshPaperTrail.Test.Accounts.User)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/news_feed.ex:1:11 #(AshPaperTrail.Test.Accounts.NewsFeed)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/api.ex:1:11 #(AshPaperTrail.Test.Accounts.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       lib/registry/registry.ex:1:11 #(AshPaperTrail.Registry)
โ”ƒ [R] โ†˜ The alias `AshPaperTrail.Test.Posts` is not alphabetically ordered among 
โ”ƒ       its group.
โ”ƒ       test/ash_paper_trail_test.exs:4:29 #(AshPaperTrailTest)

  Refactoring opportunities                                                     
โ”ƒ 
โ”ƒ [F] โ†’ Function is too complex (cyclomatic complexity is 20, max is 9).
โ”ƒ       lib/resource/transformers/create_version_resource.ex:7:7 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)
โ”ƒ [F] โ†˜ Avoid `apply/2` and `apply/3` when the number of arguments is known
โ”ƒ       lib/resource/transformers/create_version_resource.ex:32 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)
โ”ƒ [F] โ†˜ Avoid `apply/2` and `apply/3` when the number of arguments is known
โ”ƒ       lib/resource/transformers/create_version_resource.ex:32 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.5 seconds (0.1s to load, 0.3s running 64 checks on 27 files)
62 mods/funs, found 3 refactoring opportunities, 14 code readability issues, 14 software design suggestions.

Use `mix credo explain` to explain issues, `mix credo --help` for options.

=> running sobelow

Checking Sobelow version...


14:12:22.624 [warning] Description: 'Authenticity is not established by certificate path validation'
     Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'

A new version of Sobelow is available:
mix archive.install hex sobelow

WARNING: Sobelow cannot find the router. If this is a Phoenix application
please use the `--router` flag to specify the router's location.

##############################################
#                                            #
#          Running Sobelow - v0.11.1         #
#  Created by Griffin Byatt - @griffinbyatt  #
#     NCC Group - https://nccgroup.trust     #
#                                            #
##############################################

RCE.CodeModule: Code Execution in `Code.eval_quoted` - Low Confidence
File: lib/resource/transformers/create_version_resource.ex
Line: 125
Function: transform:7
Variable: quote

-----------------------------------------------

RCE.CodeModule: Code Execution in `Code.eval_quoted` - Low Confidence
File: lib/resource/transformers/create_version_resource.ex
Line: 98
Function: transform:7
Variable: quote

-----------------------------------------------

... SCAN COMPLETE ...

=> running ex_doc

Generating docs...
View "html" docs at "doc/index.html"
View "epub" docs at "doc/ash_paper_trail.epub"

=> running ex_unit

==> sourceror
....
warning: * IMPORTANT *

The configuration `use_all_identities_in_manage_relationship` was not set.
It is defaulting to `true` for backwards compatibility.

This configuration must now be manually set, and it should be set to `false`.
If you have just started a new project, or haven't used `manage_relationship` yet, just set the following config:

config :ash, :use_all_identities_in_manage_relationship?, false

If you are currently using `manage_relationship`, please read https://github.com/ash-project/ash/issues/469 before proceeding

  lib/ash/actions/managed_relationships.ex:16: (module)
  (elixir 1.14.1) src/elixir_compiler.erl:65: :elixir_compiler.dispatch/4
  (elixir 1.14.1) src/elixir_compiler.erl:50: :elixir_compiler.compile/3
  (elixir 1.14.1) src/elixir_module.erl:379: :elixir_module.eval_form/6
  (elixir 1.14.1) src/elixir_module.erl:105: :elixir_module.compile/5
  (elixir 1.14.1) src/elixir_lexical.erl:15: :elixir_lexical.run/3

Generated ash app
==> ash_paper_trail
Compiling 25 files (.ex)
Generated ash_paper_trail app
...............
Finished in 0.2 seconds (0.00s async, 0.2s sync)
15 tests, 0 failures

Randomized with seed 473024

=> running dialyzer

Finding suitable PLTs
Checking PLT...
[:ash, :asn1, :certifi, :comparable, :compiler, :crypto, :decimal, :ecto, :eex, :elixir, :ets, :ex_check, :excoveralls, :git_cli, :git_ops, :hackney, :idna, :jason, :kernel, :logger, :metrics, :mimerl, :mnesia, :nimble_options, :nimble_parsec, :parse_trans, :picosat_elixir, :public_key, :sourceror, :spark, :ssl, :ssl_verify_fun, :stdlib, :stream_data, :syntax_tools, :telemetry, :tools, :typable, :unicode_util_compat]
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Looking up modules in dialyxir_erlang-25.1.2.plt
Finding applications for dialyxir_erlang-25.1.2.plt
Finding modules for dialyxir_erlang-25.1.2.plt
Creating dialyxir_erlang-25.1.2.plt
Looking up modules in dialyxir_erlang-25.1.2.plt
Removing 3 modules from dialyxir_erlang-25.1.2.plt
Checking 18 modules in dialyxir_erlang-25.1.2.plt
Adding 185 modules to dialyxir_erlang-25.1.2.plt
done in 0m33.08s
Finding applications for dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Finding modules for dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Copying dialyxir_erlang-25.1.2.plt to dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Checking 203 modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Adding 253 modules to dialyxir_erlang-25.1.2_elixir-1.14.1.plt
done in 0m37.85s
Finding applications for dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Finding modules for dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Copying dialyxir_erlang-25.1.2_elixir-1.14.1.plt to dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Checking 456 modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Adding 1389 modules to dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
done in 3m3.58s
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
[
....
]
Total errors: 2, Skipped: 0, Unnecessary Skips: 0
done in 0m2.82s
lib/registry/transformers/add_resource_versions.ex:16:callback_arg_type_mismatch
The inferred type for the 1st argument is not a
supertype of the expected type for the transform/1 callback
in the Spark.Dsl.Transformer behaviour.

Success type:
atom()

Behaviour callback type:
map()

________________________________________________________________________________
lib/resource/transformers/create_version_resource.ex:39:call
The function call will not succeed.

Ash.DataLayer.Ets.Info.private?(_dsl_state :: map())

breaks the contract
(Ash.Resource.t()) :: boolean()

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

=> reprinting errors from formatter

** (Mix) mix format failed due to --check-formatted.
The following files are not formatted:

  * test/ash_paper_trail_test.exs
  * lib/resource/transformers/create_version_resource.ex
  * lib/resource/changes/create_new_version.ex


=> reprinting errors from credo

Checking 27 source files ...

  Software Design                                                               
โ”ƒ 
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:62:22 #(AshPaperTrail.Resource.Info.version_resource)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:54:5 #(AshPaperTrail.Resource.Info.version_extensions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:49:5 #(AshPaperTrail.Resource.Info.store_action_name?)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:44:5 #(AshPaperTrail.Resource.Info.reference_source?)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:37:10 #(AshPaperTrail.Resource.Info.on_actions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:35:5 #(AshPaperTrail.Resource.Info.on_actions)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:30:5 #(AshPaperTrail.Resource.Info.mixin)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:25:5 #(AshPaperTrail.Resource.Info.ignore_attributes)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:20:5 #(AshPaperTrail.Resource.Info.change_tracking_mode)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:11:5 #(AshPaperTrail.Resource.Info.belongs_to_actor)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/info.ex:6:5 #(AshPaperTrail.Resource.Info.attributes_as_attributes)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/transformers/validate_belongs_to_actor.ex:6:22 #(AshPaperTrail.Resource.Transformers.ValidateBelongsToActor.transform)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/resource/transformers/relate_version_resource.ex:11:27 #(AshPaperTrail.Resource.Transformers.RelateVersionResource.transform)
โ”ƒ [D] โ†˜ Nested modules could be aliased at the top of the invoking module.
โ”ƒ       lib/api/transformers/allow_resource_versions.ex:13:26 #(AshPaperTrail.Api.Transformers.AllowResourceVersions.transform)

  Code Readability                                                              
โ”ƒ 
โ”ƒ [R] โ†’ `with` contains only one <- clause and an `else` branch, consider using 
โ”ƒ       `case` instead
โ”ƒ       lib/resource/transformers/relate_version_resource.ex:8 #(AshPaperTrail.Resource.Transformers.RelateVersionResource.transform)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/tenant.ex:1:11 #(AshPaperTrail.Test.Tenant)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/tag.ex:1:11 #(AshPaperTrail.Test.Posts.Tag)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/post.ex:1:11 #(AshPaperTrail.Test.Posts.Post)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/author.ex:1:11 #(AshPaperTrail.Test.Posts.Author)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/posts/api.ex:1:11 #(AshPaperTrail.Test.Posts.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/registry.ex:1:11 #(AshPaperTrail.Test.Articles.Registry)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/article.ex:1:11 #(AshPaperTrail.Test.Articles.Article)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/articles/api.ex:1:11 #(AshPaperTrail.Test.Articles.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/user.ex:1:11 #(AshPaperTrail.Test.Accounts.User)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/news_feed.ex:1:11 #(AshPaperTrail.Test.Accounts.NewsFeed)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       test/support/accounts/api.ex:1:11 #(AshPaperTrail.Test.Accounts.Api)
โ”ƒ [R] โ†’ Modules should have a @moduledoc tag.
โ”ƒ       lib/registry/registry.ex:1:11 #(AshPaperTrail.Registry)
โ”ƒ [R] โ†˜ The alias `AshPaperTrail.Test.Posts` is not alphabetically ordered among 
โ”ƒ       its group.
โ”ƒ       test/ash_paper_trail_test.exs:4:29 #(AshPaperTrailTest)

  Refactoring opportunities                                                     
โ”ƒ 
โ”ƒ [F] โ†’ Function is too complex (cyclomatic complexity is 20, max is 9).
โ”ƒ       lib/resource/transformers/create_version_resource.ex:7:7 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)
โ”ƒ [F] โ†˜ Avoid `apply/2` and `apply/3` when the number of arguments is known
โ”ƒ       lib/resource/transformers/create_version_resource.ex:32 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)
โ”ƒ [F] โ†˜ Avoid `apply/2` and `apply/3` when the number of arguments is known
โ”ƒ       lib/resource/transformers/create_version_resource.ex:32 #(AshPaperTrail.Resource.Transformers.CreateVersionResource.transform)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.5 seconds (0.1s to load, 0.3s running 64 checks on 27 files)
62 mods/funs, found 3 refactoring opportunities, 14 code readability issues, 14 software design suggestions.

Use `mix credo explain` to explain issues, `mix credo --help` for options.

=> reprinting errors from sobelow

Checking Sobelow version...


14:12:22.624 [warning] Description: 'Authenticity is not established by certificate path validation'
     Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'

A new version of Sobelow is available:
mix archive.install hex sobelow

WARNING: Sobelow cannot find the router. If this is a Phoenix application
please use the `--router` flag to specify the router's location.

##############################################
#                                            #
#          Running Sobelow - v0.11.1         #
#  Created by Griffin Byatt - @griffinbyatt  #
#     NCC Group - https://nccgroup.trust     #
#                                            #
##############################################

RCE.CodeModule: Code Execution in `Code.eval_quoted` - Low Confidence
File: lib/resource/transformers/create_version_resource.ex
Line: 125
Function: transform:7
Variable: quote

-----------------------------------------------

RCE.CodeModule: Code Execution in `Code.eval_quoted` - Low Confidence
File: lib/resource/transformers/create_version_resource.ex
Line: 98
Function: transform:7
Variable: quote

-----------------------------------------------

... SCAN COMPLETE ...

=> reprinting errors from dialyzer

Finding suitable PLTs
Checking PLT...
[:ash, :asn1, :certifi, :comparable, :compiler, :crypto, :decimal, :ecto, :eex, :elixir, :ets, :ex_check, :excoveralls, :git_cli, :git_ops, :hackney, :idna, :jason, :kernel, :logger, :metrics, :mimerl, :mnesia, :nimble_options, :nimble_parsec, :parse_trans, :picosat_elixir, :public_key, :sourceror, :spark, :ssl, :ssl_verify_fun, :stdlib, :stream_data, :syntax_tools, :telemetry, :tools, :typable, :unicode_util_compat]
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Looking up modules in dialyxir_erlang-25.1.2.plt
Finding applications for dialyxir_erlang-25.1.2.plt
Finding modules for dialyxir_erlang-25.1.2.plt
Creating dialyxir_erlang-25.1.2.plt
Looking up modules in dialyxir_erlang-25.1.2.plt
Removing 3 modules from dialyxir_erlang-25.1.2.plt
Checking 18 modules in dialyxir_erlang-25.1.2.plt
Adding 185 modules to dialyxir_erlang-25.1.2.plt
done in 0m33.08s
Finding applications for dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Finding modules for dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Copying dialyxir_erlang-25.1.2.plt to dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Checking 203 modules in dialyxir_erlang-25.1.2_elixir-1.14.1.plt
Adding 253 modules to dialyxir_erlang-25.1.2_elixir-1.14.1.plt
done in 0m37.85s
Finding applications for dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Finding modules for dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Copying dialyxir_erlang-25.1.2_elixir-1.14.1.plt to dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Looking up modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Checking 456 modules in dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
Adding 1389 modules to dialyxir_erlang-25.1.2_elixir-1.14.1_deps-dev.plt
done in 3m3.58s
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
[
  ....
]
Total errors: 2, Skipped: 0, Unnecessary Skips: 0
done in 0m2.82s
lib/registry/transformers/add_resource_versions.ex:16:callback_arg_type_mismatch
The inferred type for the 1st argument is not a
supertype of the expected type for the transform/1 callback
in the Spark.Dsl.Transformer behaviour.

Success type:
atom()

Behaviour callback type:
map()

________________________________________________________________________________
lib/resource/transformers/create_version_resource.ex:39:call
The function call will not succeed.

Ash.DataLayer.Ets.Info.private?(_dsl_state :: map())

breaks the contract
(Ash.Resource.t()) :: boolean()

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

=> finished in 4:49

 โœ“ compiler success in 0:04
 โœ“ ex_doc success in 0:08
 โœ“ ex_unit success in 1:41
 โœ• credo error code 14 in 0:07
 โœ• dialyzer error code 2 in 4:45
 โœ• formatter error code 1 in 0:06
 โœ• sobelow error code 1 in 0:08

I truncated some stuff but you get the idea

Version policies

A couple issues:

  • Version resources are created with an authorize?: false but does this fail if the api has authorize :always
  • Are policies authorized currently or are they globably readable (footgun)
  • Policies can be added via a mixin. Should update the readme.
  • Can we declare policies in the paper_trail section. Might be a lift not worth doing if we can get full support via mixin.

attributes_as_attributes should also be ignorable

It is currently not possible to have an attribute on the version that is ignored in the change tracking. This creates an issue when you have a attribute that is used for multitenancy and you need that attribute on the resource, but it also will not change and should be ignored from change tracking

Error on migration

Thanks for your help with everything so far.

I downloaded the latest patch and now I am getting this error. I have version 1.1.26 of spark according to my mix.lock file.

[nix-shell:~/git/api]$ mix ash_postgres.generate_migrations --name add_versions

== Compilation error in file lib/myapp/myapi/resources/section.ex ==
** (NimbleOptions.ValidationError) unknown options [:source], valid options are: [:manual, :no_attributes?, :name, :destination, :description, :destination_attribute, :validate_destination_attribute?, :source_attribute, :relationship_context, :private?, :not_found_message, :writable?, :read_action, :api, :filter, :filterable?, :sort, :could_be_related_at_creation?, :violation_message]
(spark 1.1.26) lib/spark/dsl/extension.ex:737: Spark.Dsl.Extension.raise_transformer_error/2
(elixir 1.15.4) lib/enum.ex:4830: Enumerable.List.reduce/3
(elixir 1.15.4) lib/enum.ex:2564: Enum.reduce_while/3
/Users/danieljacobs/git/api/lib/scribble/scribe/resources/section.ex:20: (file)
(stdlib 4.3.1.2) erl_eval.erl:748: :erl_eval.do_apply/7
(stdlib 4.3.1.2) erl_eval.erl:961: :erl_eval.expr_list/7
(stdlib 4.3.1.2) erl_eval.erl:454: :erl_eval.expr/6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.