From 0c907d99eacf5b298434cd3d05ef94f2bef44581 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Wed, 6 Nov 2024 16:31:00 +0100 Subject: [PATCH] feat: Change video visibility (#484) --- apps/cf_graphql/lib/resolvers/videos.ex | 23 +++++++++++++++++++++++ apps/cf_graphql/lib/schema/schema.ex | 11 +++++++++++ apps/cf_graphql/lib/schema/types/video.ex | 2 ++ apps/cf_rest_api/lib/views/video_view.ex | 3 ++- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/apps/cf_graphql/lib/resolvers/videos.ex b/apps/cf_graphql/lib/resolvers/videos.ex index 141e8245..1e4c51a2 100644 --- a/apps/cf_graphql/lib/resolvers/videos.ex +++ b/apps/cf_graphql/lib/resolvers/videos.ex @@ -114,4 +114,27 @@ defmodule CF.Graphql.Resolvers.Videos do CF.LLMs.StatementsCreator.process_video!(video.id) {:ok, video} end + + def edit(_root, %{id: id, unlisted: unlisted}, %{ + context: %{user: user} + }) do + base_video = DB.Repo.get!(DB.Schema.Video, id) + changeset = Ecto.Changeset.change(base_video, %{unlisted: unlisted}) + + Ecto.Multi.new() + |> Ecto.Multi.update(:video, fn _repo -> + changeset + end) + |> Ecto.Multi.run(:action, fn _repo, %{video: video} -> + Repo.insert(CF.Actions.ActionCreator.action_update(user.id, changeset)) + end) + |> Repo.transaction() + |> case do + {:ok, %{video: video}} -> + {:ok, video} + + {:error, _} -> + {:error, "Failed to update video"} + end + end end diff --git a/apps/cf_graphql/lib/schema/schema.ex b/apps/cf_graphql/lib/schema/schema.ex index e3c55404..e0b1458e 100644 --- a/apps/cf_graphql/lib/schema/schema.ex +++ b/apps/cf_graphql/lib/schema/schema.ex @@ -99,5 +99,16 @@ defmodule CF.Graphql.Schema do resolve(&Resolvers.Videos.start_automatic_statements_extraction/3) end + + field :edit_video, :video do + middleware(Middleware.RequireAuthentication) + # MIN_REPUTATION_UPDATE_VIDEO + middleware(Middleware.RequireReputation, 75) + + arg(:id, non_null(:id)) + arg(:unlisted, non_null(:boolean)) + + resolve(&Resolvers.Videos.edit/3) + end end end diff --git a/apps/cf_graphql/lib/schema/types/video.ex b/apps/cf_graphql/lib/schema/types/video.ex index f61b5e4a..309f6397 100644 --- a/apps/cf_graphql/lib/schema/types/video.ex +++ b/apps/cf_graphql/lib/schema/types/video.ex @@ -38,6 +38,8 @@ defmodule CF.Graphql.Schema.Types.Video do field(:inserted_at, :string) @desc "Define if video has been added by a partner or a regular user" field(:is_partner, :boolean) + @desc "Define if video is unlisted" + field(:unlisted, non_null(:boolean)) @desc "List all non-removed speakers for this video" field :speakers, list_of(:speaker) do resolve(assoc(:speakers)) diff --git a/apps/cf_rest_api/lib/views/video_view.ex b/apps/cf_rest_api/lib/views/video_view.ex index b6e55b17..396c9e4d 100644 --- a/apps/cf_rest_api/lib/views/video_view.ex +++ b/apps/cf_rest_api/lib/views/video_view.ex @@ -43,7 +43,8 @@ defmodule CF.RestApi.VideoView do speakers: render_many(video.speakers, CF.RestApi.SpeakerView, "speaker.json"), language: video.language, is_partner: video.is_partner, - is_subscribed: is_subscribed + is_subscribed: is_subscribed, + unlisted: video.unlisted } end end