Commit d8ab72b5 authored by Alex Castaño's avatar Alex Castaño

Comment contexts

parent b39926d9
......@@ -12,7 +12,12 @@ build: ## Build the Docker image
@echo APP_NAME=$(APP_NAME)
@echo APP_VSN=$(APP_VSN)
@echo APP_BUILD=$(APP_BUILD)
docker build \
@echo docker build \
--no-cache \
--build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
@docker build \
--no-cache \
--build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
......@@ -23,19 +28,29 @@ build_with_cache: ## Build the Docker image
@echo APP_NAME=$(APP_NAME)
@echo APP_VSN=$(APP_VSN)
@echo APP_BUILD=$(APP_BUILD)
docker build \
@echo docker build \
--build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
@docker build \
--build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
-t moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) .
@echo moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
tag:
push:
@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
@echo docker push moodlenet/moodlenet:latest
@docker push moodlenet/moodlenet:latest
push_stable:
@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:latest
@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:$(APP_VSN)
@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:$(APP_VSN)
push:
@echo docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:stable
@docker tag moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD) moodlenet/moodlenet:stable
@echo docker push moodlenet/moodlenet:latest
@docker push moodlenet/moodlenet:latest
@echo docker push moodlenet/moodlenet:$(APP_VSN)
......
......@@ -170,13 +170,6 @@ defmodule ActivityPub.SQL.Query do
end)
end
defp to_local_ids(entities, assoc) do
Enum.map(entities, fn
e when APG.is_entity(e) -> Common.local_id(e[assoc])
int when is_integer(int) -> int
end)
end
def has?(subject, rel, target)
when APG.is_entity(subject) and APG.has_status(subject, :loaded) and APG.is_entity(target) and
APG.has_status(target, :loaded)
......@@ -265,8 +258,6 @@ defmodule ActivityPub.SQL.Query do
def belongs_to(%Ecto.Query{} = query, unquote(name), ext_ids)
when is_list(ext_ids) do
field_name = "#{unquote(name)}_id"
from([entity: entity] in query,
join: rel in fragment(unquote(table_name)),
as: unquote(name),
......@@ -407,9 +398,9 @@ defmodule ActivityPub.SQL.Query do
"Invalid status: #{Entity.status(e)}. Only entities with status :loaded can be preloaded"
)
defp print_query(query) do
{query_str, args} = Ecto.Adapters.SQL.to_sql(:all, Repo, query)
IO.puts("#{query_str} <=> #{inspect(args)}")
query
end
# defp print_query(query) do
# {query_str, args} = Ecto.Adapters.SQL.to_sql(:all, Repo, query)
# IO.puts("#{query_str} <=> #{inspect(args)}")
# query
# end
end
......@@ -15,7 +15,7 @@ defmodule MoodleNetWeb.GraphQL.MiscSchema do
end
def fetch_web_metadata(%{url: url}, info) do
with {:ok, actor} <- current_actor(info) do
with {:ok, _actor} <- current_actor(info) do
case MoodleNet.MetadataScraper.fetch(url) do
{:error, _} -> Errors.bad_gateway_error()
ret -> ret
......
......@@ -248,6 +248,19 @@ defmodule MoodleNetWeb.GraphQL.MoodleNetSchema do
field(:author, :user, do: resolve(with_assoc(:attributed_to, single: true)))
field(:in_reply_to, :comment, do: resolve(with_assoc(:in_reply_to, single: true)))
field(:replies, list_of(:comment), do: resolve(with_assoc(:replies)))
field(:context, :comment_context, do: resolve(with_assoc(:context, single: true)))
end
union :comment_context do
description("Where the comment resides")
types([:collection, :community])
resolve_type(fn
e, _ when APG.has_type(e, "MoodleNet:Community") -> :community
e, _ when APG.has_type(e, "MoodleNet:Collection") -> :collection
end)
end
input_object :comment_input do
......
......@@ -7,6 +7,99 @@ defmodule MoodleNetWeb.GraphQL.MoodleNetSchemaTest do
import ActivityPub.Entity, only: [local_id: 1]
@moduletag format: :json
@tag :user
test "comment context", %{conn: conn, actor: actor} do
community = Factory.community(actor)
collection = Factory.collection(actor, community)
resource = Factory.resource(actor, collection)
%{id: comm_comment_id} = Factory.comment(actor, community)
%{id: coll_comment_id} = Factory.comment(actor, collection)
query = """
{
threads(contextLocalId: #{local_id(community)}) {
id
context {
__typename
... on Community {
id
name
collections {
id
}
}
... on Collection {
id
name
resources {
id
}
}
}
}
}
"""
assert [comm_comment_map] =
conn
|> post("/api/graphql", %{query: query})
|> json_response(200)
|> Map.fetch!("data")
|> Map.fetch!("threads")
assert %{
"id" => ^comm_comment_id,
"context" => community_map
} = comm_comment_map
assert community_map["__typename"] == "Community"
assert community_map["id"] == community.id
assert community_map["name"] == community.name["und"]
assert [%{"id" => collection_id}] = community_map["collections"]
assert collection_id == collection.id
query = """
{
threads(contextLocalId: #{local_id(collection)}) {
id
context {
__typename
... on Community {
id
name
collections {
id
}
}
... on Collection {
id
name
resources {
id
}
}
}
}
}
"""
assert [coll_comment_map] =
conn
|> post("/api/graphql", %{query: query})
|> json_response(200)
|> Map.fetch!("data")
|> Map.fetch!("threads")
assert %{
"id" => ^coll_comment_id,
"context" => collection_map
} = coll_comment_map
assert collection_map["__typename"] == "Collection"
assert collection_map["id"] == collection.id
assert collection_map["name"] == collection.name["und"]
assert [%{"id" => resource_id}] = collection_map["resources"]
assert resource_id == resource.id
end
@tag :user
test "list following communities", %{conn: conn, actor: actor} do
%{id: community_id} = community = Factory.community(actor)
......@@ -86,6 +179,9 @@ defmodule MoodleNetWeb.GraphQL.MoodleNetSchemaTest do
id
}
}
context {
id
}
}
}
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment