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

CV2-3684: refactor update status mutation #1642

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions app/graph/mutations/graphql_crud_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ def self.apply_bulk_update_or_destroy(inputs, ctx, update_or_destroy, klass)
.to_h
.reject { |k, _v| %w[ids clientMutationId].include?(k.to_s) }
.with_indifferent_access
method_mapping = { update: :bulk_update, destroy: :bulk_destroy, mark_read: :bulk_mark_read }
method = method_mapping[update_or_destroy.to_sym]
method = "bulk_#{update_or_destroy.to_sym}"
result = klass.send(method, sql_ids, filtered_inputs, Team.current)
if update_or_destroy.to_s == "update"
unless update_or_destroy.to_s == "destroy"
result.merge!({ updated_objects: klass.where(id: sql_ids) })
end
{ ids: processed_ids }.merge(result)
Expand Down
24 changes: 22 additions & 2 deletions app/graph/mutations/project_media_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ module SharedCreateAndUpdateFields
end
end

module SharedUpdatedObjectsField
extend ActiveSupport::Concern

included do
field :updated_objects, [ProjectMediaType, null: true], null: true, camelize: false
end
end

class Create < Mutations::CreateMutation
include SharedCreateAndUpdateFields

Expand Down Expand Up @@ -106,15 +114,27 @@ class Update < Mutations::BulkUpdateMutation
end

class MarkRead < Mutations::BaseMutation
include SharedUpdatedObjectsField

define_shared_bulk_behavior(:mark_read, self, MUTATION_TARGET, GraphqlCrudOperations.hashify_parent_types(PARENTS))

description "Allow multiple items to be marked as read or unread."

graphql_name "BulkProjectMediaMarkRead"

field :updated_objects, [ProjectMediaType, null: true], null: true, camelize: false

argument :read, GraphQL::Types::Boolean, "A boolean value for ProjectMedia read value", required: true, camelize: false
end

class UpdateStatus < Mutations::BaseMutation
include SharedUpdatedObjectsField

define_shared_bulk_behavior(:update_status, self, MUTATION_TARGET, GraphqlCrudOperations.hashify_parent_types(PARENTS))

description "Update status for multiple items."

graphql_name "BulkProjectMediaUpdateStatus"

argument :status, GraphQL::Types::String, "Property whose value is a string corresponding to a status id", required: true
end
end
end
1 change: 1 addition & 0 deletions app/graph/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MutationType < BaseObject
field :destroyProjectMedia, mutation: ProjectMediaMutations::Destroy
field :replaceProjectMedia, mutation: ProjectMediaMutations::Replace
field :bulkProjectMediaMarkRead, mutation: ProjectMediaMutations::Bulk::MarkRead
field :bulkProjectMediaUpdateStatus, mutation: ProjectMediaMutations::Bulk::UpdateStatus

field :createUser, mutation: UserMutations::Create
field :updateUser, mutation: UserMutations::Update
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def collaborator_perms
changes = (after.to_a - before.to_a).to_h
obj.team&.id == @context_team.id && changes.keys == [] && !obj.annotated_is_trashed?
end
can [:administer_content, :bulk_update, :bulk_mark_read], ProjectMedia do |obj|
can [:administer_content, :bulk_update, :bulk_mark_read, :bulk_update_status], ProjectMedia do |obj|
obj.related_to_team?(@context_team) && obj.user_can_see_project?(@user)
end
can [:destroy, :update], [Dynamic, Annotation] do |obj|
Expand Down
9 changes: 4 additions & 5 deletions app/models/concerns/project_media_bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def bulk_update(ids, updates, team)
end
when 'assigned_to_ids'
self.bulk_assign(ids, params[:assigned_to_ids], params[:assignment_message], team)
when 'update_status'
self.bulk_update_status(ids, params[:status], team)
when 'remove_tags'
self.bulk_remove_tags(ids, params[:tags_text], team)
end
Expand Down Expand Up @@ -223,7 +221,8 @@ def run_bulk_assignment_create_callbacks(ids_json, status_mapping_json, extra_op
bulk_import_versions(versions, team_id) if versions.size > 0
end

def bulk_update_status(ids, status, team)
def bulk_update_status(ids, arguments, team)
status = arguments.with_indifferent_access[:status]
ids.map!(&:to_i)
# Exclude published reports
excluded_ids = []
Expand Down Expand Up @@ -325,8 +324,8 @@ def run_bulk_remove_tags_callbacks(ids_json, tag_text_ids_json, tag_pm_json)
client.bulk body: es_body unless es_body.blank?
end

def bulk_mark_read(ids, read, team)
read_value = read.with_indifferent_access[:read]
def bulk_mark_read(ids, arguments, team)
read_value = arguments.with_indifferent_access[:read]
pm_ids = ProjectMedia.where(id: ids).where.not(read: read_value).map(&:id)
# SQL bulk-update
updated_at = Time.now
Expand Down
Loading
Loading