<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="287253" data-post-id="287253">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well with this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    policy action_type(:read) do
      authorize_if(IsOwnerCheck)
    end
</code></pre>
<p>and this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule IsOwnerCheck do
    use Ash.Policy.SimpleCheck

    def match?(actor, context, opts) do
      What.To.Do.here?
    end

    def describe(x) do
      x |&gt; IO.inspect(label: ~S/x/)
      "hello"
    end
  end
</code></pre>
<p>I am not sure what I should do in the simple check. The context contains a query but If I run the query I get an infinite loop. I cannot use MyApi.can? because that would be an infinite loop as well.</p>
<p>I am not sure if I want the JSON API extension right now. I’all have two or three resources only but with some complicated logic in the backend, I do not feel like a REST API would be good for this. But I might try.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="287253" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ash-authentication-on-mobile/55568/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-287253" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="287253"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="287254" data-post-id="287254">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachdaniel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/120/31980_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachdaniel
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Ash</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ah, I was thinking you would want an <code>Ash.Policy.Check</code> instead of  an <code>Ash.Policy.SimpleCheck</code>. But even then the <code>check</code> function has you manually filter down the results, like so:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule IsOwnerCheck do
    use Ash.Policy.SimpleCheck

    def describe(_x) do
      "actor is owner"
    end

    def strict_check(_, _, _) do
      :unknown
    end

    def check(_, records, _) do
      # return only the records that match
      Enum.filter(records, fn record -&gt; 
        ...matches?
      end)
    end
  end
</code></pre>
<p>But that isn’t what you’d want in this case. I think we’d want to expand the policy options to allow you to do something like this as an “after” check, which doesn’t filter and can only forbid access. Barring that, I would suggest the after action hook that returns the forbidden error. Its hard for me to say looking at it why its not working for you, but I’ve got very similar setups in various places.</p>
<p>The simplest answer in your case to get you over the current hurdle would to just put the same logic you’d put in the controller in the after action hook, and skip the <code>Api.can?</code> step.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="287254" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ash-authentication-on-mobile/55568/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-287254" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="287254"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="287263" data-post-id="287263">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ok so I got it working like you said by putting the logic in the “after”:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    read :by_id do
      argument(:id, :uuid, allow_nil?: false)
      get?(true)
      filter(expr(id == ^arg(:id)))

      prepare(fn query, %{actor: actor} -&gt;
        Ash.Query.after_action(query, fn
          _, [] -&gt;
            {:ok, []}

          _, [single] -&gt;
            case single.owner_id == actor.id do
              true -&gt; {:ok, [single]}
              false -&gt; {:error, Ash.Error.Forbidden.exception([])}
            end
        end)
      end)
    end
</code></pre>
<p>Next step will be to look in the “allowances” table if there is a record for that inventory and that actor, to also allow <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>
<p>Thank you for your help <a class="mention" href="/u/zachdaniel" rel="nofollow">@zachdaniel</a> !</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="287263" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ash-authentication-on-mobile/55568/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-287263" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="287263"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>