diff --git a/lib/decidim/api/budget_mutation_type.rb b/lib/decidim/api/budget_mutation_type.rb index e59bb30..bf20792 100644 --- a/lib/decidim/api/budget_mutation_type.rb +++ b/lib/decidim/api/budget_mutation_type.rb @@ -16,14 +16,14 @@ class BudgetMutationType < GraphQL::Schema::Object argument :attributes, ProjectAttributes, required: true end - field :update_project, Decidim::Budgets::ProjectType, null: false do + field :update_project, Decidim::Budgets::ProjectType, null: true do description "A mutation to update a project within a budget." argument :id, GraphQL::Types::ID, required: true argument :attributes, ProjectAttributes, required: true end - field :delete_project, Decidim::Budgets::ProjectType, null: false do + field :delete_project, Decidim::Budgets::ProjectType, null: true do description "A mutation to delete a project within a budget." argument :id, GraphQL::Types::ID, required: true @@ -53,7 +53,9 @@ def create_project(attributes:) end def update_project(id:, attributes:) - project = object.projects.find(id) + project = object.projects.find_by(id: id) + return unless project + enforce_permission_to :update, :project, project: project form = project_form_from(attributes) @@ -74,7 +76,9 @@ def update_project(id:, attributes:) end def delete_project(id:) - project = object.projects.find(id) + project = object.projects.find_by(id: id) + return unless project + enforce_permission_to :destroy, :project, project: project Decidim::Budgets::Admin::DestroyProject.call(project, current_user) do