Skip to content

Commit

Permalink
Add item access
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Feb 23, 2024
1 parent 1cf28a6 commit 0ce3abc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/polar_web/controllers/streams/item_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule PolarWeb.Streams.ItemController do

alias Polar.Repo
alias Polar.Accounts
alias Polar.Streams
alias Polar.Streams.Item

action_fallback PolarWeb.FallbackController
Expand All @@ -19,6 +20,8 @@ defmodule PolarWeb.Streams.ItemController do

item = Repo.get!(Item, id)

Streams.record_item_access(item, credential)

endpoint = credential.space.cdn_host || default_cdn_host

url = Path.join(["https://", endpoint, item.path])
Expand Down
5 changes: 5 additions & 0 deletions test/polar_web/controllers/streams/item_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ defmodule PolarWeb.Streams.ItemControllerTest do
test "GET /spaces/:space_token/items/:id", %{credential: credential, item: item} do
conn = get(build_conn(), ~s"/spaces/#{credential.token}/items/#{item.id}")

item_access =
Repo.get_by(Streams.Item.Access, item_id: item.id, space_credential_id: credential.id)

assert item_access.count == 1

assert response(conn, 302)
end
end
Expand Down

0 comments on commit 0ce3abc

Please sign in to comment.