From 55cf881c8dfb135b7bb4cc706fe4a0bfe9f71ec5 Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Sat, 19 Oct 2024 12:50:38 +1100 Subject: [PATCH] Add a deposit form link to collections --- app/graphql/mutations/essence_create.rb | 2 ++ app/graphql/mutations/essence_update.rb | 2 ++ .../set_collection_has_deposit_form.rb | 20 ++++++++++++ app/graphql/types/mutation_type.rb | 1 + ...0838_add_has_deposit_form_to_collection.rb | 5 +++ nabu.graphql | 31 +++++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 app/graphql/mutations/set_collection_has_deposit_form.rb create mode 100644 db/migrate/20241019010838_add_has_deposit_form_to_collection.rb diff --git a/app/graphql/mutations/essence_create.rb b/app/graphql/mutations/essence_create.rb index fd95a85c..2d656890 100644 --- a/app/graphql/mutations/essence_create.rb +++ b/app/graphql/mutations/essence_create.rb @@ -12,6 +12,8 @@ class EssenceCreate < BaseMutation argument :attributes, Types::EssenceAttributes, required: true def resolve(item_identifier:, collection_identifier:, filename:, attributes:) + raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated] + collection = Collection.find_by(identifier: collection_identifier) item = collection.items.find_by(identifier: item_identifier) diff --git a/app/graphql/mutations/essence_update.rb b/app/graphql/mutations/essence_update.rb index ae72f53d..2fcc3de2 100644 --- a/app/graphql/mutations/essence_update.rb +++ b/app/graphql/mutations/essence_update.rb @@ -10,6 +10,8 @@ class EssenceUpdate < BaseMutation argument :attributes, Types::EssenceAttributes, required: true def resolve(id:, attributes:) + raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated] + essence = ::Essence.find(id) raise GraphQL::ExecutionError.new 'Error updating essence', extensions: essence.errors.to_hash unless essence.update(**attributes) diff --git a/app/graphql/mutations/set_collection_has_deposit_form.rb b/app/graphql/mutations/set_collection_has_deposit_form.rb new file mode 100644 index 00000000..f79962a8 --- /dev/null +++ b/app/graphql/mutations/set_collection_has_deposit_form.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Mutations + class SetCollectionHasDepositForm < BaseMutation + description 'Marks as collection a having a deposit form' + + argument :identifier, String, required: true + + def resolve(identifier:) + raise(GraphQL::ExecutionError, 'Not authorised') unless context[:admin_authenticated] + + collection = ::Collection.find_by(identifier:) + collection.has_deposit_form = true + + raise GraphQL::ExecutionError.new 'Error updating collection', extensions: collection.errors.to_hash unless collection.save + + {} + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 7dd81a3d..6568d281 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -2,5 +2,6 @@ module Types class MutationType < Types::BaseObject field :essence_update, mutation: Mutations::EssenceUpdate field :essence_create, mutation: Mutations::EssenceCreate + field :set_collection_has_deposit_form, mutation: Mutations::SetCollectionHasDepositForm end end diff --git a/db/migrate/20241019010838_add_has_deposit_form_to_collection.rb b/db/migrate/20241019010838_add_has_deposit_form_to_collection.rb new file mode 100644 index 00000000..94c5ea78 --- /dev/null +++ b/db/migrate/20241019010838_add_has_deposit_form_to_collection.rb @@ -0,0 +1,5 @@ +class AddHasDepositFormToCollection < ActiveRecord::Migration[7.2] + def change + add_column :collections, :has_deposit_form, :boolean + end +end diff --git a/nabu.graphql b/nabu.graphql index b9247f22..be4c000b 100644 --- a/nabu.graphql +++ b/nabu.graphql @@ -299,6 +299,16 @@ type Mutation { """ input: EssenceUpdateInput! ): EssenceUpdatePayload + + """ + Marks as collection a having a deposit form + """ + setCollectionHasDepositForm( + """ + Parameters for SetCollectionHasDepositForm + """ + input: SetCollectionHasDepositFormInput! + ): SetCollectionHasDepositFormPayload } type Person { @@ -343,6 +353,27 @@ type Query { userByUnikey(unikey: String!): EmailUser } +""" +Autogenerated input type of SetCollectionHasDepositForm +""" +input SetCollectionHasDepositFormInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + identifier: String! +} + +""" +Autogenerated return type of SetCollectionHasDepositForm. +""" +type SetCollectionHasDepositFormPayload { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String +} + type University { collections: [Collection] id: ID!