1+ from enum import Enum
2+
13import graphene
24from django .conf import settings
35from django .core .exceptions import SuspiciousOperation
1012from ..models .response import Response
1113from ..models .survey import Survey
1214from .response import ProfileResponseType
13- from .survey_full import SurveyType
15+ from .survey_full import FullSurveyType
1416
1517DEFAULT_LANGUAGE : str = settings .LANGUAGE_CODE
1618
1719
1820SurveyAppType = graphene .Enum .from_enum (SurveyApp )
1921
2022
23+ class SurveyRelation (Enum ):
24+ SUBSCRIBED = "SUBSCRIBED"
25+ ACCESSIBLE = "ACCESSIBLE"
26+
27+
2128class FormsEventMetaType (graphene .ObjectType ):
2229 surveys = graphene .List (
23- graphene .NonNull (SurveyType ),
30+ graphene .NonNull (FullSurveyType ),
2431 include_inactive = graphene .Boolean (),
2532 app = graphene .NonNull (SurveyAppType ),
2633 )
@@ -53,7 +60,7 @@ def resolve_surveys(
5360 return qs
5461
5562 survey = graphene .Field (
56- SurveyType ,
63+ FullSurveyType ,
5764 slug = graphene .String (required = True ),
5865 app = graphene .Argument (SurveyAppType ),
5966 )
@@ -114,15 +121,23 @@ def resolve_response(meta: FormsProfileMeta, info, id: str):
114121 )
115122
116123 @staticmethod
117- def resolve_surveys (meta : FormsProfileMeta , info , event_slug : str | None = None ):
124+ def resolve_surveys (
125+ meta : FormsProfileMeta ,
126+ info ,
127+ event_slug : str | None = None ,
128+ relation : SurveyRelation = SurveyRelation .ACCESSIBLE ,
129+ ):
118130 """
119- Returns all surveys subscribed to by the current user.
131+ Returns all surveys accessible by the current user.
132+ To limit to surveys subscribed to, specify `relation: SUBSCRIBED`.
133+ To limit by event, specify `eventSlug: $eventSlug`.
120134 """
121135 if info .context .user != meta .person .user :
122136 raise SuspiciousOperation ("User mismatch" )
123137
124- surveys = Survey .objects .filter (subscribers = meta .person .user )
125-
138+ surveys = Survey .objects .all ()
139+ if relation == SurveyRelation .SUBSCRIBED :
140+ surveys = surveys .filter (subscribers = meta .person .user )
126141 if event_slug :
127142 surveys = surveys .filter (event__slug = event_slug )
128143
@@ -141,8 +156,9 @@ def resolve_surveys(meta: FormsProfileMeta, info, event_slug: str | None = None)
141156
142157 surveys = graphene .NonNull (
143158 graphene .List (
144- graphene .NonNull (SurveyType ),
159+ graphene .NonNull (FullSurveyType ),
145160 ),
146161 event_slug = graphene .String (),
162+ relation = graphene .Argument (graphene .Enum .from_enum (SurveyRelation )),
147163 description = normalize_whitespace (resolve_surveys .__doc__ or "" ),
148164 )
0 commit comments