Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: worksheet access (#13045)

Danny Xu5d4caeb5ceab
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index eee9e45d4c..28d9b1819b 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -19,14 +19,12 @@ import (
"github.com/epiclabs-io/diff3"
"github.com/google/go-cmp/cmp"
- "github.com/pkg/errors"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/config"
"github.com/bytebase/bytebase/backend/component/iam"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
- api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
"github.com/bytebase/bytebase/backend/plugin/parser/mysql"
"github.com/bytebase/bytebase/backend/plugin/schema"
@@ -857,14 +855,6 @@ func (s *BranchService) checkProtectionRules(ctx context.Context, project *store
if len(project.Setting.GetProtectionRules()) == 0 {
return nil
}
- // Skip protection check for workspace owner and DBA.
- containsRole, err := s.iamManager.CheckUserContainsWorkspaceRoles(ctx, user, api.WorkspaceAdmin, api.WorkspaceDBA)
- if err != nil {
- return errors.Wrapf(err, "failed to check workspace role")
- }
- if containsRole {
- return nil
- }
policy, err := s.store.GetProjectIamPolicy(ctx, project.UID)
if err != nil {
diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.go
index 9a907a941c..6782e92302 100644
--- a/backend/api/v1/sheet_service.go
+++ b/backend/api/v1/sheet_service.go
@@ -13,9 +13,7 @@ import (
"github.com/bytebase/bytebase/backend/component/iam"
"github.com/bytebase/bytebase/backend/component/sheet"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
- api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
@@ -213,13 +211,6 @@ func (s *SheetService) UpdateSheet(ctx context.Context, request *v1pb.UpdateShee
if sheet == nil {
return nil, status.Errorf(codes.NotFound, "sheet %q not found", request.Sheet.Name)
}
- canAccess, err := s.canWriteSheet(ctx, sheet)
- if err != nil {
- return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
- }
- if !canAccess {
- return nil, status.Errorf(codes.PermissionDenied, "cannot write sheet %s", sheet.Title)
- }
sheetPatch := &store.PatchSheetMessage{
UID: sheet.UID,
@@ -258,39 +249,6 @@ func (s *SheetService) findSheet(ctx context.Context, find *store.FindSheetMessa
return sheet, nil
}
-// canWriteSheet check if the principal can write the sheet.
-// sheet if writable when:
-// PRIVATE: the creator only.
-// PROJECT: the creator or project role can manage sheet, workspace Owner and DBA.
-// PUBLIC: the creator only.
-func (s *SheetService) canWriteSheet(ctx context.Context, sheet *store.SheetMessage) (bool, error) {
- user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
- if !ok {
- return false, status.Errorf(codes.Internal, "user not found")
- }
-
- if sheet.CreatorID == user.ID {
- return true, nil
- }
-
- projectRoles, err := findProjectRoles(ctx, s.store, sheet.ProjectUID, user)
- if err != nil {
- return false, err
- }
- if len(projectRoles) == 0 {
- return false, nil
- }
- return projectRoles[common.FormatRole(api.ProjectOwner.String())], nil
-}
-
-func findProjectRoles(ctx context.Context, stores *store.Store, projectUID int, user *store.UserMessage) (map[string]bool, error) {
- policy, err := stores.GetProjectIamPolicy(ctx, projectUID)
- if err != nil {
- return nil, err
- }
- return utils.GetUserFormattedRolesMap(ctx, stores, user, policy.Policy), nil
-}
-
func (s *SheetService) convertToAPISheetMessage(ctx context.Context, sheet *store.SheetMessage) (*v1pb.Sheet, error) {
databaseParent := ""
if sheet.DatabaseUID != nil {
diff --git a/backend/api/v1/worksheet_service.go b/backend/api/v1/worksheet_service.go
index 4cbfff8159..b91f192f78 100644
--- a/backend/api/v1/worksheet_service.go
+++ b/backend/api/v1/worksheet_service.go
@@ -15,7 +15,6 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/iam"
- api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
@@ -127,11 +126,11 @@ func (s *WorksheetService) GetWorksheet(ctx context.Context, request *v1pb.GetWo
return nil, err
}
- canAccess, err := s.canReadWorksheet(ctx, worksheet)
+ ok, err := s.canReadWorksheet(ctx, worksheet)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
}
- if !canAccess {
+ if !ok {
return nil, status.Errorf(codes.PermissionDenied, "cannot access worksheet %s", worksheet.Title)
}
@@ -219,11 +218,11 @@ func (s *WorksheetService) SearchWorksheets(ctx context.Context, request *v1pb.S
var v1pbWorksheets []*v1pb.Worksheet
for _, worksheet := range worksheetList {
- canAccess, err := s.canReadWorksheet(ctx, worksheet)
+ ok, err := s.canReadWorksheet(ctx, worksheet)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
}
- if !canAccess {
+ if !ok {
slog.Warn("cannot access worksheet", slog.String("name", worksheet.Title))
continue
}
@@ -276,11 +275,11 @@ func (s *WorksheetService) UpdateWorksheet(ctx context.Context, request *v1pb.Up
if worksheet == nil {
return nil, status.Errorf(codes.NotFound, "worksheet %q not found", request.Worksheet.Name)
}
- canAccess, err := s.canWriteWorksheet(ctx, worksheet)
+ ok, err = s.canWriteWorksheet(ctx, worksheet)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
}
- if !canAccess {
+ if !ok {
return nil, status.Errorf(codes.PermissionDenied, "cannot write worksheet %s", worksheet.Title)
}
@@ -363,11 +362,11 @@ func (s *WorksheetService) DeleteWorksheet(ctx context.Context, request *v1pb.De
if worksheet == nil {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("worksheet with id %d not found", worksheetUID))
}
- canAccess, err := s.canWriteWorksheet(ctx, worksheet)
+ ok, err = s.canWriteWorksheet(ctx, worksheet)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
}
- if !canAccess {
+ if !ok {
return nil, status.Errorf(codes.PermissionDenied, "cannot write worksheet %s", worksheet.Title)
}
@@ -395,11 +394,11 @@ func (s *WorksheetService) UpdateWorksheetOrganizer(ctx context.Context, request
return nil, err
}
- canAccess, err := s.canReadWorksheet(ctx, worksheet)
+ ok, err := s.canWriteWorksheet(ctx, worksheet)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to check access with error: %v", err))
}
- if !canAccess {
+ if !ok {
return nil, status.Errorf(codes.PermissionDenied, "cannot access worksheet %s", worksheet.Title)
}
@@ -445,60 +444,63 @@ func (s *WorksheetService) findWorksheet(ctx context.Context, find *store.FindWo
}
// canWriteWorksheet check if the principal can write the worksheet.
-// worksheet if writable when:
-// PRIVATE: workspace Owner/DBA and the creator only.
-// PROJECT_WRITE: workspace Owner/DBA and all members in the project.
-// PROJECT_READ: workspace Owner/DBA and project owner.
+// worksheet is writable when the user has bb.worksheets.manage permission on the workspace, or.
+// PRIVATE: the creator.
+// PROJECT_WRITE: all members with bb.projects.get permission in the project.
func (s *WorksheetService) canWriteWorksheet(ctx context.Context, worksheet *store.WorkSheetMessage) (bool, error) {
user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
if !ok {
return false, status.Errorf(codes.Internal, "user not found")
}
- // Worksheet creator and workspace Owner/DBA can always write.
+ // Worksheet creator and workspace bb.worksheets.manage can always write.
if worksheet.CreatorID == user.ID {
return true, nil
}
- if s.checkUserRoles(ctx, user) {
- return true, nil
- }
-
- projectRoles, err := findProjectRoles(ctx, s.store, worksheet.ProjectUID, user)
+ ok, err := s.iamManager.CheckPermission(ctx, iam.PermissionWorksheetsManage, user)
if err != nil {
return false, err
}
- if len(projectRoles) == 0 {
- return false, nil
+ if ok {
+ return true, nil
}
switch worksheet.Visibility {
case store.PrivateWorkSheet:
return false, nil
case store.ProjectWriteWorkSheet:
- return len(projectRoles) > 0, nil
- case store.ProjectReadWorkSheet:
- return projectRoles[common.FormatRole(api.ProjectOwner.String())], nil
+ ok, err := s.iamManager.CheckPermission(ctx, iam.PermissionProjectsGet, user)
+ if err != nil {
+ return false, err
+ }
+ if ok {
+ return true, nil
+ }
}
return false, nil
}
// canReadWorksheet check if the principal can read the worksheet.
-// worksheet is readable when:
-// PRIVATE: workspace Owner/DBA and the creator only.
-// PROJECT_WRITE: workspace Owner/DBA and all members in the project.
-// PROJECT_READ: workspace Owner/DBA and all members in the project.
+// worksheet is readable when the user has bb.worksheets.get permission on the workspace, or.
+// PRIVATE: the creator only.
+// PROJECT_WRITE: all members with bb.projects.get permission in the project.
+// PROJECT_READ: all members with bb.projects.get permission in the project.
func (s *WorksheetService) canReadWorksheet(ctx context.Context, worksheet *store.WorkSheetMessage) (bool, error) {
user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
if !ok {
return false, status.Errorf(codes.Internal, "user not found")
}
- // Worksheet creator and workspace Owner/DBA can always read.
+ // Worksheet creator and workspace bb.worksheets.get can always read.
if worksheet.CreatorID == user.ID {
return true, nil
}
- if s.checkUserRoles(ctx, user) {
+ ok, err := s.iamManager.CheckPermission(ctx, iam.PermissionWorksheetsGet, user)
+ if err != nil {
+ return false, err
+ }
+ if ok {
return true, nil
}
@@ -506,26 +508,18 @@ func (s *WorksheetService) canReadWorksheet(ctx context.Context, worksheet *stor
case store.PrivateWorkSheet:
return false, nil
case store.ProjectReadWorkSheet, store.ProjectWriteWorkSheet:
- // For project level visibility, users can read the worksheet as long as they're the project member.
- projectRoles, err := findProjectRoles(ctx, s.store, worksheet.ProjectUID, user)
+ ok, err := s.iamManager.CheckPermission(ctx, iam.PermissionProjectsGet, user)
if err != nil {
return false, err
}
- return len(projectRoles) > 0, nil
+ if ok {
+ return true, nil
+ }
}
return false, nil
}
-func (s *WorksheetService) checkUserRoles(ctx context.Context, user *store.UserMessage) bool {
- containsRole, err := s.iamManager.CheckUserContainsWorkspaceRoles(ctx, user, api.WorkspaceAdmin, api.WorkspaceDBA)
- if err != nil {
- slog.Error("failed to check workspace role", log.BBError(err))
- return false
- }
- return containsRole
-}
-
func (s *WorksheetService) convertToAPIWorksheetMessage(ctx context.Context, worksheet *store.WorkSheetMessage) (*v1pb.Worksheet, error) {
databaseParent := ""
if worksheet.DatabaseUID != nil {
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index cc3e5e5d51..3360218361 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -40,11 +40,6 @@ func (s *WorkspaceService) GetIamPolicy(ctx context.Context, _ *v1pb.GetIamPolic
}
func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIamPolicyRequest) (*v1pb.IamPolicy, error) {
- userUID, err := s.checkUserIsAdmin(ctx)
- if err != nil {
- return nil, err
- }
-
policyMessage, err := s.store.GetWorkspaceIamPolicy(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to find workspace iam policy with error: %v", err.Error())
@@ -67,9 +62,13 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIa
return nil, status.Errorf(codes.Internal, "failed to marshal iam policy with error: %v", err.Error())
}
+ principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
+ if !ok {
+ return nil, status.Errorf(codes.Internal, "principal ID not found")
+ }
payloadStr := string(payloadBytes)
patch := &store.UpdatePolicyMessage{
- UpdaterID: userUID,
+ UpdaterID: principalID,
ResourceType: api.PolicyResourceTypeWorkspace,
Type: api.PolicyTypeIAM,
Payload: &payloadStr,
@@ -97,18 +96,3 @@ func containsActiveEndUser(users []*store.UserMessage) bool {
}
return false
}
-
-func (s *WorkspaceService) checkUserIsAdmin(ctx context.Context) (int, error) {
- user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
- if !ok {
- return 0, status.Errorf(codes.Internal, "failed to get user")
- }
- isAdmin, err := s.iamManager.CheckUserContainsWorkspaceRoles(ctx, user, api.WorkspaceAdmin)
- if err != nil {
- return 0, status.Errorf(codes.Internal, "failed to get check admin role")
- }
- if !isAdmin {
- return 0, status.Errorf(codes.PermissionDenied, "only admin can set workspace iam policy")
- }
- return user.ID, nil
-}
diff --git a/backend/component/iam/acl.yaml b/backend/component/iam/acl.yaml
index 108e52dc09..3cc6fd4600 100644
--- a/backend/component/iam/acl.yaml
+++ b/backend/component/iam/acl.yaml
@@ -112,6 +112,8 @@ roles:
- bb.userGroups.get
- bb.userGroups.list
- bb.userGroups.update
+ - bb.worksheets.manage
+ - bb.worksheets.get
- name: roles/workspaceDBA
permissions:
- bb.auditLogs.get
@@ -222,6 +224,8 @@ roles:
- bb.taskRuns.list
- bb.userGroups.get
- bb.userGroups.list
+ - bb.worksheets.manage
+ - bb.worksheets.get
- name: roles/workspaceMember
permissions:
- bb.environments.get
diff --git a/backend/component/iam/permission.go b/backend/component/iam/permission.go
index da99a83eb1..d1df9db782 100644
--- a/backend/component/iam/permission.go
+++ b/backend/component/iam/permission.go
@@ -60,6 +60,8 @@ const (
PermissionSettingsGet Permission = "bb.settings.get"
PermissionSettingsList Permission = "bb.settings.list"
PermissionSettingsSet Permission = "bb.settings.set"
+ PermissionWorksheetsGet Permission = "bb.worksheets.get"
+ PermissionWorksheetsManage Permission = "bb.worksheets.manage"
// Project-level permissions.
PermissionAuditLogsGet Permission = "bb.auditLogs.get"
@@ -176,6 +178,8 @@ var allWorkspacePermissions = []Permission{
PermissionSettingsGet,
PermissionSettingsList,
PermissionSettingsSet,
+ PermissionWorksheetsManage,
+ PermissionWorksheetsGet,
}
var allProjectPermissions = []Permission{
PermissionAuditLogsGet,
diff --git a/backend/component/iam/permission.yaml b/backend/component/iam/permission.yaml
index 1b3c7ef220..2873e6e1b1 100644
--- a/backend/component/iam/permission.yaml
+++ b/backend/component/iam/permission.yaml
@@ -104,3 +104,5 @@ permissions:
- bb.settings.get
- bb.settings.list
- bb.settings.set
+ - bb.worksheets.manage
+ - bb.worksheets.get
diff --git a/frontend/src/types/proto/v1/worksheet_service.ts b/frontend/src/types/proto/v1/worksheet_service.ts
index 0a3efff263..e1ec4559e7 100644
--- a/frontend/src/types/proto/v1/worksheet_service.ts
+++ b/frontend/src/types/proto/v1/worksheet_service.ts
@@ -1021,6 +1021,7 @@ export const WorksheetServiceDefinition = {
name: "WorksheetService",
fullName: "bytebase.v1.WorksheetService",
methods: {
+ /** Create a personal worksheet used in SQL Editor. */
createWorksheet: {
name: "CreateWorksheet",
requestType: CreateWorksheetRequest,
@@ -1066,6 +1067,13 @@ export const WorksheetServiceDefinition = {
},
},
},
+ /**
+ * Get a worksheet by name.
+ * The users can access this method if,
+ * - they are the creator of the worksheet;
+ * - they have bb.worksheets.get permission on the workspace;
+ * - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
+ */
getWorksheet: {
name: "GetWorksheet",
requestType: GetWorksheetRequest,
@@ -1109,6 +1117,11 @@ export const WorksheetServiceDefinition = {
},
},
},
+ /**
+ * Search for worksheets.
+ * This is used for finding my worksheets or worksheets shared by other people.
+ * The sheet accessibility is the same as GetWorksheet().
+ */
searchWorksheets: {
name: "SearchWorksheets",
requestType: SearchWorksheetsRequest,
@@ -1149,6 +1162,13 @@ export const WorksheetServiceDefinition = {
},
},
},
+ /**
+ * Update a worksheet.
+ * The users can access this method if,
+ * - they are the creator of the worksheet;
+ * - they have bb.worksheets.manage permission on the workspace;
+ * - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
+ */
updateWorksheet: {
name: "UpdateWorksheet",
requestType: UpdateWorksheetRequest,
@@ -1238,6 +1258,10 @@ export const WorksheetServiceDefinition = {
},
},
},
+ /**
+ * Update the organizer of a worksheet.
+ * The access is the same as UpdateWorksheet method.
+ */
updateWorksheetOrganizer: {
name: "UpdateWorksheetOrganizer",
requestType: UpdateWorksheetOrganizerRequest,
@@ -1342,6 +1366,10 @@ export const WorksheetServiceDefinition = {
},
},
},
+ /**
+ * Delete a worksheet.
+ * The access is the same as UpdateWorksheet method.
+ */
deleteWorksheet: {
name: "DeleteWorksheet",
requestType: DeleteWorksheetRequest,
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index cd7a15164c..2f31c42060 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -7749,6 +7749,7 @@ paths:
post:
tags:
- WorksheetService
+ description: Create a personal worksheet used in SQL Editor.
operationId: WorksheetService_CreateWorksheet
requestBody:
content:
@@ -7773,6 +7774,12 @@ paths:
get:
tags:
- WorksheetService
+ description: |-
+ Get a worksheet by name.
+ The users can access this method if,
+ - they are the creator of the worksheet;
+ - they have bb.worksheets.get permission on the workspace;
+ - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
operationId: WorksheetService_GetWorksheet
parameters:
- name: worksheet
@@ -7797,6 +7804,9 @@ paths:
delete:
tags:
- WorksheetService
+ description: |-
+ Delete a worksheet.
+ The access is the same as UpdateWorksheet method.
operationId: WorksheetService_DeleteWorksheet
parameters:
- name: worksheet
@@ -7818,6 +7828,12 @@ paths:
patch:
tags:
- WorksheetService
+ description: |-
+ Update a worksheet.
+ The users can access this method if,
+ - they are the creator of the worksheet;
+ - they have bb.worksheets.manage permission on the workspace;
+ - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
operationId: WorksheetService_UpdateWorksheet
parameters:
- name: worksheet
@@ -7863,6 +7879,9 @@ paths:
patch:
tags:
- WorksheetService
+ description: |-
+ Update the organizer of a worksheet.
+ The access is the same as UpdateWorksheet method.
operationId: WorksheetService_UpdateWorksheetOrganizer
parameters:
- name: worksheet
@@ -7904,6 +7923,10 @@ paths:
get:
tags:
- WorksheetService
+ description: |-
+ Search for worksheets.
+ This is used for finding my worksheets or worksheets shared by other people.
+ The sheet accessibility is the same as GetWorksheet().
operationId: WorksheetService_SearchWorksheets
parameters:
- name: filter
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 2fc77c9ed0..557ad7e8fa 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -11250,12 +11250,12 @@ The worksheet's `name` field is used to identify the worksheet to update. Fo
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
-| CreateWorksheet | [CreateWorksheetRequest](#bytebase-v1-CreateWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | |
-| GetWorksheet | [GetWorksheetRequest](#bytebase-v1-GetWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | |
-| SearchWorksheets | [SearchWorksheetsRequest](#bytebase-v1-SearchWorksheetsRequest) | [SearchWorksheetsResponse](#bytebase-v1-SearchWorksheetsResponse) | |
-| UpdateWorksheet | [UpdateWorksheetRequest](#bytebase-v1-UpdateWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | |
-| UpdateWorksheetOrganizer | [UpdateWorksheetOrganizerRequest](#bytebase-v1-UpdateWorksheetOrganizerRequest) | [WorksheetOrganizer](#bytebase-v1-WorksheetOrganizer) | |
-| DeleteWorksheet | [DeleteWorksheetRequest](#bytebase-v1-DeleteWorksheetRequest) | [.google.protobuf.Empty](#google-protobuf-Empty) | |
+| CreateWorksheet | [CreateWorksheetRequest](#bytebase-v1-CreateWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | Create a personal worksheet used in SQL Editor. |
+| GetWorksheet | [GetWorksheetRequest](#bytebase-v1-GetWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | Get a worksheet by name. The users can access this method if, - they are the creator of the worksheet; - they have bb.worksheets.get permission on the workspace; - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project. |
+| SearchWorksheets | [SearchWorksheetsRequest](#bytebase-v1-SearchWorksheetsRequest) | [SearchWorksheetsResponse](#bytebase-v1-SearchWorksheetsResponse) | Search for worksheets. This is used for finding my worksheets or worksheets shared by other people. The sheet accessibility is the same as GetWorksheet(). |
+| UpdateWorksheet | [UpdateWorksheetRequest](#bytebase-v1-UpdateWorksheetRequest) | [Worksheet](#bytebase-v1-Worksheet) | Update a worksheet. The users can access this method if, - they are the creator of the worksheet; - they have bb.worksheets.manage permission on the workspace; - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project. |
+| UpdateWorksheetOrganizer | [UpdateWorksheetOrganizerRequest](#bytebase-v1-UpdateWorksheetOrganizerRequest) | [WorksheetOrganizer](#bytebase-v1-WorksheetOrganizer) | Update the organizer of a worksheet. The access is the same as UpdateWorksheet method. |
+| DeleteWorksheet | [DeleteWorksheetRequest](#bytebase-v1-DeleteWorksheetRequest) | [.google.protobuf.Empty](#google-protobuf-Empty) | Delete a worksheet. The access is the same as UpdateWorksheet method. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 2db893b96e..85eef022af 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -30695,42 +30695,54 @@ Format: worksheets/{worksheet} </p></td>
<td>CreateWorksheet</td>
<td><a href="#bytebase.v1.CreateWorksheetRequest">CreateWorksheetRequest</a></td>
<td><a href="#bytebase.v1.Worksheet">Worksheet</a></td>
- <td><p></p></td>
+ <td><p>Create a personal worksheet used in SQL Editor.</p></td>
</tr>
<tr>
<td>GetWorksheet</td>
<td><a href="#bytebase.v1.GetWorksheetRequest">GetWorksheetRequest</a></td>
<td><a href="#bytebase.v1.Worksheet">Worksheet</a></td>
- <td><p></p></td>
+ <td><p>Get a worksheet by name.
+The users can access this method if,
+- they are the creator of the worksheet;
+- they have bb.worksheets.get permission on the workspace;
+- the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.</p></td>
</tr>
<tr>
<td>SearchWorksheets</td>
<td><a href="#bytebase.v1.SearchWorksheetsRequest">SearchWorksheetsRequest</a></td>
<td><a href="#bytebase.v1.SearchWorksheetsResponse">SearchWorksheetsResponse</a></td>
- <td><p></p></td>
+ <td><p>Search for worksheets.
+This is used for finding my worksheets or worksheets shared by other people.
+The sheet accessibility is the same as GetWorksheet().</p></td>
</tr>
<tr>
<td>UpdateWorksheet</td>
<td><a href="#bytebase.v1.UpdateWorksheetRequest">UpdateWorksheetRequest</a></td>
<td><a href="#bytebase.v1.Worksheet">Worksheet</a></td>
- <td><p></p></td>
+ <td><p>Update a worksheet.
+The users can access this method if,
+- they are the creator of the worksheet;
+- they have bb.worksheets.manage permission on the workspace;
+- the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.</p></td>
</tr>
<tr>
<td>UpdateWorksheetOrganizer</td>
<td><a href="#bytebase.v1.UpdateWorksheetOrganizerRequest">UpdateWorksheetOrganizerRequest</a></td>
<td><a href="#bytebase.v1.WorksheetOrganizer">WorksheetOrganizer</a></td>
- <td><p></p></td>
+ <td><p>Update the organizer of a worksheet.
+The access is the same as UpdateWorksheet method.</p></td>
</tr>
<tr>
<td>DeleteWorksheet</td>
<td><a href="#bytebase.v1.DeleteWorksheetRequest">DeleteWorksheetRequest</a></td>
<td><a href="#google.protobuf.Empty">.google.protobuf.Empty</a></td>
- <td><p></p></td>
+ <td><p>Delete a worksheet.
+The access is the same as UpdateWorksheet method.</p></td>
</tr>
</tbody>
diff --git a/proto/generated-go/v1/worksheet_service_grpc.pb.go b/proto/generated-go/v1/worksheet_service_grpc.pb.go
index b9fde27355..5f2c32bef4 100644
--- a/proto/generated-go/v1/worksheet_service_grpc.pb.go
+++ b/proto/generated-go/v1/worksheet_service_grpc.pb.go
@@ -32,11 +32,29 @@ const (
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type WorksheetServiceClient interface {
+ // Create a personal worksheet used in SQL Editor.
CreateWorksheet(ctx context.Context, in *CreateWorksheetRequest, opts ...grpc.CallOption) (*Worksheet, error)
+ // Get a worksheet by name.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.get permission on the workspace;
+ // - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
GetWorksheet(ctx context.Context, in *GetWorksheetRequest, opts ...grpc.CallOption) (*Worksheet, error)
+ // Search for worksheets.
+ // This is used for finding my worksheets or worksheets shared by other people.
+ // The sheet accessibility is the same as GetWorksheet().
SearchWorksheets(ctx context.Context, in *SearchWorksheetsRequest, opts ...grpc.CallOption) (*SearchWorksheetsResponse, error)
+ // Update a worksheet.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.manage permission on the workspace;
+ // - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
UpdateWorksheet(ctx context.Context, in *UpdateWorksheetRequest, opts ...grpc.CallOption) (*Worksheet, error)
+ // Update the organizer of a worksheet.
+ // The access is the same as UpdateWorksheet method.
UpdateWorksheetOrganizer(ctx context.Context, in *UpdateWorksheetOrganizerRequest, opts ...grpc.CallOption) (*WorksheetOrganizer, error)
+ // Delete a worksheet.
+ // The access is the same as UpdateWorksheet method.
DeleteWorksheet(ctx context.Context, in *DeleteWorksheetRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
@@ -112,11 +130,29 @@ func (c *worksheetServiceClient) DeleteWorksheet(ctx context.Context, in *Delete
// All implementations must embed UnimplementedWorksheetServiceServer
// for forward compatibility
type WorksheetServiceServer interface {
+ // Create a personal worksheet used in SQL Editor.
CreateWorksheet(context.Context, *CreateWorksheetRequest) (*Worksheet, error)
+ // Get a worksheet by name.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.get permission on the workspace;
+ // - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
GetWorksheet(context.Context, *GetWorksheetRequest) (*Worksheet, error)
+ // Search for worksheets.
+ // This is used for finding my worksheets or worksheets shared by other people.
+ // The sheet accessibility is the same as GetWorksheet().
SearchWorksheets(context.Context, *SearchWorksheetsRequest) (*SearchWorksheetsResponse, error)
+ // Update a worksheet.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.manage permission on the workspace;
+ // - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
UpdateWorksheet(context.Context, *UpdateWorksheetRequest) (*Worksheet, error)
+ // Update the organizer of a worksheet.
+ // The access is the same as UpdateWorksheet method.
UpdateWorksheetOrganizer(context.Context, *UpdateWorksheetOrganizerRequest) (*WorksheetOrganizer, error)
+ // Delete a worksheet.
+ // The access is the same as UpdateWorksheet method.
DeleteWorksheet(context.Context, *DeleteWorksheetRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedWorksheetServiceServer()
}
diff --git a/proto/v1/worksheet_service.proto b/proto/v1/worksheet_service.proto
index a15eb43876..d76c0af3a4 100644
--- a/proto/v1/worksheet_service.proto
+++ b/proto/v1/worksheet_service.proto
@@ -13,6 +13,7 @@ import "v1/annotation.proto";
option go_package = "generated-go/v1";
service WorksheetService {
+ // Create a personal worksheet used in SQL Editor.
rpc CreateWorksheet(CreateWorksheetRequest) returns (Worksheet) {
option (google.api.http) = {
post: "/v1/worksheets"
@@ -22,17 +23,30 @@ service WorksheetService {
option (bytebase.v1.auth_method) = CUSTOM;
}
+ // Get a worksheet by name.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.get permission on the workspace;
+ // - the sheet is shared with them with PROJECT_READ and PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
rpc GetWorksheet(GetWorksheetRequest) returns (Worksheet) {
option (google.api.http) = {get: "/v1/{name=worksheets/*}"};
option (google.api.method_signature) = "name";
option (bytebase.v1.auth_method) = CUSTOM;
}
+ // Search for worksheets.
+ // This is used for finding my worksheets or worksheets shared by other people.
+ // The sheet accessibility is the same as GetWorksheet().
rpc SearchWorksheets(SearchWorksheetsRequest) returns (SearchWorksheetsResponse) {
option (google.api.http) = {get: "/v1/worksheets:search"};
option (bytebase.v1.auth_method) = CUSTOM;
}
+ // Update a worksheet.
+ // The users can access this method if,
+ // - they are the creator of the worksheet;
+ // - they have bb.worksheets.manage permission on the workspace;
+ // - the sheet is shared with them with PROJECT_WRITE visibility, and they have bb.projects.get permission on the project.
rpc UpdateWorksheet(UpdateWorksheetRequest) returns (Worksheet) {
option (google.api.http) = {
patch: "/v1/{worksheet.name=worksheets/*}"
@@ -42,6 +56,8 @@ service WorksheetService {
option (bytebase.v1.auth_method) = CUSTOM;
}
+ // Update the organizer of a worksheet.
+ // The access is the same as UpdateWorksheet method.
rpc UpdateWorksheetOrganizer(UpdateWorksheetOrganizerRequest) returns (WorksheetOrganizer) {
option (google.api.http) = {
patch: "/v1/{organizer.worksheet=worksheets/*}/organizer"
@@ -51,6 +67,8 @@ service WorksheetService {
option (bytebase.v1.auth_method) = CUSTOM;
}
+ // Delete a worksheet.
+ // The access is the same as UpdateWorksheet method.
rpc DeleteWorksheet(DeleteWorksheetRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {delete: "/v1/{name=worksheets/*}"};
option (google.api.method_signature) = "name";