Skip to content

Commit 29fd44c

Browse files
authored
Adds Survey General Access (proto, model, converter) (#2151)
1 parent d1ae971 commit 29fd44c

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

proto/src/ground/v1beta1/survey.proto

+19-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ message Survey {
7171
// collecting data.
7272
DataSharingTerms data_sharing_terms = 6;
7373

74-
// Defines the survey's current state.
74+
// Possible values for the survey's current state.
7575
enum State {
7676
// Default value when status is missing.
7777
STATE_UNSPECIFIED = 0;
@@ -85,6 +85,24 @@ message Survey {
8585

8686
// Defines the survey's current state.
8787
State state = 7;
88+
89+
// Possible values for who can access the survey beyond users in the ACLs.
90+
enum GeneralAccess {
91+
// Default value when general_access is missing.
92+
GENERAL_ACCESS_UNSPECIFIED = 0;
93+
94+
// Only users with the DATA_COLLECTOR role in the survey ACLs can contribute.
95+
RESTRICTED = 1;
96+
97+
// Anyone with a link or QR Code can contribute.
98+
UNLISTED = 2;
99+
100+
// Anyone can contribute.
101+
PUBLIC = 3;
102+
}
103+
104+
// Defines who can access the survey beyond users in the ACLs.
105+
GeneralAccess general_access = 8;
88106
}
89107

90108
// Defines a user's role in a survey.

web/src/app/converters/survey-data-converter.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
import {DocumentData} from '@angular/fire/firestore';
1718
import {toMessage} from '@ground/lib';
1819
import {GroundProtos} from '@ground/proto';
1920
import {List, Map} from 'immutable';
2021

2122
import {DataCollectionStrategy, Job} from 'app/models/job.model';
2223
import {Role} from 'app/models/role.model';
23-
import {DataSharingType, Survey, SurveyState} from 'app/models/survey.model';
24+
import {
25+
DataSharingType,
26+
Survey,
27+
SurveyGeneralAccess,
28+
SurveyState,
29+
} from 'app/models/survey.model';
2430
import {
2531
Cardinality,
2632
MultipleChoice,
@@ -47,7 +53,7 @@ export const MODEL_ROLES = Map([
4753
[Pb.Role.VIEWER, Role.VIEWER],
4854
]);
4955

50-
const DATA_SHARING_MODEL_TYPE = Map([
56+
const MODEL_SHARING_MODEL_TYPES = Map([
5157
[Pb.Survey.DataSharingTerms.Type.PRIVATE, DataSharingType.PRIVATE],
5258
[Pb.Survey.DataSharingTerms.Type.PUBLIC_CC0, DataSharingType.PUBLIC],
5359
[Pb.Survey.DataSharingTerms.Type.CUSTOM, DataSharingType.CUSTOM],
@@ -58,14 +64,20 @@ const MODEL_STATES = Map([
5864
[Pb.Survey.State.READY, SurveyState.READY],
5965
]);
6066

67+
const MODEL_VISIBILITIES = Map([
68+
[Pb.Survey.GeneralAccess.RESTRICTED, SurveyGeneralAccess.RESTRICTED],
69+
[Pb.Survey.GeneralAccess.UNLISTED, SurveyGeneralAccess.UNLISTED],
70+
[Pb.Survey.GeneralAccess.PUBLIC, SurveyGeneralAccess.PUBLIC],
71+
]);
72+
6173
function dataSharingTypeFromProto(
6274
protoType?: Pb.Survey.DataSharingTerms.Type | null
6375
) {
6476
if (!protoType) {
6577
return DataSharingType.PRIVATE;
6678
}
6779

68-
const dataSharingType = DATA_SHARING_MODEL_TYPE.get(protoType);
80+
const dataSharingType = MODEL_SHARING_MODEL_TYPES.get(protoType);
6981

7082
if (!dataSharingType) {
7183
return DataSharingType.PRIVATE;
@@ -212,6 +224,7 @@ export function surveyDocToModel(
212224
type: dataSharingTypeFromProto(pb.dataSharingTerms?.type),
213225
customText: pb.dataSharingTerms?.customText ?? undefined,
214226
},
215-
MODEL_STATES.get(pb.state)
227+
MODEL_STATES.get(pb.state),
228+
MODEL_VISIBILITIES.get(pb.generalAccess) || SurveyGeneralAccess.RESTRICTED
216229
);
217230
}

web/src/app/models/survey.model.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export enum SurveyState {
5050
READY = 2,
5151
}
5252

53+
/** Enum for survey's current general access. */
54+
export enum SurveyGeneralAccess {
55+
RESTRICTED = 1,
56+
UNLISTED = 2,
57+
PUBLIC = 3,
58+
}
59+
5360
export class Survey extends Copiable {
5461
static readonly UNSAVED_NEW = new Survey(
5562
/* id= */
@@ -66,7 +73,8 @@ export class Survey extends Copiable {
6673
'',
6774
/* dataSharingTerms= */
6875
{type: DataSharingType.PRIVATE},
69-
SurveyState.UNSAVED
76+
SurveyState.UNSAVED,
77+
SurveyGeneralAccess.RESTRICTED
7078
);
7179

7280
constructor(
@@ -77,7 +85,8 @@ export class Survey extends Copiable {
7785
readonly acl: ImmutableMap<string, Role>,
7886
readonly ownerId: string,
7987
readonly dataSharingTerms: {type: DataSharingType; customText?: string},
80-
readonly state?: SurveyState
88+
readonly state?: SurveyState,
89+
readonly generalAccess?: SurveyGeneralAccess
8190
) {
8291
super();
8392
}

web/src/testing/test-data.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import {Map} from 'immutable';
1818

1919
import {DataCollectionStrategy, Job} from 'app/models/job.model';
2020
import {Role} from 'app/models/role.model';
21-
import {DataSharingType, Survey, SurveyState} from 'app/models/survey.model';
21+
import {
22+
DataSharingType,
23+
Survey,
24+
SurveyGeneralAccess,
25+
SurveyState,
26+
} from 'app/models/survey.model';
2227
import {Task} from 'app/models/task/task.model';
2328
import {User} from 'app/models/user.model';
2429

@@ -56,7 +61,8 @@ export class TestData {
5661
{
5762
type: DataSharingType.PRIVATE,
5863
},
59-
SurveyState.DRAFT
64+
SurveyState.DRAFT,
65+
SurveyGeneralAccess.RESTRICTED
6066
);
6167
}
6268

0 commit comments

Comments
 (0)