Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change video visibility #484

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/cf_graphql/lib/resolvers/videos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions apps/cf_graphql/lib/schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions apps/cf_graphql/lib/schema/types/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion apps/cf_rest_api/lib/views/video_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading