Skip to content

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

chore: unify role const and remove unused code (#18966)

ecmadao3641269a3dcc
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index 0c71c7f452..47c4313175 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -1087,7 +1087,7 @@ func validateBindings(bindings []*v1pb.Binding, roles []*store.RoleMessage, maxi
return err
}
- if binding.Role != fmt.Sprintf("roles/%s", common.ProjectOwner) && maximumRoleExpiration != nil {
+ if binding.Role != fmt.Sprintf("roles/%s", store.ProjectOwnerRole) && maximumRoleExpiration != nil {
// Only validate when maximumRoleExpiration is set and the role is not project owner.
if err := validateExpirationInExpression(binding.GetCondition().GetExpression(), maximumRoleExpiration); err != nil {
return connect.NewError(connect.CodeInvalidArgument, errors.Wrapf(err, "failed to validate expiration for binding %v", binding.Role))
diff --git a/backend/api/v1/user_service.go b/backend/api/v1/user_service.go
index 9efe0fab09..90fceecaef 100644
--- a/backend/api/v1/user_service.go
+++ b/backend/api/v1/user_service.go
@@ -307,7 +307,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *connect.Request[v
// The first end user should be workspace admin.
updateRole := &store.PatchIamPolicyMessage{
Member: common.FormatUserEmail(user.Email),
- Roles: []string{common.FormatRole(common.WorkspaceAdmin)},
+ Roles: []string{common.FormatRole(store.WorkspaceAdminRole)},
}
if _, err := s.store.PatchWorkspaceIamPolicy(ctx, updateRole); err != nil {
return nil, connect.NewError(connect.CodeInternal, err)
@@ -614,7 +614,7 @@ func (s *UserService) getActiveUserCount(ctx context.Context) (int, error) {
}
func (s *UserService) hasExtraWorkspaceAdmin(ctx context.Context, policy *storepb.IamPolicy, user *store.UserMessage) (bool, error) {
- workspaceAdminRole := common.FormatRole(common.WorkspaceAdmin)
+ workspaceAdminRole := common.FormatRole(store.WorkspaceAdminRole)
userMember := common.FormatUserEmail(user.Email)
for _, binding := range policy.GetBindings() {
@@ -946,5 +946,5 @@ func isUserWorkspaceAdmin(ctx context.Context, stores *store.Store, user *store.
return false, err
}
roles := utils.GetUserFormattedRolesMap(ctx, stores, user, workspacePolicy.Policy)
- return roles[common.FormatRole(common.WorkspaceAdmin)], nil
+ return roles[common.FormatRole(store.WorkspaceAdminRole)], nil
}
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 1b71e62024..670d07fba4 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -64,7 +64,7 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, req *connect.Reques
if err != nil {
return nil, err
}
- users := utils.GetUsersByRoleInIAMPolicy(ctx, s.store, common.WorkspaceAdmin, iamPolicy)
+ users := utils.GetUsersByRoleInIAMPolicy(ctx, s.store, store.WorkspaceAdminRole, iamPolicy)
if !containsActiveEndUser(users) {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("workspace must have at least one admin"))
}
diff --git a/backend/common/cel_attributes.go b/backend/common/cel_attributes.go
index 65b653376a..d35f690b01 100644
--- a/backend/common/cel_attributes.go
+++ b/backend/common/cel_attributes.go
@@ -54,11 +54,3 @@ const (
// CELAttributeRiskLevel is the risk level of the issue (LOW, MODERATE, HIGH).
CELAttributeRiskLevel = "risk.level"
)
-
-// CEL attribute names for approval scope (deprecated, kept for backward compatibility).
-const (
- // CELAttributeLevel is the risk level (deprecated).
- CELAttributeLevel = "level"
- // CELAttributeSource is the risk source (deprecated).
- CELAttributeSource = "source"
-)
diff --git a/backend/common/const.go b/backend/common/const.go
index 42ba53e087..300aa05c13 100644
--- a/backend/common/const.go
+++ b/backend/common/const.go
@@ -1,12 +1,6 @@
//nolint:revive
package common
-const (
- WorkspaceAdmin = "workspaceAdmin"
- WorkspaceMember = "workspaceMember"
- ProjectOwner = "projectOwner"
-)
-
const (
// SystemBotID is the ID of the system robot.
SystemBotID = 1
@@ -17,9 +11,6 @@ const (
// AllUsers is the email of the pseudo allUsers account.
AllUsers = "allUsers"
- // PrincipalIDForFirstUser is the principal id for the first user in workspace.
- PrincipalIDForFirstUser = 101
-
// ServiceAccountAccessKeyPrefix is the prefix for service account access key.
ServiceAccountAccessKeyPrefix = "bbs_"
diff --git a/backend/common/util.go b/backend/common/util.go
index 4c530e19d0..f942a48860 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -30,12 +30,6 @@ const (
// MaximumAdvicePerStatus is the maximum number of advice that can be returned per status.
MaximumAdvicePerStatus = 50
MaximumLintExplainSize = 10
-
- // MinimumCompletedPlanCheckRun is the minimum number required to generate approval flow.
- MinimumCompletedPlanCheckRun = 5
-
- // ExternalURLPlaceholder is the docs link to configure --external-url.
- ExternalURLPlaceholder = "https://docs.bytebase.com/get-started/self-host/external-url"
)
var letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
diff --git a/backend/store/project.go b/backend/store/project.go
index 268a86e7cb..c47b51851d 100644
--- a/backend/store/project.go
+++ b/backend/store/project.go
@@ -209,7 +209,7 @@ func (s *Store) CreateProject(ctx context.Context, create *ProjectMessage, creat
policy := &storepb.IamPolicy{
Bindings: []*storepb.Binding{
{
- Role: common.FormatRole(common.ProjectOwner),
+ Role: common.FormatRole(ProjectOwnerRole),
Members: []string{
common.FormatUserEmail(creator.Email),
},