Merge pull request #4366 from betagouv/dev

2019-09-26-02
This commit is contained in:
LeSim 2019-09-26 16:03:42 +02:00 committed by GitHub
commit 5e8c89684f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 8 deletions

View file

@ -102,8 +102,8 @@ type Demarche {
"""
since: ISO8601DateTime
): DossierConnection!
groupeInstructeurs: [GroupeInstructeur!]!
id: ID!
instructeurs: [Profile!]!
"""
Le numero de la démarche.
@ -279,6 +279,15 @@ type GeoJSON {
type: String!
}
"""
Un groupe instructeur
"""
type GroupeInstructeur {
id: ID!
instructeurs: [Profile!]!
label: String!
}
"""
An ISO 8601-encoded datetime
"""

View file

@ -18,7 +18,7 @@ module Types
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :archived_at, GraphQL::Types::ISO8601DateTime, null: true
field :instructeurs, [Types::ProfileType], null: false
field :groupe_instructeurs, [Types::GroupeInstructeurType], null: false
field :dossiers, Types::DossierType.connection_type, "Liste de tous les dossiers d'une démarche.", null: false do
argument :ids, [ID], required: false, description: "Filtrer les dossiers par ID."
@ -32,8 +32,8 @@ module Types
object.aasm.current_state
end
def instructeurs
Loaders::Association.for(Procedure, :instructeurs).load(object)
def groupe_instructeurs
Loaders::Association.for(object.class, groupe_instructeurs: { procedure: [:administrateurs] }).load(object)
end
def dossiers(ids: nil, since: nil)

View file

@ -0,0 +1,17 @@
module Types
class GroupeInstructeurType < Types::BaseObject
description "Un groupe instructeur"
global_id_field :id
field :label, String, null: false
field :instructeurs, [Types::ProfileType], null: false
end
def instructeurs
Loaders::Association.for(object.class, :instructeurs).load(object)
end
def self.authorized?(object, context)
authorized_demarche?(object.procedure, context)
end
end

View file

@ -167,14 +167,14 @@ class Dossier < ApplicationRecord
scope :with_notifications, -> do
# This scope is meant to be composed, typically with Instructeur.followed_dossiers, which means that the :follows table is already INNER JOINed;
# it will fail otherwise
# Relations passed to #or must be “structurally compatible”, i.e. query the same tables.
joined_dossiers = left_outer_joins(:champs, :champs_private, :avis, :commentaires)
joined_dossiers = joins('LEFT OUTER JOIN "champs" ON "champs" . "dossier_id" = "dossiers" . "id" AND "champs" . "parent_id" IS NULL AND "champs" . "private" = FALSE AND "champs"."updated_at" > "follows"."demande_seen_at"')
.joins('LEFT OUTER JOIN "champs" "champs_privates_dossiers" ON "champs_privates_dossiers" . "dossier_id" = "dossiers" . "id" AND "champs_privates_dossiers" . "parent_id" IS NULL AND "champs_privates_dossiers" . "private" = TRUE AND "champs_privates_dossiers"."updated_at" > "follows"."annotations_privees_seen_at"')
.joins('LEFT OUTER JOIN "avis" ON "avis" . "dossier_id" = "dossiers" . "id" AND avis.updated_at > follows.avis_seen_at')
.joins('LEFT OUTER JOIN "commentaires" ON "commentaires" . "dossier_id" = "dossiers" . "id" and commentaires.updated_at > follows.messagerie_seen_at and "commentaires"."email" != \'contact@tps.apientreprise.fr\' AND "commentaires"."email" != \'contact@demarches-simplifiees.fr\'')
updated_demandes = joined_dossiers
.where('champs.updated_at > follows.demande_seen_at')
# We join `:champs` twice, the second time with `has_many :champs_privates`. ActiveRecord generates the SQL: 'LEFT OUTER JOIN "champs" "champs_privates_dossiers" ON …'. We can then use this `champs_privates_dossiers` alias to disambiguate the table in this WHERE clause.
updated_annotations = joined_dossiers
.where('champs_privates_dossiers.updated_at > follows.annotations_privees_seen_at')

View file

@ -24,6 +24,12 @@ describe API::V2::GraphqlController do
createdAt
updatedAt
archivedAt
groupeInstructeurs {
label
instructeurs {
email
}
}
champDescriptors {
id
type
@ -67,6 +73,7 @@ describe API::V2::GraphqlController do
archivedAt: nil,
createdAt: procedure.created_at.iso8601,
updatedAt: procedure.updated_at.iso8601,
groupeInstructeurs: [{ instructeurs: [], label: "défaut" }],
champDescriptors: procedure.types_de_champ.map do |tdc|
{
id: tdc.to_typed_id,