MCPcopy Create free account
hub / github.com/bytebase/bytebase / isWorksheetWritableV1

Function isWorksheetWritableV1

frontend/src/utils/v1/worksheet.ts:50–76  ·  view source on GitHub ↗
(sheet: Worksheet)

Source from the content-addressed store, hash-verified

48// PROJECT_WRITE: workspace Owner/DBA and all members in the project.
49// PROJECT_READ: workspace Owner/DBA and project owner.
50export const isWorksheetWritableV1 = (sheet: Worksheet) => {
51 const currentUser = getCurrentUserV1();
52
53 if (extractUserEmail(sheet.creator) === currentUser.email) {
54 // Always writable to the creator
55 return true;
56 }
57
58 if (hasWorkspacePermissionV2("bb.worksheets.manage")) {
59 return true;
60 }
61
62 const projectV1 = getProjectByName(sheet.project);
63 if (projectV1.name === UNKNOWN_PROJECT_NAME) {
64 return false;
65 }
66 switch (sheet.visibility) {
67 case Worksheet_Visibility.PRIVATE:
68 return false;
69 case Worksheet_Visibility.PROJECT_WRITE:
70 return hasProjectPermissionV2(projectV1, "bb.projects.get");
71 case Worksheet_Visibility.PROJECT_READ:
72 return hasProjectPermissionV2(projectV1, "bb.worksheets.manage");
73 }
74
75 return false;
76};
77
78// `extractWorksheetConnection` moved to `@/react/lib/sqlEditorConnection`
79// so the database lookup can go through the React app store without

Callers 4

EditorActionFunction · 0.90
runAutoSaveFunction · 0.90
useDropdownFunction · 0.90
useWorksheetAndTabFunction · 0.90

Calls 5

getCurrentUserV1Function · 0.90
extractUserEmailFunction · 0.90
hasWorkspacePermissionV2Function · 0.90
getProjectByNameFunction · 0.90
hasProjectPermissionV2Function · 0.90

Tested by

no test coverage detected