@@ -24,7 +24,8 @@ rules_version = '2';
2424 * Fetches and returns the survey with the specified id.
2525 */
2626 function getSurvey (surveyId ) {
27- return get (/ databases/ $(database )/ documents/ surveys/ $(surveyId )).data ;
27+ let doc = get (/ databases/ $(database )/ documents/ surveys/ $(surveyId ));
28+ return doc == null ? null : doc.data ;
2829 }
2930
3031 /**
@@ -57,14 +58,16 @@ rules_version = '2';
5758 * Returns the regular expression matching emails granted access.
5859 */
5960 function getPassRegexp () {
60- return get (/ databases/ $(database )/ documents/ passlist/ regexp ).data.regexp
61+ let doc = get (/ databases/ $(database )/ documents/ passlist/ regexp );
62+ return doc == null ? null : doc.data.regexp ;
6163 }
6264
6365 /**
6466 * Returns true iff the user ' s email is listed in the passlist or allowed via regex.
6567 */
6668 function isPasslisted() {
67- return request.auth.token.email.matches(getPassRegexp())
69+ let regexp = getPassRegexp();
70+ return (regexp != null && request.auth.token.email.matches(regexp))
6871 || exists(/databases/$(database)/documents/passlist/$(request.auth.token.email));
6972 }
7073
@@ -80,7 +83,7 @@ rules_version = '2';
8083 * survey.
8184 */
8285 function canViewSurvey (survey ) {
83- return isSignedIn () &&
86+ return survey != null && isSignedIn () &&
8487 (isUnlistedOrPublic (survey ) || getRole (survey ) != null );
8588 }
8689
@@ -115,7 +118,7 @@ rules_version = '2';
115118 * assigned this role by default.
116119 */
117120 function canManageSurvey (survey ) {
118- return isSignedIn () && isOneOf (survey , [
121+ return survey != null && isSignedIn () && isOneOf (survey , [
119122 3 /* SURVEY_ORGANIZER */
120123 ]);
121124 }
@@ -125,7 +128,7 @@ rules_version = '2';
125128 * and submissions to the specified survey.
126129 */
127130 function canCollectData (survey ) {
128- return isSignedIn () &&
131+ return survey != null && isSignedIn () &&
129132 (isUnlistedOrPublic (survey ) || isOneOf (survey , [
130133 2 /* DATA_COLLECTOR */ ,
131134 3 /* SURVEY_ORGANIZER */
0 commit comments