Skip to content

Commit

Permalink
Add media reaction unholding mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Dec 25, 2024
1 parent 5c2826f commit e7e213d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/graphql/mutations/media_reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class Mutations::MediaReaction < Mutations::Namespace
field :unlike, mutation: Mutations::MediaReaction::Unlike
field :create, mutation: Mutations::MediaReaction::Create
field :delete, mutation: Mutations::MediaReaction::Delete
field :unhold, mutation: Mutations::MediaReaction::Update
end
30 changes: 30 additions & 0 deletions app/graphql/mutations/media_reaction/unhold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class Mutations::MediaReaction::Unhold < Mutations::Base
include FancyMutation

directive Directive::SitePermission, required: 'community_mod'

description 'Mark a held reaction as fine, unholding it.'

input do
argument :media_reaction_id, ID, required: true
end
result Types::Post
errors Types::Errors::NotAuthorized,
Types::Errors::NotAuthenticated,
Types::Errors::NotFound

def ready?(media_reaction_id:)
authenticate!
@reaction = MediaReaction.find_by(id: media_reaction_id)
return errors << Types::Errors::NotFound.build if @reaction.nil?
authorize!(@reaction, :unhold?)
true
end

def resolve(**)
@reaction.update!(hidden_at: nil)
@reaction
end
end
2 changes: 2 additions & 0 deletions app/policies/media_reaction_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def destroy?
record.try(:user) == user || can_administrate?
end

def unhold? = can_administrate?

class Scope < Scope
def resolve
return scope if can_administrate?
Expand Down

0 comments on commit e7e213d

Please sign in to comment.