Commit graph

888 commits

Author SHA1 Message Date
Zach Daniel
d6a973cef0 improvement: better error messages on incorrect action types 2024-09-04 20:41:56 -04:00
Zach Daniel
d144be692e fix: properly await tasks from lazy loading multiple relationships 2024-09-04 10:32:34 -04:00
Zach Daniel
06cd509e1f chore: make the new policy behavior opt-in with config 2024-09-03 22:22:46 -04:00
Andreas Donig
de0f72b475
Fix: honor bulk upsert condition (#1432)
* Require Ash.Expr to make sure upsert_conflict/1 is available

* Make sure it correctly tests opts[:upsert_condition] for nilness

* Make sure the base changeset also adheres to the upsert condition

* Revert the changes so we can show the problem with a test case

* Add a test case that shows what the problem is

* Add the upsert_condition filter to the base changeset again

* Change the way the test checks because bulk_create/4 does not return unchanged records
2024-09-03 16:23:12 -04:00
Zach Daniel
1002d8178e improvement: make read policies more consistent, always preferring to filter over raise
docs: document access type
2024-09-02 14:11:09 -04:00
Zach Daniel
6f2a14715d improvement: show an explanation when no policies apply 2024-09-02 12:48:36 -04:00
Zach Daniel
c7eaabdb2e
fix: correctly handle return values of batch callbacks (#1424)
* improvement: factor out static branches at compile time

---------

Co-authored-by: Hannes Wüthrich <hannes.wuethrich@zebbra.ch>
2024-08-31 15:53:14 -04:00
Zach Daniel
4adddcdd69 Revert "improvement: make authorization failures behave consistently across reads"
This reverts commit ffa37d0c95.
2024-08-30 19:51:46 -04:00
Zach Daniel
ffa37d0c95 improvement: make authorization failures behave consistently across reads 2024-08-30 19:45:28 -04:00
Rebecca Le
cc55670c7f
bug: Add failing test for lazy-reloaded calculations that aren't loading their dependencies (#1420) 2024-08-30 18:29:38 -04:00
Zach Daniel
cb80df9ed8 test: test new default keyset pagination 2024-08-30 17:36:10 -04:00
Zach Daniel
9b0fb15ecb fix: honor the countable option in pagination
the default unfortunately had to be changed to `true`, given that it was being ignored before

chore: clean up error declarations
2024-08-30 15:34:40 -04:00
Zach Daniel
0007d0e60a fix: return proper data shape when doing a read in a transaction
closes #1410
2024-08-30 15:19:38 -04:00
Jinkyou Son
e2731ecd2d
Replace PaginationNotSupported exception with ActionRequiresPagination exception (#1411) 2024-08-30 13:11:46 -04:00
Hannes Wüthrich
4a75743812
Fix generated change/3 function when only implementing batch_change/3 (#1415) 2024-08-28 08:04:52 -04:00
Zach Daniel
b841eaf54c chore: add tests for accept & some opts improvements 2024-08-21 11:58:11 -04:00
Zach Daniel
d593e3cee9 improvement: error at compile for bypasses that will have no effect
chore: remove unused `checks` field from `%Ash.Policy.Authorizer.Policy{}`
2024-08-20 21:30:55 -04:00
Zach Daniel
7cf38273fa improvement: prevent unnecessary calls to Ash.load 2024-08-20 11:55:46 -04:00
Zach Daniel
48507eac13 chore: run proper callback and test that we call the loading callback 2024-08-20 10:25:50 -04:00
Zach Daniel
51f57b6390 chore: pass context to load relationships 2024-08-20 10:18:01 -04:00
Zach Daniel
a43624c9f3
improvement: add cascade update built in change (#1398)
---------

Co-authored-by: Alykhan Jetha <aj@marketcircle.com>
2024-08-19 11:34:38 -04:00
Zach Daniel
7071884d05 improvement: optimize field checking for loading fields in query
improvement: allow functions in tracers for lazy loading metadata
2024-08-15 21:19:23 -04:00
Jonatan Männchen
e200b5b9d1
chore: Implement upsert_condition for bulk create (#1389) 2024-08-14 20:26:03 -04:00
Zach Daniel
ba30ec880e chore: clean up tests 2024-08-14 11:46:18 -04:00
Zach Daniel
7cb3e04b2a fix: fix ets lateral join source field usage
fix: properly apply distinct in ets
2024-08-14 11:11:03 -04:00
Jonatan Männchen
93775109c7
improvement: Implement condition for upsert (#1386)
Resolves #1385
2024-08-13 19:19:13 -04:00
Zach Daniel
1654ccdead fix: properly pass actor, action, tenant etc. to lazy loaded relationships 2024-08-13 11:16:00 -04:00
Zach Daniel
dc73c3a3d5 feat: add policy groups
Policy groups allow you to group policies by shared conditions.
This can help simplify the mental overhead of large sets of policies.

For example:

```elixir
policies do
  policy_group actor_attribute_equals(:role, :owner) do
    policy action_type(:read) do
      authorize_if expr(owner_id == ^actor(:id))
    end

    policy action_type([:create, :update, :destroy]) do
      forbid_if
      authorize_if expr(owner_id == ^actor(:id))
    end
  end
end
```
2024-08-09 16:48:54 -04:00
Zach Daniel
5a4864650b improvement: prune calculations made unnecessary by field policies
closes #1356
2024-08-09 13:46:02 -04:00
Zach Daniel
2f22905ff3 chore: add better errors to help debug strange path/field errors in sort code 2024-08-08 20:26:53 -04:00
Jinkyou Son
2fc934fb61
fix: Fix error with nil value on structure types (#1380)
* Fix no cond clause evaluated to a truthy value error

* Fix error with nil value

* Add tests
2024-08-08 20:15:20 -04:00
Zach Daniel
763b0c59ed chore: update tests to avoid flakiness 2024-08-07 19:44:01 -04:00
Zach Daniel
a719c791ba improvement: add optimized path for casting embeds when they are simple
improvement: add `include_embedded_source_by_default?` config to optimize embeds
improvement: support `:fields` constraint on `:struct` type, enabling persistence
2024-08-07 16:47:01 -04:00
Jonatan Männchen
d1efc3fb6c
fix: after_batch arguments for bulk_create with return_records? disabled (#1371)
Fixes #1369
2024-08-07 16:17:40 -04:00
Jonatan Männchen
4efe51418e
improvement: Warn on bulk action return_stream? without any other return_*? options enabled. (#1370)
Resolves #1368
2024-08-07 14:51:15 -04:00
Minsub Kim
ad1a634fc0
test: use other resource's calculation in expr (#1365) 2024-08-06 08:44:15 -04:00
Zach Daniel
c4a910a5d1 improvement: support authorize_with option on Ash.read 2024-08-05 12:36:19 -04:00
m0rt3nlund
4508b439a5
improvement: Add defaults and typespec to resulting Resource struct (#1364)
* improvement: Add typespec to resource if it doesn't exist

---------

Co-authored-by: morten.lund@maskon.no <morten.lund@maskon.no>
Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
2024-08-05 10:35:17 -04:00
Zach Daniel
54738baad2 fix: prefer source_attribute is required, instead of relationship name
we only do this if the source attribute is accepted by the action

fixes #1362
2024-08-02 09:41:34 -04:00
Zach Daniel
28f73546cc fix: roll back bulk update/destroy on before action error 2024-08-01 12:09:01 -04:00
Zach Daniel
db54a655c8 fix: properly key nested calculations and add additional tests 2024-07-31 13:19:04 -04:00
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