Commit graph

897 commits

Author SHA1 Message Date
Zach Daniel
8a368c0fcd fix: fix behavior of synthesized joins across data layers
test: fix our testing set up so its actually testing join synthesizer

closes #1354
2024-07-30 22:11:32 -04:00
Zach Daniel
cb7b712460 improvement: implement change/3 automatically if batch callbacks are defined
fix: properly handle mixed atomic & non-atomic validations/changes
2024-07-29 19:54:12 -04:00
Barnabas Jovanovics
1ce0480a85
test: tests for atomic only validation (#1331) 2024-07-29 15:29:39 -04:00
Zach Daniel
b3ac13e760 chore: release version v3.3.0 2024-07-27 17:05:46 -04:00
Zach Daniel
dc4a63c86c fix: ensure that statuses are set correctly on bulk actions
fix: properly transfer process context(tracers) for bulk actions

closes #1332
2024-07-26 11:38:41 -04:00
Jonatan Männchen
3de985ccc5
feat: Add Ash.Type.File (#1337) 2024-07-26 07:57:23 -04:00
Jonatan Männchen
bda0c0e0da
chore: credo fix (#1347) 2024-07-25 18:08:32 -04:00
Riccardo Binetti
df7adce976
fix: apply constraints to NewType even when casting an array (#1341)
The previous implementation was behaving differently when dealing with single
values and arrays.
Close #1342
2024-07-25 10:17:18 -04:00
Zach Daniel
99966d0e57 fix: fix enum typespec generation for strings/mixed types 2024-07-25 09:30:04 -04:00
Zach Daniel
b46e172627 fix: properly generate types for string & mixed enums 2024-07-25 07:34:53 -04:00
Barnabas Jovanovics
8a1c47c131
test: add test for string enum (#1344) 2024-07-25 07:24:50 -04:00
Riccardo Binetti
d199f701ac
fix: pass reuse_values? true when loading in Ash.Query.apply_to/2 (#1346)
The function is meant to be used to act on data that is in-memory, so it makes
sense to not read data again. Moreover this caused an infinite loop if using
this at the end of a manual read.
Add a regression test for the manual read case.
2024-07-25 07:21:08 -04:00
Jonatan Männchen
8d3b0b7246
improvement: Expose type t() on Ash.Type.Enum implementations (#1338) 2024-07-24 07:06:11 -04:00
Zach Daniel
be542cf880 fix: only call batch_change if it is defined, never change in bulk create 2024-07-22 14:32:27 -04:00
Zach Daniel
bad62c1e8a improvement: add authorize_with fallback option to bulk actions
improvement: store non-expr atomic changes in attributes for simplicity
fix: make `relating_to_actor` built-in-check aware of atomics

closes #1327
2024-07-22 10:03:14 -04:00
Zach Daniel
34d6f229c5 improvement: allow policy conditions to be applied inside their block
```elixir
policy do
  condition [...]
  authorize_if ...
end
```
2024-07-22 07:10:09 -04:00
Zach Daniel
3c2f51224a chore: get build passing 2024-07-19 12:40:09 -04:00
Jinkyou Son
063e654405
fix: cast_input/2 of Ash.Type.NewType returning :ok (#1324) 2024-07-18 23:07:14 -04:00
Zach Daniel
6632f599bc chore: keep only correct changes from earlier reverts 2024-07-17 15:08:19 -04:00
Zach Daniel
05cdaa04c5 Revert "fix: honor atomic validations in destroy actions using filter"
This reverts commit a6a9961c0d.
2024-07-17 15:06:39 -04:00
Zach Daniel
a6a9961c0d fix: honor atomic validations in destroy actions using filter
test: add tests for atomic validations in destroy actions
2024-07-17 14:32:57 -04:00
Hannes Wüthrich
dad0bfd1c4
fix: handle casting nil vectors (#1316) 2024-07-17 09:52:12 -04:00
Tore Pettersen
37755a870b
feat: Allow field policies to hide private fields (#1289)
* Allow field policies to hide private fields

* Create option for how to handle private fields

* Improve docs
2024-07-15 08:16:52 -04:00
Zach Daniel
476dfede63 improvement: add cast_atomic_constraints callback and use it in core typest 2024-07-12 23:12:59 -04:00
Riccardo Binetti
3e39595730
test: add failing test for bulk update with numeric constraints (#1310) 2024-07-12 08:15:25 -04:00
Torkild Gundersen Kjevik
ad6954aca8
improvement: add strict? option to Ash.Query.load (#1302)
---------

Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
2024-07-11 09:34:30 -04:00
Zach Daniel
7cb007d32d test: add tests for integers 2024-07-10 13:13:55 -04:00
Andreas Donig
28c1aa4f30
improvement: don't refer to private attributes when parsing filter inputs that refer to relationships (#1280)
---------

Co-authored-by: Andreas Donig <git@innwiese.de>
2024-07-10 12:14:27 -04:00
Zach Daniel
426ee6671d fix: ensure that manual action configurations are honored for bulk actions 2024-07-10 11:24:48 -04:00
Zach Daniel
e1dffc0c0c fix: properly enforce tenancy on all mutative actions 2024-07-06 13:41:58 -04:00
Zach Daniel
25faa93a83 chore: thread calc & relationship paths through calculation dependency loader 2024-07-04 10:39:22 -04:00
Riccardo Binetti
97cab3d767
chore: failing test for nested calculation loading a relationship (#1283) 2024-07-04 10:10:16 -04:00
Zach Daniel
5a4fdcc362 fix: don't reuse calculations/aggregates if authorize? is true 2024-07-04 09:46:38 -04:00
Zach Daniel
920f52ff27 chore: fix build 2024-07-04 08:55:39 -04:00
Zach Daniel
fa94e76855 Revert "fix: don't reuse requested relationship loads for calculations"
This reverts commit 49da3638f1.
2024-07-04 07:09:56 -04:00
Zach Daniel
49da3638f1 fix: don't reuse requested relationship loads for calculations
this is less efficient, and there are still some cases where
we could combine queries, but we need to first solve the behavioral
issues where relationships loaded for calculations could sometimes be loaded
in an "authorized" state when they should not be. We can improve the
speed/efficiency later, correctness is more important.
2024-07-03 18:32:20 -04:00
pinetops
22ac5bbcc1
test: added test case showing calculations erroneously respect policies (#1278) 2024-07-03 12:43:15 -04:00
Zach Daniel
a06b161591 fix: properly set context on streamed batch changesets 2024-07-03 11:34:05 -04:00
Robert Timis
a06bf364ac
test: replicate forbidden error on update (#1276) 2024-07-03 10:54:12 -04:00
Hannes Wüthrich
0e5587552c
fix: invert logic for lazy-loading calculations/aggregates (#1275) 2024-07-03 07:06:11 -04:00
Zach Daniel
d997902a6c chore: raise explicit error on missing last_relationship/2 2024-07-02 15:19:33 -04:00
Zach Daniel
a3b026404e test: add passing test for bulk update code interface policies
fix: properly match on async task exceptions
2024-07-02 14:33:13 -04:00
Robert Timis
5e29160316
test: expr context in policy test (#1274) 2024-07-02 12:48:09 -04:00
Zach Daniel
f13895b0f2 fix: override authorize?: nil context
fix: ensure forbidden errors behave the same on `id` provided to code interfaces
2024-07-02 11:05:13 -04:00
Zach Daniel
b1d9c81725 chore: more list.wrapping of notifications 2024-07-02 10:41:15 -04:00
Zach Daniel
d53ad508cd test: update non-simple-equality manual relationship tests 2024-07-01 17:32:32 -04:00
kernel-io
3265b36589
fix: compare keys in manual relationships when using 'complex' types (#1270)
Signed-off-by: kernel-io <kernel-io@users.noreply.github.com>
2024-07-01 17:21:01 -04:00
Zach Daniel
3e1b15eae4 improvement: remove non-simple equality check for uuidv7 type 2024-07-01 09:38:23 -04:00
Andreas Donig
d436278616
fix: filter parsing cases (#1261)
* Fix the issue with the order of cases

* Make it pass all tests

* Add a test case for the new feature

---------

Co-authored-by: Andreas Donig <git@innwiese.de>
2024-06-30 07:26:25 -04:00
Zach Daniel
66ebb1422e tests: more notification transaction tests 2024-06-28 13:59:03 -04:00
Zach Daniel
4c0faabbec Revert "fix: gather up process notifications from atomic transaction"
This reverts commit 62c832a6b3.
2024-06-28 12:53:37 -04:00
Zach Daniel
62c832a6b3 fix: gather up process notifications from atomic transaction 2024-06-28 11:40:44 -04:00
Zach Daniel
2d29dab90b fix: set tenant context when calling data layers
fix: set `from_many?` if a `has_one` has a `sort` applied

(because there is no other reason to apply a `sort`)
2024-06-28 11:13:34 -04:00
Zach Daniel
6898bde0a4 fix: proper return value from synthesized joins
fix: properly support multitenancy in joins in ets
2024-06-27 20:53:35 -04:00
Ryan
a117327c0c
test: assert that notifications are sent for bulk updates and destroys using the :stream strategy (#1266) 2024-06-25 12:39:18 -04:00
Zach Daniel
83434b0d1a improvement: bulk destroy for handling array changes in embeds
improvement: set `__union_tag__` constraint in array handlers for unions
fix: sleep to avoid uuidv7 specifity flaky test
test: remove unused variable in tests
2024-06-24 09:48:08 -04:00
Zach Daniel
ec4ff55529 fix: ensure that we notify on code-interface id synthesized bulk operations 2024-06-24 08:38:45 -04:00
Alessio Montagnani
7f2e7d3ec1
improvement: bring uuid version 7 into the core (#1253) 2024-06-23 18:16:20 -04:00
Davide Briani
b256e1d8a3
test: Test loading paginated relationship when tenant is in primary key (#1252)
* Chore: test loading paginated relationship when tenant is in primary key

Ash is already able to load paginated relationships on multitenant
resources after a create or update action.
However this change specifically test the case of a many to many
relationship where the tenant is included in the primary key of the
joined resources.

Signed-off-by: Davide Briani <davide@briani.dev>

* fix: apply pagination at runtime for non lateral join queries
fix: consider multitenancy when checking if through-join is unique

---------

Signed-off-by: Davide Briani <davide@briani.dev>
Co-authored-by: Zach Daniel <zach@zachdaniel.dev>
2024-06-21 15:00:50 -04:00
Davide Briani
71d871b54a
Test loading relationships on multitenant resources after create or update (#1249)
* Chore: add tests on loading relationship on multitenant resource

Add tests to verify that relationships can be loaded on multitenant
resources after a create or update action.

Signed-off-by: Davide Briani <davide@briani.dev>

* fix: set tenant in ets data layer when generating aggregates

---------

Signed-off-by: Davide Briani <davide@briani.dev>
Co-authored-by: Zach Daniel <zach@zachdaniel.dev>
2024-06-20 16:46:29 -04:00
Zach Daniel
fa5d4a1a96 fix: don't start async limiter tasks if async is disabled
fix: properly set default timeout to `:infinity`

this avoids unnecessary processes starting when in the vast majority of cases some external thing is imposing a timeout.

fix: pass down `identity` when doing upserts, for new feature support
2024-06-17 10:56:48 -04:00
Zach Daniel
1fe799c7bb chore: fix match eror in changeset hook runner 2024-06-15 11:31:39 -04:00
Zach Daniel
9882037780 fix: set default argument values on generic actions
fixes #1220
2024-06-13 10:25:25 -04:00
Jechol Lee
c5d96e1a0a
chore: Fix warning: using map.field notation (#1238) 2024-06-13 08:02:35 -04:00
Zach Daniel
00e294e050 fix: support ^arg/1 and similar constructions in filter policies on generic actions
closes #1221
2024-06-11 13:31:13 -04:00
Davide Briani
cd06f919c0
fix: load relationships on bulk operations (#1234)
This change validates that the `load` statement of bulk operations is
respected when specified, and correctly loads relationships.

Loading relationships with pagination on results for bulk destroys is
still not supported. Indeed, relationships are currently queried using a
lateral join but after the resource deletion has happened, so it looks
like nothing is related.

Signed-off-by: Davide Briani <davide@briani.dev>
2024-06-10 20:14:37 -04:00
Zach Daniel
d5d0b04bb6 improvement: validate require_attributes and allow_nil_input at compile time 2024-06-10 17:43:15 -04:00
Davide Briani
ae9671158f
fix: correctly load paginated relationships after create, update, delete (#1229)
Ensure that relationships can be correctly loaded, even with pagination,
on the resources resulting from create, update and delete actions.

Signed-off-by: Davide Briani <davide.briani@secomind.com>
2024-06-10 10:46:49 -04:00
Andreas Donig
4153ba7ef3
fix: fix the compare/2 implementations (#1232)
Co-authored-by: Andreas Donig <git@innwiese.de>
2024-06-10 08:15:51 -04:00
Robert Timis
6b964b9384
improvement: add tenant option to Ash.Seed.seed! (#1230) 2024-06-10 07:47:43 -04:00
Robert Timis
9c32eab87e
fix: fix seed not working when :__keep_nil__ is generated using seed_input (#1228) 2024-06-07 08:14:39 -04:00
Robert Timis
4d35117649
fix: add resource to Ash.Seed.seed! in Ash.Generator.seed! (#1227) 2024-06-07 07:31:29 -04:00
Zach Daniel
459426135e test: add example factory pattern for tests 2024-06-06 10:30:35 -04:00
Zach Daniel
e4980d55ba fix: don't update tenant on update, instead enforce it
the attribute strategy allowed for overwriting the multitenant attribute
on update. In practice, this can't really happen using any standard pattern
because any record to be updated is read with the tenant context, but it still
represents a small risk (and `schema` based multitenancy would enforce it in this
way anyway, so this is more consistent).
2024-06-05 10:43:38 -04:00
Zach Daniel
8799191165 test: add tests showing before_transaction hooks setting derived values 2024-06-02 11:59:18 -04:00
Zach Daniel
fbcafa1bfa fix: when hydrating nested aggregates, use correct related resource/path pair
closes #1213
2024-05-30 00:12:12 -05:00
Zach Daniel
1c21e390be fix: retain ref_path when authorizing aggregates 2024-05-29 14:03:33 -04:00
Zach Daniel
e9897eb50f fix: ensure that belongs_to relationships are properly not reloaded with lazy?: true
closes #1208
2024-05-29 12:59:10 -04:00
Jechol Lee
5dbf8fc0ed
fix get_domain (#1209) 2024-05-29 07:31:18 -04:00
Zach Daniel
bfdb8f9bab chore: format 2024-05-28 14:32:30 -04:00
Alan Heywood
2ee311b061
test: demonstrate error with bulk update on manual action (#1204)
The following error is produced

1) test manual updates are supported (Ash.Test.Actions.BulkUpdateTest)
     test/actions/bulk/bulk_update_test.exs:358
     ** (CaseClauseError) no case clause matching: nil
     code: |> Ash.bulk_update!(:update_manual, %{},
     stacktrace:
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:2076: anonymous fn/11 in Ash.Actions.Update.Bulk.run_batch/10
       (elixir 1.16.2) lib/enum.ex:1264: anonymous fn/3 in Enum.flat_map/2
       (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
       (elixir 1.16.2) lib/enum.ex:2540: Enum.flat_map/2
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1966: Ash.Actions.Update.Bulk.run_batch/10
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1505: Ash.Actions.Update.Bulk.do_handle_batch/13
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1042: anonymous fn/12 in Ash.Actions.Update.Bulk.do_stream_batches/7
       (elixir 1.16.2) lib/stream.ex:613: anonymous fn/4 in Stream.map/2
       (elixir 1.16.2) lib/stream.ex:1816: anonymous fn/3 in Enumerable.Stream.reduce/3
       (elixir 1.16.2) lib/stream.ex:273: anonymous fn/4 in Stream.chunk_while_fun/2
       (elixir 1.16.2) lib/stream.ex:1159: anonymous fn/3 in Stream.with_index/2
       (elixir 1.16.2) lib/stream.ex:1079: Stream.do_transform_each/3
       (elixir 1.16.2) lib/stream.ex:1816: anonymous fn/3 in Enumerable.Stream.reduce/3
       (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3
       (elixir 1.16.2) lib/stream.ex:1027: Stream.do_transform_inner_list/7
       (elixir 1.16.2) lib/stream.ex:1828: Enumerable.Stream.do_each/4
       (elixir 1.16.2) lib/stream.ex:1052: Stream.do_transform_inner_enum/7
       (elixir 1.16.2) lib/stream.ex:1828: Enumerable.Stream.do_each/4
       (elixir 1.16.2) lib/stream.ex:943: Stream.do_transform/5
       (elixir 1.16.2) lib/enum.ex:4396: Enum.reverse/1
       (elixir 1.16.2) lib/enum.ex:3728: Enum.to_list/1
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1070: Ash.Actions.Update.Bulk.run_batches/3
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:386: Ash.Actions.Update.Bulk.run/6
       (ash 3.0.7) lib/ash.ex:2209: Ash.bulk_update!/4
       test/actions/bulk/bulk_update_test.exs:373: (test)
2024-05-27 10:32:39 -04:00
Zach Daniel
adda85297c fix: multiple filter-checks in policy conditions were not composing properly 2024-05-24 22:58:05 -04:00
Zach Daniel
3057c4d936 chore: make credo happy 2024-05-24 21:57:54 -04:00
Zach Daniel
c45ecbfa49 fix: properly honor trailing policies that are constantly false 2024-05-24 21:03:06 -04:00
Zach Daniel
3510cd48f4 chore: clean up changelog and format 2024-05-24 00:35:13 -04:00
Zach Daniel
dc94f3a743 improvement: support nils_distinct? on identities
improvement: support `where` option on `identities`
improvement: allow calculations in identity keys

closes #1001
closes #1182
2024-05-24 00:24:42 -04:00
Zach Daniel
808692bbd7 fix: improve non-atomic-upgrade policy handling
fix: ensure we have a primary key for certain kinds of calculations:
2024-05-23 18:34:15 -04:00
Zach Daniel
e63d80e645 fix: handle subquery-requiring calculations in calculate/2 2024-05-23 17:33:29 -04:00
Zach Daniel
feb187bdf6 improvement: add atomic_upgrade? flag to update/destroy actions
improvement: do not do atomic upgrade by default unless `require_atomic?` is `true`
improvement: allow configuring the read action used by atomic upgrades
2024-05-23 11:05:17 -04:00
Zach Daniel
67c6e5e22a fix: ensure that all notifications are sent for bulk destroy/update
closes #1186
2024-05-22 18:42:19 -04:00
danielatdpg
05379e15b2
fix: handle list of atomic conditions (#1194) (#1195) 2024-05-22 11:38:15 -04:00
ab3786ebf6
feat(Ash.Reactor): Add bulk_update step type. (#1185) 2024-05-22 15:26:51 +12:00
Riccardo Binetti
86676cd0fc
feat: allow retrieving the count of paginated relationships (#1183) 2024-05-21 08:48:11 -04:00
Jinkyou Son
aae679f50e
improvement: Implement show_sensitive? config (#1180)
* Refactor with Ash.Helpers.redact/1

* Implement show_sensitive? config

* Use Application.compile_env/3 instead of Application.get_env/3

* Update sensitive-data.md
2024-05-21 08:47:51 -04:00
807ed72e89
chore: run formatter. 2024-05-21 09:17:58 +12:00
1d5d247d7a feat(Ash.Reactor): Add bulk_create step type. 2024-05-21 09:14:02 +12:00
Zach Daniel
a162b52b7f fix: use Ash.Sort.parse_input/3 in Ash.Query.sort_input/2 2024-05-20 09:52:52 -04:00
Riccardo Binetti
9fc5ddfe2b
fix: make Ash.Resource.Validation.Changing work correctly in atomics (#1178)
- Use the correct option key to select the field
- Fail without hitting the data layer if the attribute is not changing
- Allow checking relationships like the non-atomic counterpart
2024-05-16 18:15:35 -05:00
Riccardo Binetti
16b7ea7693
fix: check the where condition before checking validation atomicity (#1177)
:not_atomic was returned for a non-atomic validation even if the where condition
evaluated to false
2024-05-16 15:49:08 -05:00
Zach Daniel
23d7479417 fix: handle nil notification results better
fix: don't emit after batch notifications if `notify?: false`
2024-05-16 11:19:24 -05:00