diff --git a/src/config/constants.ts b/src/config/constants.ts index 6c68dd7b..9817e9ee 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -1,4 +1,5 @@ import { StatusCodes } from 'http-status-codes'; +import { PermissionLevel } from '@graasp/sdk'; // React Query Configs // time during which cache entry is never refetched @@ -21,12 +22,13 @@ export const THUMBNAIL_SIZES = { }; export const DEFAULT_THUMBNAIL_SIZES = THUMBNAIL_SIZES.SMALL; -export const PERMISSION_LEVELS = { - WRITE: 'write', - READ: 'read', - ADMIN: 'admin', -}; -export const DEFAULT_PERMISSION = PERMISSION_LEVELS.READ; +export const DEFAULT_PERMISSION = PermissionLevel.Read; + +// Has to match with https://github.com/graasp/graasp-apps/blob/main/src/interfaces/app-details.ts +export enum AppDataVisibility { + ITEM = 'item', + MEMBER = 'member', +} export const DEFAULT_CONTEXT = 'standalone'; export const DEFAULT_LANG = 'en'; diff --git a/src/mockServer/fixtures.ts b/src/mockServer/fixtures.ts index b9cb02e9..03bb77bb 100644 --- a/src/mockServer/fixtures.ts +++ b/src/mockServer/fixtures.ts @@ -1,4 +1,4 @@ -import { PERMISSION_LEVELS } from '../config/constants'; +import { PermissionLevel } from '@graasp/sdk'; import { buildContext } from '../hooks/postMessage'; import { LocalContext, Member } from '../types'; import { Context } from '@graasp/sdk'; @@ -18,7 +18,7 @@ export const buildMockLocalContext = (appContext = {}) => { memberId: MOCK_SERVER_MEMBER.id, offline: false, apiHost: 'http://localhost:3000', - permission: PERMISSION_LEVELS.READ, + permission: PermissionLevel.Read, context: Context.PLAYER, dev: true, ...appContext, diff --git a/src/mockServer/mockServer.ts b/src/mockServer/mockServer.ts index 1bcca525..328ed13f 100644 --- a/src/mockServer/mockServer.ts +++ b/src/mockServer/mockServer.ts @@ -3,6 +3,7 @@ import { createServer, Model, Factory, RestSerializer, Response } from 'miragejs import { API_ROUTES } from '../api/routes'; import { AppAction, AppData, AppSetting, Database, LocalContext, Member } from '../types'; import { buildMockLocalContext, MOCK_SERVER_ITEM, MOCK_SERVER_MEMBER } from './fixtures'; +import { AppDataVisibility } from '../config/constants'; const { buildGetAppDataRoute, @@ -80,6 +81,7 @@ export const mockServer = ({ itemId: currentItemId, memberId: currentMemberId, creator: currentMemberId, + visibility: () => AppDataVisibility.MEMBER, // TODO: Is it right? }), appActionResource: Factory.extend({ id: () => v4(), diff --git a/src/types.ts b/src/types.ts index e499416e..6c624eda 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ import { List, Record } from 'immutable'; import { Context, PermissionLevel } from '@graasp/sdk'; +import { AppDataVisibility } from './config/constants'; // generic type type EnumToUnionType = T extends `${infer R}` ? R : never; @@ -63,6 +64,7 @@ export type AppData = { updatedAt: string; memberId: UUID; itemId: UUID; + visibility: AppDataVisibility; }; export type AppAction = { diff --git a/test/constants.ts b/test/constants.ts index 7c0eee17..d764c5d2 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -1,4 +1,5 @@ import { v4 } from 'uuid'; +import { AppDataVisibility } from '../src/config/constants'; import { AppData, AppSetting, LocalContext, Member } from '../src/types'; export const API_HOST = 'http://localhost:3000'; @@ -63,6 +64,7 @@ export const buildAppData = ({ id = v4(), data = {} }: Partial = {}): A updatedAt: Date.now().toString(), memberId: 'memberId', itemId: 'itemId', + visibility: AppDataVisibility.MEMBER, }); export const FIXTURE_APP_DATA: AppData[] = [buildAppData(), buildAppData(), buildAppData()];