Skip to content

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

refactor: remove roles in user api (#12856)

ecmadao1f632777b40b
diff --git a/backend/api/v1/acl_config.go b/backend/api/v1/acl_config.go
index 8737d7c932..e271a8444e 100644
--- a/backend/api/v1/acl_config.go
+++ b/backend/api/v1/acl_config.go
@@ -149,8 +149,9 @@ var methodPermissionMap = map[string]iam.Permission{
v1pb.OrgPolicyService_DeletePolicy_FullMethodName: iam.PermissionPoliciesDelete,
// TODO(p0ny): ensure the permission.
- v1pb.WorkspaceService_GetIamPolicy_FullMethodName: iam.PermissionPoliciesGet,
- v1pb.WorkspaceService_SetIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
+ v1pb.WorkspaceService_GetIamPolicy_FullMethodName: iam.PermissionPoliciesGet,
+ v1pb.WorkspaceService_SetIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
+ v1pb.WorkspaceService_PatchIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
v1pb.BranchService_GetBranch_FullMethodName: iam.PermissionBranchesGet,
v1pb.BranchService_ListBranches_FullMethodName: iam.PermissionBranchesList,
diff --git a/backend/api/v1/audit.go b/backend/api/v1/audit.go
index f507b54521..cacb1895ac 100644
--- a/backend/api/v1/audit.go
+++ b/backend/api/v1/audit.go
@@ -344,7 +344,6 @@ func redactUser(r *v1pb.User) *v1pb.User {
Email: r.Email,
Title: r.Title,
UserType: r.UserType,
- Roles: r.Roles,
}
}
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index e7458fb738..806692eebf 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -96,7 +96,7 @@ func (s *AuthService) GetUser(ctx context.Context, request *v1pb.GetUserRequest)
if user == nil {
return nil, status.Errorf(codes.NotFound, "user %d not found", userID)
}
- return s.convertToUser(ctx, user)
+ return convertToUser(user), nil
}
// ListUsers lists all users.
@@ -107,11 +107,7 @@ func (s *AuthService) ListUsers(ctx context.Context, request *v1pb.ListUsersRequ
}
response := &v1pb.ListUsersResponse{}
for _, user := range users {
- v1User, err := s.convertToUser(ctx, user)
- if err != nil {
- return nil, err
- }
- response.Users = append(response.Users, v1User)
+ response.Users = append(response.Users, convertToUser(user))
}
return response, nil
}
@@ -212,28 +208,16 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
return nil, status.Errorf(codes.Internal, "failed to create user, error: %v", err)
}
- // TODO(ed): deprecate this.
- updateRole := &store.PatchIamPolicyMessage{
- Member: common.FormatUserUID(user.ID),
- UpdaterUID: creatorUID,
- }
-
if firstEndUser {
// The first end user should be workspace admin.
- updateRole.Roles = []string{common.FormatRole(api.WorkspaceAdmin.String())}
- } else {
- // Otherwise only workspace admin can set roles while creating the user.
- rolePtr := ctx.Value(common.RoleContextKey)
- if rolePtr != nil && rolePtr.(api.Role) == api.WorkspaceAdmin {
- // TODO(ed):
- updateRole.Roles = request.User.Roles
- } else if len(request.User.Roles) > 0 {
- return nil, status.Errorf(codes.PermissionDenied, "only workspace owner can create user with multiple roles")
+ updateRole := &store.PatchIamPolicyMessage{
+ Member: common.FormatUserUID(user.ID),
+ UpdaterUID: creatorUID,
+ Roles: []string{common.FormatRole(api.WorkspaceAdmin.String())},
+ }
+ if _, err := s.store.PatchWorkspaceIamPolicy(ctx, updateRole); err != nil {
+ return nil, err
}
- }
-
- if _, err := s.store.PatchWorkspaceIamPolicy(ctx, updateRole); err != nil {
- return nil, err
}
if err := s.postCreateUser(ctx, user, firstEndUser); err != nil {
@@ -254,10 +238,7 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
},
})
- userResponse, err := s.convertToUser(ctx, user)
- if err != nil {
- return nil, err
- }
+ userResponse := convertToUser(user)
if request.User.UserType == v1pb.UserType_SERVICE_ACCOUNT {
userResponse.ServiceKey = password
}
@@ -342,30 +323,6 @@ func (s *AuthService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
}
password := fmt.Sprintf("%s%s", api.ServiceAccountAccessKeyPrefix, val)
passwordPatch = &password
- case "roles":
- // TODO(ed): deprecate roles field.
- if role != api.WorkspaceAdmin {
- return nil, status.Errorf(codes.PermissionDenied, "only workspace admin can update roles")
- }
- // Check if the user is the only workspace admin.
- isAdmin, err := s.iamManager.CheckUserContainsWorkspaceRoles(ctx, user, api.WorkspaceAdmin)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to check admin role with error: %v", err.Error())
- }
- if isAdmin && !slices.Contains(request.User.Roles, common.FormatRole(api.WorkspaceAdmin.String())) {
- workspaceAdmin, userType := api.WorkspaceAdmin, api.EndUser
- adminUser, err := s.store.ListUsers(ctx, &store.FindUserMessage{
- Role: &workspaceAdmin,
- Type: &userType,
- })
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to find workspace admin, error: %v", err)
- }
- if len(adminUser) == 1 && adminUser[0].ID == userID {
- return nil, status.Errorf(codes.InvalidArgument, "workspace must have at least one admin")
- }
- }
- patch.Roles = &request.User.Roles
case "mfa_enabled":
if request.User.MfaEnabled {
if user.MFAConfig.TempOtpSecret == "" || len(user.MFAConfig.TempRecoveryCodes) == 0 {
@@ -450,16 +407,7 @@ func (s *AuthService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
return nil, status.Errorf(codes.Internal, "failed to update user, error: %v", err)
}
- // TODO(ed):
- if patch.Roles != nil {
- s.iamManager.RemoveCache(user.ID)
- }
-
- userResponse, err := s.convertToUser(ctx, user)
- if err != nil {
- return nil, err
- }
-
+ userResponse := convertToUser(user)
if request.User.UserType == v1pb.UserType_SERVICE_ACCOUNT && passwordPatch != nil {
userResponse.ServiceKey = *passwordPatch
}
@@ -556,10 +504,10 @@ func (s *AuthService) UndeleteUser(ctx context.Context, request *v1pb.UndeleteUs
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
- return s.convertToUser(ctx, user)
+ return convertToUser(user), nil
}
-func (s *AuthService) convertToUser(ctx context.Context, user *store.UserMessage) (*v1pb.User, error) {
+func convertToUser(user *store.UserMessage) *v1pb.User {
userType := v1pb.UserType_USER_TYPE_UNSPECIFIED
switch user.Type {
case api.EndUser:
@@ -579,17 +527,12 @@ func (s *AuthService) convertToUser(ctx context.Context, user *store.UserMessage
UserType: userType,
}
- workspaceRoles, err := s.iamManager.GetWorkspaceRoles(ctx, user)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get workspace roles for user with error: %v", err.Error())
- }
- convertedUser.Roles = workspaceRoles
if user.MFAConfig != nil {
convertedUser.MfaEnabled = user.MFAConfig.OtpSecret != ""
convertedUser.MfaSecret = user.MFAConfig.TempOtpSecret
convertedUser.RecoveryCodes = user.MFAConfig.TempRecoveryCodes
}
- return convertedUser, nil
+ return convertedUser
}
func convertToPrincipalType(userType v1pb.UserType) (api.PrincipalType, error) {
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 8789d3e5be..4a42930953 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -83,6 +83,7 @@ func (s *WorkspaceService) PatchIamPolicy(ctx context.Context, request *v1pb.Pat
return nil, err
}
+ // TODO(ed): Check if the user is the only workspace admin.
storeMember, err := convertToStoreIamPolicyMember(ctx, s.store, request.Member)
if err != nil {
return nil, err
@@ -98,6 +99,8 @@ func (s *WorkspaceService) PatchIamPolicy(ctx context.Context, request *v1pb.Pat
return nil, status.Errorf(codes.Internal, "failed to patch iam policy with error: %v", err.Error())
}
+ s.iamManager.RemoveCache(userUID)
+
return convertToV1IamPolicy(ctx, s.store, policy)
}
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 2f73544e87..83438af477 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -39,11 +39,9 @@ type UpdateUserMessage struct {
Email *string
Name *string
PasswordHash *string
- // TODO(ed): remove roles in user patch.
- Roles *[]string
- Delete *bool
- MFAConfig *storepb.MFAConfig
- Phone *string
+ Delete *bool
+ MFAConfig *storepb.MFAConfig
+ Phone *string
}
// UserMessage is the message for an user.
@@ -354,17 +352,6 @@ func (s *Store) UpdateUser(ctx context.Context, currentUser *UserMessage, patch
return nil, err
}
- // TODO(ed): remove in patch
- if v := patch.Roles; v != nil {
- if _, err := s.PatchWorkspaceIamPolicy(ctx, &PatchIamPolicyMessage{
- Member: common.FormatUserUID(currentUser.ID),
- Roles: *v,
- UpdaterUID: updaterID,
- }); err != nil {
- return nil, errors.Wrapf(err, "failed to update user roles")
- }
- }
-
s.userEmailCache.Remove(currentUser.Email)
s.userIDCache.Remove(currentUser.ID)
user, err := s.GetUserByID(ctx, currentUser.ID)
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 66de7640da..0629ace8a0 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -52,6 +52,7 @@ import OverlayStackManager from "./components/misc/OverlayStackManager.vue";
import { t } from "./plugins/i18n";
import { AUTH_SIGNIN_MODULE } from "./router/auth";
import {
+ useWorkspaceV1Store,
useActuatorV1Store,
useAuthStore,
useNotificationStore,
@@ -84,7 +85,8 @@ onMounted(async () => {
await useSubscriptionV1Store().fetchFeatureMatrix();
};
const restoreUser = async () => {
- await useAuthStore().restoreUser();
+ await useWorkspaceV1Store().fetchIamPolicy();
+ await authStore.restoreUser();
};
const initBasicModules = async () => {
await Promise.all([
diff --git a/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
index 513455b885..b0016df678 100644
--- a/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
+++ b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
@@ -4,7 +4,7 @@
class="flex flex-row gap-x-1 mr-1 justify-start items-center border border-gray-200 rounded-md p-0.5 px-2"
>
<UserAvatar size="TINY" :user="updater" />
- <span>{{ updater.title }}</span>
+ <span>{{ updater?.title }}</span>
</div>
<span>{{ updateTimeStr }}</span>
</div>
@@ -15,7 +15,6 @@ import dayjs from "dayjs";
import { computed } from "vue";
import { useUserStore } from "@/store";
import { getUserEmailFromIdentifier } from "@/store/modules/v1/common";
-import type { User } from "@/types/proto/v1/auth_service";
import type { Branch } from "@/types/proto/v1/branch_service";
const props = defineProps<{
@@ -26,7 +25,7 @@ const userStore = useUserStore();
const updater = computed(() => {
const email = getUserEmailFromIdentifier(props.branch.updater);
- return userStore.getUserByEmail(email) as User;
+ return userStore.getUserByEmail(email);
});
const updateTimeStr = computed(() => {
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/rollout/RolloutActionButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/rollout/RolloutActionButton.vue
index 70815b713b..904b20a59b 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/rollout/RolloutActionButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/rollout/RolloutActionButton.vue
@@ -33,6 +33,7 @@ import type { ErrorItem } from "@/components/misc/ErrorList.vue";
import ErrorList from "@/components/misc/ErrorList.vue";
import { ContextMenuButton } from "@/components/v2";
import { useCurrentUserV1, useUserStore } from "@/store";
+import { userNamePrefix, roleNamePrefix } from "@/store/modules/v1/common";
import { displayRoleTitle, extractUserResourceName } from "@/utils";
import type { RolloutAction, RolloutButtonAction } from "./common";
@@ -64,13 +65,13 @@ const errors = asyncComputed(async () => {
const { releasers } = issue.value;
for (let i = 0; i < releasers.length; i++) {
const roleOrUser = releasers[i];
- if (roleOrUser.startsWith("roles/")) {
+ if (roleOrUser.startsWith(roleNamePrefix)) {
errors.push({
error: displayRoleTitle(roleOrUser),
indent: 1,
});
}
- if (roleOrUser.startsWith("users/")) {
+ if (roleOrUser.startsWith(userNamePrefix)) {
const email = extractUserResourceName(roleOrUser);
const user = useUserStore().getUserByEmail(email);
if (user) {
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
index a40448aa5c..3c29e274bf 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
@@ -47,14 +47,14 @@ import { updateIssueSubscribers, useIssueContext } from "@/components/IssueV1";
import UserAvatar from "@/components/User/UserAvatar.vue";
import { useUserStore } from "@/store";
import { unknownUser } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import { extractUserResourceName } from "@/utils";
import SubscriberListItem from "./SubscriberListItem.vue";
type UserSelectOption = SelectOption & {
- user: User;
+ user: ComposedUser;
value: string;
};
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vue
index 9ad0ddf955..9955ee89fb 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vue
@@ -10,9 +10,9 @@
<script setup lang="ts">
import UserAvatar from "@/components/User/UserAvatar.vue";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
defineProps<{
- user: User;
+ user: ComposedUser;
}>();
</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
index 17ef609e55..bccef7293e 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
@@ -62,7 +62,9 @@
:step="step"
class="inline"
>
- <template #title="{ approver }: { approver: User | undefined }">
+ <template
+ #title="{ approver }: { approver: ComposedUser | undefined }"
+ >
<span>{{ approver?.title }}</span>
</template>
</Approver>
@@ -80,8 +82,7 @@ import {
NPopover,
NPerformantEllipsis,
} from "naive-ui";
-import type { WrappedReviewStep } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { WrappedReviewStep, ComposedUser } from "@/types";
import type { ApprovalStep } from "@/types/proto/v1/issue_service";
import { approvalNodeText } from "@/utils";
import Approver from "./Approver.vue";
diff --git a/frontend/src/components/IssueV1/logic/action/issue.ts b/frontend/src/components/IssueV1/logic/action/issue.ts
index 6eb17b4001..0ef5ad637d 100644
--- a/frontend/src/components/IssueV1/logic/action/issue.ts
+++ b/frontend/src/components/IssueV1/logic/action/issue.ts
@@ -1,7 +1,6 @@
import type { ButtonProps } from "naive-ui";
import { t } from "@/plugins/i18n";
-import type { ComposedIssue } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedIssue, ComposedUser } from "@/types";
import {
IssueStatus,
Issue_Approver_Status,
@@ -96,7 +95,7 @@ export const issueStatusActionButtonProps = (
export const allowUserToApplyIssueStatusAction = (
issue: ComposedIssue,
- user: User,
+ user: ComposedUser,
action: IssueStatusAction
): [boolean /** ok */, string /** reason */] => {
// User does not have permission to update the issue and is not the creator of the issue.
diff --git a/frontend/src/components/IssueV1/logic/action/review.ts b/frontend/src/components/IssueV1/logic/action/review.ts
index 6f17b15a69..d5a4d6e601 100644
--- a/frontend/src/components/IssueV1/logic/action/review.ts
+++ b/frontend/src/components/IssueV1/logic/action/review.ts
@@ -1,8 +1,7 @@
import type { ButtonProps } from "naive-ui";
import { t } from "@/plugins/i18n";
import { candidatesOfApprovalStepV1 } from "@/store";
-import type { ComposedIssue } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedIssue, ComposedUser } from "@/types";
import {
IssueStatus,
Issue_Approver_Status,
@@ -58,7 +57,7 @@ export const issueReviewActionButtonProps = (
export const allowUserToApplyReviewAction = (
issue: ComposedIssue,
context: ReviewContext,
- user: User,
+ user: ComposedUser,
action: IssueReviewAction
) => {
const { ready, done, flow } = context;
diff --git a/frontend/src/components/IssueV1/logic/action/task.ts b/frontend/src/components/IssueV1/logic/action/task.ts
index 0685525681..fc3d8e1e35 100644
--- a/frontend/src/components/IssueV1/logic/action/task.ts
+++ b/frontend/src/components/IssueV1/logic/action/task.ts
@@ -2,9 +2,8 @@ import { head } from "lodash-es";
import type { ButtonProps } from "naive-ui";
import { t } from "@/plugins/i18n";
import { userNamePrefix } from "@/store/modules/v1/common";
-import type { ComposedIssue } from "@/types";
+import type { ComposedIssue, ComposedUser } from "@/types";
import { PresetRoleType } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
import type { Task } from "@/types/proto/v1/rollout_service";
import { Task_Status, Task_Type } from "@/types/proto/v1/rollout_service";
@@ -133,9 +132,9 @@ export const taskRolloutActionButtonProps = (
export const allowUserToApplyTaskRolloutAction = (
issue: ComposedIssue,
task: Task,
- user: User,
+ user: ComposedUser,
action: TaskRolloutAction,
- releaserCandidates: User[]
+ releaserCandidates: ComposedUser[]
) => {
// For data export issues, only the creator can take actions.
if (issue.type === Issue_Type.DATABASE_DATA_EXPORT) {
diff --git a/frontend/src/components/IssueV1/logic/context.ts b/frontend/src/components/IssueV1/logic/context.ts
index eca0107eb6..bdc238054b 100644
--- a/frontend/src/components/IssueV1/logic/context.ts
+++ b/frontend/src/components/IssueV1/logic/context.ts
@@ -3,8 +3,7 @@ import type { useDialog } from "naive-ui";
import { v4 as uuidv4 } from "uuid";
import type { InjectionKey, Ref } from "vue";
import { inject, provide } from "vue";
-import type { ComposedIssue, ReviewFlow } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedIssue, ComposedUser, ReviewFlow } from "@/types";
import type { Issue_Approver_Status } from "@/types/proto/v1/issue_service";
import type { Plan_Spec } from "@/types/proto/v1/plan_service";
import type { Stage, Task } from "@/types/proto/v1/rollout_service";
@@ -48,7 +47,7 @@ export type IssueContext = {
phase: Ref<IssuePhase>;
isGhostMode: Ref<boolean>;
isLegacyIssue: Ref<boolean>;
- releaserCandidates: Ref<User[]>;
+ releaserCandidates: Ref<ComposedUser[]>;
// review status
reviewContext: ReviewContext;
diff --git a/frontend/src/components/IssueV1/logic/releaser.ts b/frontend/src/components/IssueV1/logic/releaser.ts
index 826414f629..b82ba87c13 100644
--- a/frontend/src/components/IssueV1/logic/releaser.ts
+++ b/frontend/src/components/IssueV1/logic/releaser.ts
@@ -1,19 +1,19 @@
import { uniqBy } from "lodash-es";
import { useUserStore } from "@/store";
-import type { ComposedIssue } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
-import { extractUserResourceName, memberListInProjectV1 } from "@/utils";
+import { userNamePrefix, roleNamePrefix } from "@/store/modules/v1/common";
+import type { ComposedIssue, ComposedUser } from "@/types";
+import { extractUserResourceName, memberListInIAM } from "@/utils";
export const releaserCandidatesForIssue = (issue: ComposedIssue) => {
- const users: User[] = [];
+ const users: ComposedUser[] = [];
const project = issue.projectEntity;
- const projectMembers = memberListInProjectV1(project.iamPolicy);
+ const projectMembers = memberListInIAM(project.iamPolicy);
const workspaceMembers = useUserStore().userList;
for (let i = 0; i < issue.releasers.length; i++) {
const releaserRole = issue.releasers[i];
- if (releaserRole.startsWith("roles/")) {
+ if (releaserRole.startsWith(roleNamePrefix)) {
users.push(
...workspaceMembers.filter((user) => user.roles.includes(releaserRole))
);
@@ -23,7 +23,7 @@ export const releaserCandidatesForIssue = (issue: ComposedIssue) => {
.map((membership) => membership.user)
);
}
- if (releaserRole.startsWith("users/")) {
+ if (releaserRole.startsWith(userNamePrefix)) {
const email = extractUserResourceName(releaserRole);
const user = workspaceMembers.find((u) => u.email === email);
if (user) {
diff --git a/frontend/src/components/IssueV1/logic/rollout.ts b/frontend/src/components/IssueV1/logic/rollout.ts
index 0dcfe0fe67..47ac6c65f9 100644
--- a/frontend/src/components/IssueV1/logic/rollout.ts
+++ b/frontend/src/components/IssueV1/logic/rollout.ts
@@ -1,6 +1,5 @@
import { t } from "@/plugins/i18n";
-import type { ComposedIssue } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedIssue, ComposedUser } from "@/types";
import { IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
import type { Task } from "@/types/proto/v1/rollout_service";
import {
@@ -29,7 +28,7 @@ export const isGroupingChangeTaskV1 = (issue: ComposedIssue, task: Task) => {
export const allowUserToEditStatementForTask = (
issue: ComposedIssue,
task: Task,
- user: User
+ user: ComposedUser
): string[] => {
const denyReasons: string[] = [];
diff --git a/frontend/src/components/IssueV1/logic/subscriber.ts b/frontend/src/components/IssueV1/logic/subscriber.ts
index adb750bcb3..8c02313d0b 100644
--- a/frontend/src/components/IssueV1/logic/subscriber.ts
+++ b/frontend/src/components/IssueV1/logic/subscriber.ts
@@ -2,7 +2,7 @@ import { pull } from "lodash-es";
import { issueServiceClient } from "@/grpcweb";
import { t } from "@/plugins/i18n";
import { pushNotification } from "@/store";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import { Issue } from "@/types/proto/v1/issue_service";
export const updateIssueSubscribers = async (
@@ -28,7 +28,10 @@ export const updateIssueSubscribers = async (
}
};
-export const toggleSubscribeIssue = async (issue: Issue, user: User) => {
+export const toggleSubscribeIssue = async (
+ issue: Issue,
+ user: ComposedUser
+) => {
const subscribers = [...issue.subscribers];
const userTag = `users/${user.email}`;
const isSubscribed = subscribers.includes(userTag);
@@ -40,7 +43,7 @@ export const toggleSubscribeIssue = async (issue: Issue, user: User) => {
return await updateIssueSubscribers(issue, subscribers);
};
-export const doSubscribeIssue = async (issue: Issue, user: User) => {
+export const doSubscribeIssue = async (issue: Issue, user: ComposedUser) => {
const subscribers = [...issue.subscribers];
const userTag = `users/${user.email}`;
const isSubscribed = subscribers.includes(userTag);
diff --git a/frontend/src/components/IssueV1/logic/transition.ts b/frontend/src/components/IssueV1/logic/transition.ts
index 6f948b7100..a2558de2c3 100644
--- a/frontend/src/components/IssueV1/logic/transition.ts
+++ b/frontend/src/components/IssueV1/logic/transition.ts
@@ -3,9 +3,9 @@ import type {
ComposedIssue,
IssueStatusTransitionType,
IssueStatusTransition,
+ ComposedUser,
} from "@/types";
import { ISSUE_STATUS_TRANSITION_LIST } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { IssueStatus } from "@/types/proto/v1/issue_service";
import { Task_Status } from "@/types/proto/v1/rollout_service";
import type { StageStatusTransition, TaskStatusTransition } from "@/utils";
@@ -102,7 +102,7 @@ export function isApplicableTransition<
const allowUserToApplyIssueStatusTransition = (
issue: ComposedIssue,
- user: User
+ user: ComposedUser
) => {
// Allowed if the user has issues.update permission in the project
if (hasProjectPermissionV2(issue.projectEntity, user, "bb.issues.update")) {
diff --git a/frontend/src/components/PrincipalAvatar.vue b/frontend/src/components/PrincipalAvatar.vue
index 1b2be252ae..5bc2c60a51 100644
--- a/frontend/src/components/PrincipalAvatar.vue
+++ b/frontend/src/components/PrincipalAvatar.vue
@@ -13,14 +13,13 @@ import type { PropType } from "vue";
import { computed } from "vue";
import { BBAvatar } from "@/bbkit";
import type { BBAvatarSizeType } from "@/bbkit/types";
-import { UNKNOWN_ID, unknownUser } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { UNKNOWN_ID, unknownUser, type ComposedUser } from "@/types";
import type { VueClass } from "@/utils";
import { extractUserUID } from "@/utils";
const props = defineProps({
user: {
- type: Object as PropType<User>,
+ type: Object as PropType<ComposedUser>,
default: () => unknownUser(),
},
username: {
diff --git a/frontend/src/components/ProjectMember/ProjectMemberPanel.vue b/frontend/src/components/ProjectMember/ProjectMemberPanel.vue
index 80514931dd..523b7c2b90 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberPanel.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberPanel.vue
@@ -85,7 +85,7 @@ import {
useUserStore,
useUserGroupStore,
} from "@/store";
-import type { ComposedProject } from "@/types";
+import type { ComposedProject, ComposedUser } from "@/types";
import {
getUserEmailInBinding,
getGroupEmailInBinding,
@@ -93,7 +93,6 @@ import {
PRESET_WORKSPACE_ROLES,
groupBindingPrefix,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import type { UserGroup } from "@/types/proto/v1/user_group";
import AddProjectMembersPanel from "./AddProjectMember/AddProjectMembersPanel.vue";
@@ -150,7 +149,7 @@ const activeUserList = computed(() => {
({
...unknownUser(),
email,
- } as User)
+ } as ComposedUser)
);
});
diff --git a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
index 59008f5e04..2d29d830fe 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
@@ -109,7 +109,8 @@
<InstanceV1Name
class="text-gray-500"
:instance="
- extractDatabase(item.databaseResource).instanceResource
+ extractDatabase(item.databaseResource)
+ .instanceResource
"
:link="false"
/>
@@ -223,9 +224,8 @@ import {
pushNotification,
} from "@/store";
import { userGroupNamePrefix } from "@/store/modules/v1/common";
-import type { ComposedProject, DatabaseResource } from "@/types";
+import type { ComposedProject, DatabaseResource, ComposedUser } from "@/types";
import { PresetRoleType, PRESET_ROLES } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import { Binding } from "@/types/proto/v1/iam_policy";
import { displayRoleTitle, hasProjectPermissionV2 } from "@/utils";
@@ -369,7 +369,7 @@ const allowRemoveRole = (role: string) => {
const ownerBindings = iamPolicy.value.bindings.filter(
(binding) => binding.role === PresetRoleType.PROJECT_OWNER
);
- const members: User[] = [];
+ const members: ComposedUser[] = [];
// Find those never expires owner members.
for (const binding of ownerBindings) {
if (binding.condition?.expression !== "") {
@@ -381,7 +381,9 @@ const allowRemoveRole = (role: string) => {
.map((userIdentifier) => {
return userStore.getUserByIdentifier(userIdentifier);
})
- .filter((user) => user && user.state === State.ACTIVE) as User[])
+ .filter(
+ (user) => user && user.state === State.ACTIVE
+ ) as ComposedUser[])
);
}
// If there is only one owner, disallow removing.
diff --git a/frontend/src/components/ProjectMember/types.ts b/frontend/src/components/ProjectMember/types.ts
index a1391e4956..7536e5a61e 100644
--- a/frontend/src/components/ProjectMember/types.ts
+++ b/frontend/src/components/ProjectMember/types.ts
@@ -1,4 +1,4 @@
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import type { Binding } from "@/types/proto/v1/iam_policy";
import type { UserGroup } from "@/types/proto/v1/user_group";
@@ -14,6 +14,6 @@ export interface ProjectBinding extends ProjectRole {
// like user:{email} or group:{email}
binding: string;
type: "users" | "groups";
- user?: User;
+ user?: ComposedUser;
group?: UserGroup;
}
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index e6ee5cad9b..97e9e0f0b4 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -34,6 +34,7 @@ import {
SQL_EDITOR_PROJECT_MODULE,
} from "@/router/sqlEditor";
import {
+ usePolicyV1Store,
useInstanceV1Store,
useProjectV1Store,
useCurrentUserV1,
@@ -54,6 +55,7 @@ import {
isValidInstanceName,
} from "@/types";
import { State } from "@/types/proto/v1/common";
+import { PolicyResourceType } from "@/types/proto/v1/org_policy_service";
import {
emptySQLEditorConnection,
extractProjectResourceName,
@@ -88,6 +90,7 @@ const editorStore = useSQLEditorStore();
const worksheetStore = useWorkSheetStore();
const tabStore = useSQLEditorTabStore();
const groupStore = useUserGroupStore();
+const policyStore = usePolicyV1Store();
const { isFetching: isFetchingWorksheet } = useSheetContext();
const { filter } = useFilterStore();
const {
@@ -599,7 +602,13 @@ const restoreLastVisitedSidebarTab = () => {
onMounted(async () => {
editorStore.projectContextReady = false;
- await Promise.all([initializeProjects(), groupStore.fetchGroupList()]);
+ await Promise.all([
+ policyStore.fetchPolicies({
+ resourceType: PolicyResourceType.WORKSPACE,
+ }),
+ initializeProjects(),
+ groupStore.fetchGroupList(),
+ ]);
await prepareInstancesAndDatabases();
tabStore.maybeInitProject(editorStore.project);
editorStore.projectContextReady = true;
diff --git a/frontend/src/components/Role/Setting/components/RolePanel.vue b/frontend/src/components/Role/Setting/components/RolePanel.vue
index 5d43eedb87..04116bcd50 100644
--- a/frontend/src/components/Role/Setting/components/RolePanel.vue
+++ b/frontend/src/components/Role/Setting/components/RolePanel.vue
@@ -110,6 +110,7 @@ import { computed, reactive, watch, nextTick, ref } from "vue";
import { useI18n } from "vue-i18n";
import { Drawer, DrawerContent, ResourceIdField } from "@/components/v2";
import { pushNotification, useRoleStore } from "@/store";
+import { roleNamePrefix } from "@/store/modules/v1/common";
import type { ValidatedMessage } from "@/types";
import { PROJECT_PERMISSIONS, WORKSPACE_PERMISSIONS } from "@/types";
import { Role } from "@/types/proto/v1/role_service";
@@ -151,7 +152,7 @@ const resourceId = computed({
return extractRoleResourceName(state.role.name);
},
set(value) {
- state.role.name = `roles/${value}`;
+ state.role.name = `${roleNamePrefix}${value}`;
},
});
@@ -207,7 +208,7 @@ const handleSave = async () => {
const validateResourceId = async (
name: string
): Promise<ValidatedMessage[]> => {
- if (roleStore.roleList.find((r) => r.name === `roles/${name}`)) {
+ if (roleStore.roleList.find((r) => r.name === `${roleNamePrefix}${name}`)) {
return [
{
type: "error",
diff --git a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
index 1ca1fb8355..53641f1742 100644
--- a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
+++ b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
@@ -290,9 +290,9 @@ import {
getUserEmailInBinding,
getGroupEmailInBinding,
groupBindingPrefix,
+ type ComposedUser,
} from "@/types";
import { Expr } from "@/types/proto/google/type/expr";
-import type { User } from "@/types/proto/v1/auth_service";
import { MaskingLevel, maskingLevelToJSON } from "@/types/proto/v1/common";
import type {
Policy,
@@ -316,7 +316,7 @@ import { getMaskDataIdentifier, isCurrentColumnException } from "./utils";
interface AccessUser {
type: "user" | "group";
group?: UserGroup;
- user?: User;
+ user?: ComposedUser;
supportActions: Set<MaskingExceptionPolicy_MaskingException_Action>;
maskingLevel: MaskingLevel;
expirationTimestamp?: number;
diff --git a/frontend/src/components/User/Settings/CreateUserDrawer.vue b/frontend/src/components/User/Settings/CreateUserDrawer.vue
index 3a6e611c5a..5d64ee64a1 100644
--- a/frontend/src/components/User/Settings/CreateUserDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateUserDrawer.vue
@@ -169,7 +169,7 @@
</template>
<script lang="ts" setup>
-import { cloneDeep, head, isEmpty } from "lodash-es";
+import { cloneDeep, head, isEmpty, isEqual, isUndefined } from "lodash-es";
import { ArchiveIcon } from "lucide-vue-next";
import type { SelectGroupOption, SelectOption } from "naive-ui";
import {
@@ -198,22 +198,22 @@ import {
PRESET_WORKSPACE_ROLES,
PresetRoleType,
emptyUser,
+ type ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { UpdateUserRequest, UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import { displayRoleTitle, randomString } from "@/utils";
interface LocalState {
isRequesting: boolean;
- user: User;
+ user: ComposedUser;
passwordConfirm: string;
}
const serviceAccountEmailSuffix = "@service.bytebase.com";
const props = defineProps<{
- user?: User;
+ user?: ComposedUser;
}>();
const emit = defineEmits<{
@@ -396,6 +396,12 @@ const tryCreateOrUpdateUser = async () => {
updateMask: getUpdateMaskFromUsers(props.user!, state.user),
})
);
+ if (
+ !isUndefined(state.user.roles) &&
+ !isEqual(props.user?.roles, state.user.roles)
+ ) {
+ await userStore.updateUserRoles(state.user);
+ }
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/User/Settings/UserDataTable/cells/UserGroupsCell.vue b/frontend/src/components/User/Settings/UserDataTable/cells/UserGroupsCell.vue
index 09c6b77a04..d1a6882334 100644
--- a/frontend/src/components/User/Settings/UserDataTable/cells/UserGroupsCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/cells/UserGroupsCell.vue
@@ -17,11 +17,11 @@ import { NTag } from "naive-ui";
import { computed } from "vue";
import { useUserGroupStore } from "@/store";
import { getUserEmailFromIdentifier } from "@/store/modules/v1/common";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import type { UserGroup } from "@/types/proto/v1/user_group";
const props = defineProps<{
- user: User;
+ user: ComposedUser;
}>();
defineEmits<{
diff --git a/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue b/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
index 55ead1249e..2f11ef3a03 100644
--- a/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
@@ -63,17 +63,16 @@ import { NButton } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { pushNotification, useCurrentUserV1 } from "@/store";
-import { SYSTEM_BOT_USER_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { SYSTEM_BOT_USER_NAME, type ComposedUser } from "@/types";
import { UserType } from "@/types/proto/v1/auth_service";
import { hasWorkspacePermissionV2, toClipboard } from "@/utils";
defineProps<{
- user: User;
+ user: ComposedUser;
}>();
defineEmits<{
- (event: "reset-service-key", user: User): void;
+ (event: "reset-service-key", user: ComposedUser): void;
}>();
const { t } = useI18n();
diff --git a/frontend/src/components/User/Settings/UserDataTable/cells/UserOperationsCell.vue b/frontend/src/components/User/Settings/UserDataTable/cells/UserOperationsCell.vue
index cd6cdf7bab..450af14b2d 100644
--- a/frontend/src/components/User/Settings/UserDataTable/cells/UserOperationsCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/cells/UserOperationsCell.vue
@@ -31,12 +31,15 @@ import { PencilIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { computed } from "vue";
import { useCurrentUserV1, useUserStore } from "@/store";
-import { PresetRoleType, SYSTEM_BOT_USER_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import {
+ PresetRoleType,
+ SYSTEM_BOT_USER_NAME,
+ type ComposedUser,
+} from "@/types";
import { State } from "@/types/proto/v1/common";
defineProps<{
- user: User;
+ user: ComposedUser;
}>();
defineEmits<{
@@ -51,18 +54,18 @@ const allowEdit = computed(() => {
return currentUserV1.value.roles.includes(PresetRoleType.WORKSPACE_ADMIN);
});
-const allowUpdateUser = (user: User) => {
+const allowUpdateUser = (user: ComposedUser) => {
if (user.name === SYSTEM_BOT_USER_NAME) {
return false;
}
return allowEdit.value && user.state === State.ACTIVE;
};
-const allowReactiveUser = (user: User) => {
+const allowReactiveUser = (user: ComposedUser) => {
return allowEdit.value && user.state === State.DELETED;
};
-const changeRowStatus = (user: User, state: State) => {
+const changeRowStatus = (user: ComposedUser, state: State) => {
if (state === State.ACTIVE) {
userStore.restoreUser(user);
} else {
diff --git a/frontend/src/components/User/Settings/UserDataTable/index.vue b/frontend/src/components/User/Settings/UserDataTable/index.vue
index bc13209d25..373b49bfcf 100644
--- a/frontend/src/components/User/Settings/UserDataTable/index.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/index.vue
@@ -25,7 +25,7 @@ import { NDataTable } from "naive-ui";
import { computed, reactive, h } from "vue";
import { useI18n } from "vue-i18n";
import { useUserStore } from "@/store";
-import type { User } from "@/types/proto/v1/auth_service";
+import { type ComposedUser } from "@/types";
import type { UserGroup } from "@/types/proto/v1/user_group";
import { copyServiceKeyToClipboardIfNeeded } from "../common";
import UserGroupsCell from "./cells/UserGroupsCell.vue";
@@ -35,15 +35,15 @@ import UserRolesCell from "./cells/UserRolesCell.vue";
interface LocalState {
showResetKeyAlert: boolean;
- targetServiceAccount?: User;
+ targetServiceAccount?: ComposedUser;
}
defineProps<{
- userList: User[];
+ userList: ComposedUser[];
}>();
const emit = defineEmits<{
- (event: "update-user", user: User): void;
+ (event: "update-user", user: ComposedUser): void;
(event: "select-group", group: UserGroup): void;
}>();
@@ -60,7 +60,7 @@ const columns = computed(() => {
title: t("settings.members.table.account"),
width: "32rem",
resizable: true,
- render: (user: User) => {
+ render: (user: ComposedUser) => {
return h(UserNameCell, {
user,
"onReset-service-key": tryResetServiceKey,
@@ -71,7 +71,7 @@ const columns = computed(() => {
key: "roles",
title: t("settings.members.table.role"),
resizable: true,
- render: (user: User) => {
+ render: (user: ComposedUser) => {
return h(UserRolesCell, {
roles: user.roles,
});
@@ -81,7 +81,7 @@ const columns = computed(() => {
key: "groups",
title: t("settings.members.table.groups"),
resizable: true,
- render: (user: User) => {
+ render: (user: ComposedUser) => {
return h(UserGroupsCell, {
user,
"onSelect-group": (group) => emit("select-group", group),
@@ -92,7 +92,7 @@ const columns = computed(() => {
key: "operations",
title: "",
width: "4rem",
- render: (user: User) => {
+ render: (user: ComposedUser) => {
return h(UserOperationsCell, {
user,
"onUpdate-user": () => {
@@ -101,10 +101,10 @@ const columns = computed(() => {
});
},
},
- ] as DataTableColumn<User>[];
+ ] as DataTableColumn<ComposedUser>[];
});
-const tryResetServiceKey = (user: User) => {
+const tryResetServiceKey = (user: ComposedUser) => {
state.showResetKeyAlert = true;
state.targetServiceAccount = user;
};
diff --git a/frontend/src/components/User/Settings/UserDataTableByGroup/cells/GroupMemberNameCell.vue b/frontend/src/components/User/Settings/UserDataTableByGroup/cells/GroupMemberNameCell.vue
index f87f7c6aee..1a7283370c 100644
--- a/frontend/src/components/User/Settings/UserDataTableByGroup/cells/GroupMemberNameCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTableByGroup/cells/GroupMemberNameCell.vue
@@ -36,8 +36,7 @@
<script lang="ts" setup>
import { useCurrentUserV1 } from "@/store";
-import { SYSTEM_BOT_USER_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { SYSTEM_BOT_USER_NAME, type ComposedUser } from "@/types";
import { UserType } from "@/types/proto/v1/auth_service";
import {
UserGroupMember_Role,
@@ -46,7 +45,7 @@ import {
withDefaults(
defineProps<{
- user: User;
+ user: ComposedUser;
role?: UserGroupMember_Role;
}>(),
{
@@ -55,7 +54,7 @@ withDefaults(
);
defineEmits<{
- (event: "reset-service-key", user: User): void;
+ (event: "reset-service-key", user: ComposedUser): void;
}>();
const currentUserV1 = useCurrentUserV1();
diff --git a/frontend/src/components/User/Settings/UserDataTableByGroup/index.vue b/frontend/src/components/User/Settings/UserDataTableByGroup/index.vue
index aa7d64a430..943e587f2f 100644
--- a/frontend/src/components/User/Settings/UserDataTableByGroup/index.vue
+++ b/frontend/src/components/User/Settings/UserDataTableByGroup/index.vue
@@ -17,7 +17,7 @@ import { computed, h } from "vue";
import { useI18n } from "vue-i18n";
import { useUserStore } from "@/store";
import { getUserEmailFromIdentifier } from "@/store/modules/v1/common";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import { UserGroup, UserGroupMember_Role } from "@/types/proto/v1/user_group";
import GroupMemberNameCell from "./cells/GroupMemberNameCell.vue";
import GroupNameCell from "./cells/GroupNameCell.vue";
@@ -33,7 +33,7 @@ interface GroupRowData {
interface UserRowData {
type: "user";
name: string;
- user: User;
+ user: ComposedUser;
role: UserGroupMember_Role;
}
diff --git a/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserNameCell.vue b/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserNameCell.vue
index 069910d853..bac469a9d0 100644
--- a/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserNameCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserNameCell.vue
@@ -24,16 +24,15 @@
<script lang="ts" setup>
import { useCurrentUserV1 } from "@/store";
-import { SYSTEM_BOT_USER_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { SYSTEM_BOT_USER_NAME, type ComposedUser } from "@/types";
import { UserType } from "@/types/proto/v1/auth_service";
defineProps<{
- user: User;
+ user: ComposedUser;
}>();
defineEmits<{
- (event: "reset-service-key", user: User): void;
+ (event: "reset-service-key", user: ComposedUser): void;
}>();
const currentUserV1 = useCurrentUserV1();
diff --git a/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserOperationsCell.vue b/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserOperationsCell.vue
index e071629256..c1c7414d87 100644
--- a/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserOperationsCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTableByRole/cells/UserOperationsCell.vue
@@ -20,12 +20,15 @@ import { PencilIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { computed } from "vue";
import { useCurrentUserV1 } from "@/store";
-import { PresetRoleType, SYSTEM_BOT_USER_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import {
+ PresetRoleType,
+ SYSTEM_BOT_USER_NAME,
+ type ComposedUser,
+} from "@/types";
import { State } from "@/types/proto/v1/common";
defineProps<{
- user: User;
+ user: ComposedUser;
}>();
defineEmits<{
@@ -38,7 +41,7 @@ const allowEdit = computed(() => {
return currentUserV1.value.roles.includes(PresetRoleType.WORKSPACE_ADMIN);
});
-const allowUpdateUser = (user: User) => {
+const allowUpdateUser = (user: ComposedUser) => {
if (user.name === SYSTEM_BOT_USER_NAME) {
return false;
}
diff --git a/frontend/src/components/User/Settings/UserDataTableByRole/index.vue b/frontend/src/components/User/Settings/UserDataTableByRole/index.vue
index f8e223a32d..8f3e385ac9 100644
--- a/frontend/src/components/User/Settings/UserDataTableByRole/index.vue
+++ b/frontend/src/components/User/Settings/UserDataTableByRole/index.vue
@@ -17,8 +17,7 @@ import { NDataTable } from "naive-ui";
import { computed, h } from "vue";
import { useI18n } from "vue-i18n";
import { useRoleStore } from "@/store";
-import { PRESET_WORKSPACE_ROLES } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { PRESET_WORKSPACE_ROLES, type ComposedUser } from "@/types";
import { displayRoleTitle, sortRoles } from "@/utils";
import UserNameCell from "./cells/UserNameCell.vue";
import UserOperationsCell from "./cells/UserOperationsCell.vue";
@@ -32,15 +31,15 @@ interface RoleRowData {
interface UserRowData {
type: "user";
name: string;
- user: User;
+ user: ComposedUser;
}
const props = defineProps<{
- userList: User[];
+ userList: ComposedUser[];
}>();
const emit = defineEmits<{
- (event: "update-user", user: User): void;
+ (event: "update-user", user: ComposedUser): void;
}>();
const { t } = useI18n();
diff --git a/frontend/src/components/User/Settings/common.ts b/frontend/src/components/User/Settings/common.ts
index 5169215450..7ae6dd5054 100644
--- a/frontend/src/components/User/Settings/common.ts
+++ b/frontend/src/components/User/Settings/common.ts
@@ -1,9 +1,9 @@
import { t } from "@/plugins/i18n";
import { pushNotification } from "@/store";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedUser } from "@/types";
import { toClipboard } from "@/utils";
-export const copyServiceKeyToClipboardIfNeeded = (user: User) => {
+export const copyServiceKeyToClipboardIfNeeded = (user: ComposedUser) => {
if (!user.serviceKey) return;
toClipboard(user.serviceKey);
diff --git a/frontend/src/components/User/UserAvatar.vue b/frontend/src/components/User/UserAvatar.vue
index 26c67823a1..e584bf00a9 100644
--- a/frontend/src/components/User/UserAvatar.vue
+++ b/frontend/src/components/User/UserAvatar.vue
@@ -13,13 +13,12 @@ import type { PropType } from "vue";
import { computed } from "vue";
import { BBAvatar } from "@/bbkit";
import type { BBAvatarSizeType } from "@/bbkit/types";
-import { UNKNOWN_ID, unknownUser } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import { UNKNOWN_ID, unknownUser, type ComposedUser } from "@/types";
import type { VueClass } from "@/utils";
const props = defineProps({
user: {
- type: Object as PropType<User>,
+ type: Object as PropType<ComposedUser>,
default: () => unknownUser(),
},
size: {
diff --git a/frontend/src/components/v2/Select/UserSelect.vue b/frontend/src/components/v2/Select/UserSelect.vue
index 138e89490c..87c3fa6eaa 100644
--- a/frontend/src/components/v2/Select/UserSelect.vue
+++ b/frontend/src/components/v2/Select/UserSelect.vue
@@ -39,15 +39,15 @@ import {
unknownUser,
PresetRoleType,
isValidProjectName,
+ type ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
-import { extractUserUID, memberListInProjectV1 } from "@/utils";
+import { extractUserUID, memberListInIAM } from "@/utils";
export interface UserSelectOption extends SelectOption {
value: string;
- user: User;
+ user: ComposedUser;
}
const props = withDefaults(
@@ -65,8 +65,10 @@ const props = withDefaults(
allowedWorkspaceRoleList?: string[];
allowedProjectMemberRoleList?: string[];
autoReset?: boolean;
- filter?: (user: User, index: number) => boolean;
- mapOptions?: (users: User[]) => (UserSelectOption | SelectGroupOption)[];
+ filter?: (user: ComposedUser, index: number) => boolean;
+ mapOptions?: (
+ users: ComposedUser[]
+ ) => (UserSelectOption | SelectGroupOption)[];
fallbackOption?: SelectProps["fallbackOption"];
size?: "tiny" | "small" | "medium" | "large";
}>(),
@@ -127,7 +129,7 @@ watchEffect(prepare);
const getUserListFromProject = (projectName: string) => {
const project = projectV1Store.getProjectByName(projectName);
- const memberList = memberListInProjectV1(project.iamPolicy);
+ const memberList = memberListInIAM(project.iamPolicy);
const filteredUserList = memberList
.filter((member) => {
if (props.allowedProjectMemberRoleList.length === 0) {
@@ -239,7 +241,7 @@ const handleValueUpdated = (value: string | string[]) => {
}
};
-const renderAvatar = (user: User) => {
+const renderAvatar = (user: ComposedUser) => {
if (user.name === UNKNOWN_USER_NAME) {
return (
<div class="bb-user-select--avatar w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white">
diff --git a/frontend/src/grpcweb/index.ts b/frontend/src/grpcweb/index.ts
index 41c33625a8..2066983e26 100644
--- a/frontend/src/grpcweb/index.ts
+++ b/frontend/src/grpcweb/index.ts
@@ -33,6 +33,7 @@ import { UserGroupServiceDefinition } from "@/types/proto/v1/user_group";
import { VCSConnectorServiceDefinition } from "@/types/proto/v1/vcs_connector_service";
import { VCSProviderServiceDefinition } from "@/types/proto/v1/vcs_provider_service";
import { WorksheetServiceDefinition } from "@/types/proto/v1/worksheet_service";
+import { WorkspaceServiceDefinition } from "@/types/proto/v1/workspace_service";
import {
authInterceptorMiddleware,
errorNotificationMiddleware,
@@ -124,6 +125,7 @@ export const settingServiceClient = clientFactory.create(
SettingServiceDefinition,
channel
);
+
export const sheetServiceClient = clientFactory.create(
SheetServiceDefinition,
channel
@@ -208,11 +210,17 @@ export const userGroupServiceClient = clientFactory.create(
UserGroupServiceDefinition,
channel
);
+
export const reviewConfigServiceClient = clientFactory.create(
ReviewConfigServiceDefinition,
channel
);
+export const workspaceServiceClient = clientFactory.create(
+ WorkspaceServiceDefinition,
+ channel
+);
+
// e.g. How to use `authServiceClient`?
//
// await authServiceClient.login({
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index ed91d6a53b..d9802da049 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -5,17 +5,17 @@ import { computed } from "vue";
import { authServiceClient } from "@/grpcweb";
import type { SignupInfo, ActivateInfo } from "@/types";
import { unknownUser } from "@/types";
+import type { ComposedUser } from "@/types";
import type {
LoginRequest,
LoginResponse,
- User,
} from "@/types/proto/v1/auth_service";
import { UserType } from "@/types/proto/v1/auth_service";
import { getIntCookie } from "@/utils";
import { useUserStore } from ".";
interface AuthState {
- currentUser: User;
+ currentUser: ComposedUser;
}
export const useAuthStore = defineStore("auth_v1", {
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index 455bea467f..1192a156ef 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -10,20 +10,34 @@ import {
allUsersUser,
SYSTEM_BOT_USER_NAME,
} from "@/types";
+import type { ComposedUser } from "@/types";
import type { UpdateUserRequest, User } from "@/types/proto/v1/auth_service";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
+import { roleListInIAM } from "@/utils";
import { userNamePrefix, getUserEmailFromIdentifier } from "./v1/common";
import { usePermissionStore } from "./v1/permission";
+import { useWorkspaceV1Store } from "./v1/workspace";
export const useUserStore = defineStore("user", () => {
- const userMapByName = ref<Map<string, User>>(new Map());
+ const userMapByName = ref<Map<string, ComposedUser>>(new Map());
+ const workspaceStore = useWorkspaceV1Store();
+
+ const iamPolicy = computed(() => {
+ return workspaceStore.workspaceIamPolicy;
+ });
const setUser = (user: User) => {
- userMapByName.value.set(user.name, user);
+ const roles = roleListInIAM(iamPolicy.value, user.email);
+ const composedUser: ComposedUser = {
+ ...user,
+ roles,
+ };
+ userMapByName.value.set(user.name, composedUser);
// invalid permission cache
- usePermissionStore().invalidCacheByUser(user);
+ usePermissionStore().invalidCacheByUser(composedUser);
+ return composedUser;
};
const userList = computed(() => {
@@ -66,10 +80,11 @@ export const useUserStore = defineStore("user", () => {
const { users } = await authServiceClient.listUsers({
showDeleted: true,
});
+ const response: ComposedUser[] = [];
for (const user of users) {
- setUser(user);
+ response.push(setUser(user));
}
- return users;
+ return response;
};
const fetchUser = async (name: string, silent = false) => {
const user = await authServiceClient.getUser(
@@ -80,15 +95,18 @@ export const useUserStore = defineStore("user", () => {
silent,
}
);
- setUser(user);
- return user;
+ return setUser(user);
};
- const createUser = async (user: User) => {
+ const createUser = async (user: ComposedUser) => {
const createdUser = await authServiceClient.createUser({
user,
});
- setUser(createdUser);
- return createdUser;
+ await workspaceStore.patchIamPolicy({
+ member: `user:${createdUser.email}`,
+ roles: user.roles,
+ });
+
+ return setUser(createdUser);
};
const updateUser = async (updateUserRequest: UpdateUserRequest) => {
const name = updateUserRequest.user?.name || "";
@@ -97,8 +115,14 @@ export const useUserStore = defineStore("user", () => {
throw new Error(`user with name ${name} not found`);
}
const user = await authServiceClient.updateUser(updateUserRequest);
- setUser(user);
- return user;
+ return setUser(user);
+ };
+ const updateUserRoles = async (user: ComposedUser) => {
+ await workspaceStore.patchIamPolicy({
+ member: `user:${user.email}`,
+ roles: user.roles,
+ });
+ return setUser(user);
};
const getOrFetchUserByName = async (name: string, silent = false) => {
const cachedData = userMapByName.value.get(name);
@@ -106,8 +130,7 @@ export const useUserStore = defineStore("user", () => {
return cachedData;
}
const user = await fetchUser(name, silent);
- setUser(user);
- return user;
+ return setUser(user);
};
const getUserByName = (name: string) => {
return userMapByName.value.get(name);
@@ -140,8 +163,7 @@ export const useUserStore = defineStore("user", () => {
const restoredUser = await authServiceClient.undeleteUser({
name: user.name,
});
- setUser(restoredUser);
- return restoredUser;
+ return setUser(restoredUser);
};
return {
@@ -154,6 +176,7 @@ export const useUserStore = defineStore("user", () => {
fetchUser,
createUser,
updateUser,
+ updateUserRoles,
getOrFetchUserByName,
getUserByName,
getOrFetchUserById,
@@ -188,9 +211,6 @@ export const getUpdateMaskFromUsers = (
if (!isUndefined(update.password) && update.password !== "") {
updateMask.push("password");
}
- if (!isUndefined(update.roles) && !isEqual(origin.roles, update.roles)) {
- updateMask.push("roles");
- }
if (!isUndefined(update.phone) && !isEqual(origin.phone, update.phone)) {
updateMask.push("phone");
}
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index 36d1794266..55131f224f 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -2,6 +2,7 @@ import type { ResourceId, Project, SheetId } from "@/types";
import { UNKNOWN_ID } from "@/types";
export const userNamePrefix = "users/";
+export const roleNamePrefix = "roles/";
export const environmentNamePrefix = "environments/";
export const projectNamePrefix = "projects/";
export const instanceNamePrefix = "instances/";
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index 505d1ded1a..29c75d7174 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -2,7 +2,12 @@ import { uniq } from "lodash-es";
import { defineStore } from "pinia";
import { computed, reactive, ref, unref, watch, markRaw } from "vue";
import { databaseServiceClient } from "@/grpcweb";
-import type { ComposedInstance, ComposedDatabase, MaybeRef } from "@/types";
+import type {
+ ComposedInstance,
+ ComposedDatabase,
+ MaybeRef,
+ ComposedUser,
+} from "@/types";
import {
emptyDatabase,
EMPTY_ID,
@@ -12,7 +17,6 @@ import {
unknownInstanceResource,
} from "@/types";
import { DEFAULT_PROJECT_NAME } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import type {
Database,
UpdateDatabaseRequest,
@@ -95,7 +99,7 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
await fetchDatabaseByName(database);
}
};
- const databaseListByUser = (user: User) => {
+ const databaseListByUser = (user: ComposedUser) => {
return databaseList.value.filter((db) => {
if (hasProjectPermissionV2(db.projectEntity, user, "bb.databases.get"))
return true;
diff --git a/frontend/src/store/modules/v1/index.ts b/frontend/src/store/modules/v1/index.ts
index 0af6b1090d..1acade96e8 100644
--- a/frontend/src/store/modules/v1/index.ts
+++ b/frontend/src/store/modules/v1/index.ts
@@ -26,3 +26,4 @@ export * from "./issueComment";
export * from "./auditLog";
export * from "./userGroup";
export * from "./permission";
+export * from "./workspace";
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index e02a86f4e2..23787670ee 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -13,7 +13,7 @@ import {
ApprovalNode_Type,
ApprovalNode_GroupValue,
} from "@/types/proto/v1/issue_service";
-import { extractProjectResourceName, memberListInProjectV1 } from "@/utils";
+import { extractProjectResourceName, memberListInIAM } from "@/utils";
import { useUserStore } from "../user";
import {
shallowComposeIssue,
@@ -147,7 +147,7 @@ export const candidatesOfApprovalStepV1 = (
(user) => user.userType === UserType.USER
);
const project = issue.projectEntity;
- const projectMemberList = memberListInProjectV1(project.iamPolicy).filter(
+ const projectMemberList = memberListInIAM(project.iamPolicy).filter(
(member) => member.user.userType === UserType.USER
);
@@ -184,7 +184,7 @@ export const candidatesOfApprovalStepV1 = (
return [];
};
const candidatesForCustomRoles = (role: string) => {
- const memberList = memberListInProjectV1(project.iamPolicy);
+ const memberList = memberListInIAM(project.iamPolicy);
return memberList
.filter((member) => member.user.userType === UserType.USER)
.filter((member) => member.roleList.includes(role))
diff --git a/frontend/src/store/modules/v1/permission.ts b/frontend/src/store/modules/v1/permission.ts
index f545b9d3f0..cf4ccac410 100644
--- a/frontend/src/store/modules/v1/permission.ts
+++ b/frontend/src/store/modules/v1/permission.ts
@@ -2,19 +2,14 @@ import { uniq } from "lodash-es";
import { defineStore } from "pinia";
import { shallowReactive } from "vue";
import {
- ALL_USERS_USER_EMAIL,
- getUserEmailInBinding,
- groupBindingPrefix,
PRESET_WORKSPACE_ROLES,
type ComposedProject,
type ProjectPermission,
type WorkspacePermission,
+ type ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
-import { isBindingPolicyExpired } from "@/utils";
+import { roleListInIAM } from "@/utils";
import { useRoleStore } from "../role";
-import { userNamePrefix } from "./common";
-import { useUserGroupStore } from "./userGroup";
export const usePermissionStore = defineStore("permission", () => {
const projectRoleListCache = shallowReactive(new Map<string, string[]>());
@@ -27,7 +22,7 @@ export const usePermissionStore = defineStore("permission", () => {
const roleStore = useRoleStore();
const workspaceLevelPermissionsByUser = (
- user: User
+ user: ComposedUser
): Set<WorkspacePermission | ProjectPermission> => {
const cached = workspaceLevelPermissionsMapByUserName.get(user.name);
if (cached) {
@@ -49,48 +44,22 @@ export const usePermissionStore = defineStore("permission", () => {
return permissions;
};
- const roleListInProjectV1 = (project: ComposedProject, user: User) => {
+ const roleListInProjectV1 = (
+ project: ComposedProject,
+ user: ComposedUser
+ ) => {
const key = `${user.name}@@${project.name}`;
const cached = projectRoleListCache.get(key);
if (cached) {
return cached;
}
- const groupStore = useUserGroupStore();
- const userInBinding = getUserEmailInBinding(user.email);
-
const workspaceLevelProjectRoles = user.roles.filter(
(role) => !PRESET_WORKSPACE_ROLES.includes(role)
);
const { iamPolicy } = project;
- const projectBindingRoles = iamPolicy.bindings
- .filter((binding) => {
- if (isBindingPolicyExpired(binding)) {
- return false;
- }
- for (const member of binding.members) {
- if (member === ALL_USERS_USER_EMAIL) {
- return true;
- }
- if (member === userInBinding) {
- return true;
- }
-
- if (member.startsWith(groupBindingPrefix)) {
- const group = groupStore.getGroupByIdentifier(member);
- if (!group) {
- continue;
- }
-
- return group.members.some(
- (m) => m.member === `${userNamePrefix}${user.email}`
- );
- }
- }
- return false;
- })
- .map((binding) => binding.role);
+ const projectBindingRoles = roleListInIAM(iamPolicy, user.email);
const result = uniq([
...projectBindingRoles,
@@ -100,7 +69,10 @@ export const usePermissionStore = defineStore("permission", () => {
return result;
};
- const permissionsInProjectV1 = (project: ComposedProject, user: User) => {
+ const permissionsInProjectV1 = (
+ project: ComposedProject,
+ user: ComposedUser
+ ) => {
const key = `${user.name}@@${project.name}`;
const cached = projectPermissionsCache.get(key);
if (cached) {
@@ -130,7 +102,7 @@ export const usePermissionStore = defineStore("permission", () => {
);
permissionsKeys.forEach((key) => projectPermissionsCache.delete(key));
};
- const invalidCacheByUser = (user: User) => {
+ const invalidCacheByUser = (user: ComposedUser) => {
workspaceLevelPermissionsMapByUserName.delete(user.name);
const roleListKeys = Array.from(projectRoleListCache.keys()).filter((key) =>
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index e470ce215d..62c78cc718 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -11,7 +11,7 @@ import {
isOwnerOfProjectV1,
isViewerOfProjectV1,
} from "@/utils";
-import { getUserEmailListInBinding, memberListInProjectV1 } from "@/utils";
+import { getUserEmailListInBinding, memberListInIAM } from "@/utils";
import { convertFromExpr } from "@/utils/issue/cel";
import { useCurrentUserV1 } from "../auth";
import { usePermissionStore } from "./permission";
@@ -211,7 +211,7 @@ export const useCurrentUserIamPolicy = () => {
return false;
}
- const member = memberListInProjectV1(policy).find(
+ const member = memberListInIAM(policy).find(
(member) => member.user.email === currentUser.value.email
);
if (!member) {
@@ -280,7 +280,7 @@ export const useCurrentUserIamPolicy = () => {
return false;
}
- const member = memberListInProjectV1(policy).find(
+ const member = memberListInIAM(policy).find(
(member) => member.user.email === currentUser.value.email
);
if (!member) {
diff --git a/frontend/src/store/modules/v1/workspace.ts b/frontend/src/store/modules/v1/workspace.ts
new file mode 100644
index 0000000000..9082cda0f8
--- /dev/null
+++ b/frontend/src/store/modules/v1/workspace.ts
@@ -0,0 +1,46 @@
+import { defineStore } from "pinia";
+import { computed, ref, watchEffect } from "vue";
+import { workspaceServiceClient } from "@/grpcweb";
+import { IamPolicy } from "@/types/proto/v1/iam_policy";
+
+export const useWorkspaceV1Store = defineStore("workspace_v1", () => {
+ const workspaceIamPolicy = ref<IamPolicy>(IamPolicy.fromPartial({}));
+
+ const fetchIamPolicy = async () => {
+ const policy = await workspaceServiceClient.getIamPolicy({
+ resource: "workspaces/-",
+ });
+ workspaceIamPolicy.value = policy;
+ };
+
+ const patchIamPolicy = async ({
+ member,
+ roles,
+ }: {
+ member: string;
+ roles: string[];
+ }) => {
+ const policy = await workspaceServiceClient.patchIamPolicy({
+ resource: "workspaces/-",
+ member,
+ roles,
+ });
+ workspaceIamPolicy.value = policy;
+ };
+
+ return {
+ workspaceIamPolicy,
+ fetchIamPolicy,
+ patchIamPolicy,
+ };
+});
+
+export const useWorkspaceIamPolicy = () => {
+ const store = useWorkspaceV1Store();
+
+ watchEffect(() => {
+ store.fetchIamPolicy();
+ });
+
+ return computed(() => store.workspaceIamPolicy);
+};
diff --git a/frontend/src/types/iam/role.ts b/frontend/src/types/iam/role.ts
index 8f73754e2b..3ea3d11824 100644
--- a/frontend/src/types/iam/role.ts
+++ b/frontend/src/types/iam/role.ts
@@ -1,13 +1,15 @@
+import { roleNamePrefix } from "@/store/modules/v1/common";
+
export const PresetRoleType = {
- WORKSPACE_ADMIN: "roles/workspaceAdmin",
- WORKSPACE_DBA: "roles/workspaceDBA",
- WORKSPACE_MEMBER: "roles/workspaceMember",
- PROJECT_OWNER: "roles/projectOwner",
- PROJECT_DEVELOPER: "roles/projectDeveloper",
- PROJECT_QUERIER: "roles/projectQuerier",
- PROJECT_EXPORTER: "roles/projectExporter",
- PROJECT_RELEASER: "roles/projectReleaser",
- PROJECT_VIEWER: "roles/projectViewer",
+ WORKSPACE_ADMIN: `${roleNamePrefix}workspaceAdmin`,
+ WORKSPACE_DBA: `${roleNamePrefix}workspaceDBA`,
+ WORKSPACE_MEMBER: `${roleNamePrefix}workspaceMember`,
+ PROJECT_OWNER: `${roleNamePrefix}projectOwner`,
+ PROJECT_DEVELOPER: `${roleNamePrefix}projectDeveloper`,
+ PROJECT_QUERIER: `${roleNamePrefix}projectQuerier`,
+ PROJECT_EXPORTER: `${roleNamePrefix}projectExporter`,
+ PROJECT_RELEASER: `${roleNamePrefix}projectReleaser`,
+ PROJECT_VIEWER: `${roleNamePrefix}projectViewer`,
};
export const PRESET_ROLES = Object.values(PresetRoleType);
diff --git a/frontend/src/types/proto/v1/auth_service.ts b/frontend/src/types/proto/v1/auth_service.ts
index a2b5409a9c..21faa6d187 100644
--- a/frontend/src/types/proto/v1/auth_service.ts
+++ b/frontend/src/types/proto/v1/auth_service.ts
@@ -223,12 +223,6 @@ export interface User {
* Could be empty.
*/
phone: string;
- /**
- * The roles of the user.
- * This filed is to supersede the `user_role` field.
- * TODO(ed): deprecate roles field.
- */
- roles: string[];
}
function createBaseGetUserRequest(): GetUserRequest {
@@ -1236,7 +1230,6 @@ function createBaseUser(): User {
mfaSecret: "",
recoveryCodes: [],
phone: "",
- roles: [],
};
}
@@ -1275,9 +1268,6 @@ export const User = {
if (message.phone !== "") {
writer.uint32(98).string(message.phone);
}
- for (const v of message.roles) {
- writer.uint32(106).string(v!);
- }
return writer;
},
@@ -1365,13 +1355,6 @@ export const User = {
message.phone = reader.string();
continue;
- case 13:
- if (tag !== 106) {
- break;
- }
-
- message.roles.push(reader.string());
- continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -1396,7 +1379,6 @@ export const User = {
? object.recoveryCodes.map((e: any) => globalThis.String(e))
: [],
phone: isSet(object.phone) ? globalThis.String(object.phone) : "",
- roles: globalThis.Array.isArray(object?.roles) ? object.roles.map((e: any) => globalThis.String(e)) : [],
};
},
@@ -1435,9 +1417,6 @@ export const User = {
if (message.phone !== "") {
obj.phone = message.phone;
}
- if (message.roles?.length) {
- obj.roles = message.roles;
- }
return obj;
},
@@ -1457,7 +1436,6 @@ export const User = {
message.mfaSecret = object.mfaSecret ?? "";
message.recoveryCodes = object.recoveryCodes?.map((e) => e) || [];
message.phone = object.phone ?? "";
- message.roles = object.roles?.map((e) => e) || [];
return message;
},
};
diff --git a/frontend/src/types/review.ts b/frontend/src/types/review.ts
index a597b58b8a..a85236510b 100644
--- a/frontend/src/types/review.ts
+++ b/frontend/src/types/review.ts
@@ -1,6 +1,6 @@
-import type { User } from "./proto/v1/auth_service";
import type { ApprovalStep, Issue_Approver } from "./proto/v1/issue_service";
import { ApprovalTemplate } from "./proto/v1/issue_service";
+import type { ComposedUser } from "./v1/user";
export type ApprovalEvent = {
status: "APPROVED" | "REJECTED" | "PENDING";
@@ -16,8 +16,8 @@ export type WrappedReviewStep = {
index: number;
step: ApprovalStep;
status: "APPROVED" | "REJECTED" | "CURRENT" | "PENDING";
- approver: User | undefined;
- candidates: User[];
+ approver: ComposedUser | undefined;
+ candidates: ComposedUser[];
};
export const emptyFlow = (): ReviewFlow => {
diff --git a/frontend/src/types/v1/issue/issue.ts b/frontend/src/types/v1/issue/issue.ts
index 34cb06afa9..a9a44a939d 100644
--- a/frontend/src/types/v1/issue/issue.ts
+++ b/frontend/src/types/v1/issue/issue.ts
@@ -1,4 +1,4 @@
-import type { ComposedProject } from "@/types";
+import type { ComposedProject, ComposedUser } from "@/types";
import {
EMPTY_PROJECT_NAME,
UNKNOWN_PROJECT_NAME,
@@ -8,7 +8,6 @@ import {
unknownUser,
} from "@/types";
import type { Rollout, TaskRun } from "@/types//proto/v1/rollout_service";
-import type { User } from "@/types/proto/v1/auth_service";
import { Issue, IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
import type { Plan, PlanCheckRun } from "@/types/proto/v1/plan_service";
import { EMPTY_ID, UNKNOWN_ID } from "../../const";
@@ -23,7 +22,7 @@ export interface ComposedIssue extends Issue {
rolloutTaskRunList: TaskRun[];
project: string;
projectEntity: ComposedProject;
- creatorEntity: User;
+ creatorEntity: ComposedUser;
}
export const ESTABLISH_BASELINE_SQL =
diff --git a/frontend/src/types/v1/issue/plan.ts b/frontend/src/types/v1/issue/plan.ts
index e499783115..d90cfab89d 100644
--- a/frontend/src/types/v1/issue/plan.ts
+++ b/frontend/src/types/v1/issue/plan.ts
@@ -1,6 +1,5 @@
-import { emptyUser, unknownUser } from "@/types";
+import { emptyUser, unknownUser, type ComposedUser } from "@/types";
import { EMPTY_ID, UNKNOWN_ID } from "@/types/const";
-import type { User } from "@/types/proto/v1/auth_service";
import {
Plan,
PlanCheckRun,
@@ -19,7 +18,7 @@ export interface ComposedPlan extends Plan {
planCheckRunList: PlanCheckRun[];
project: string;
projectEntity: ComposedProject;
- creatorEntity: User;
+ creatorEntity: ComposedUser;
}
export const EMPTY_PLAN_NAME = `projects/${EMPTY_ID}/plans/${EMPTY_ID}`;
diff --git a/frontend/src/types/v1/role.ts b/frontend/src/types/v1/role.ts
index fd2992947f..6960da9c30 100644
--- a/frontend/src/types/v1/role.ts
+++ b/frontend/src/types/v1/role.ts
@@ -1,10 +1,11 @@
+import { roleNamePrefix } from "@/store/modules/v1/common";
import { PresetRoleType } from "../iam";
export const VirtualRoleType = {
WORKSPACE_ADMIN: PresetRoleType.WORKSPACE_ADMIN,
WORKSPACE_DBA: PresetRoleType.WORKSPACE_DBA,
- LAST_APPROVER: "roles/LAST_APPROVER",
- CREATOR: "roles/CREATOR",
+ LAST_APPROVER: `${roleNamePrefix}LAST_APPROVER`,
+ CREATOR: `${roleNamePrefix}CREATOR`,
};
export const IssueReleaserRoleType = {
diff --git a/frontend/src/types/v1/user.ts b/frontend/src/types/v1/user.ts
index a049fef961..de115776a4 100644
--- a/frontend/src/types/v1/user.ts
+++ b/frontend/src/types/v1/user.ts
@@ -6,17 +6,24 @@ import { State } from "../proto/v1/common";
export const UNKNOWN_USER_NAME = `users/${UNKNOWN_ID}`;
export const SYSTEM_BOT_USER_NAME = `users/${SYSTEM_BOT_ID}`;
-export const emptyUser = () => {
- return User.fromJSON({
- name: `users/${EMPTY_ID}`,
- state: State.ACTIVE,
- email: "",
- title: "",
- userType: UserType.USER,
- });
+export interface ComposedUser extends User {
+ roles: string[];
+}
+
+export const emptyUser = (): ComposedUser => {
+ return {
+ ...User.fromPartial({
+ name: `users/${EMPTY_ID}`,
+ state: State.ACTIVE,
+ email: "",
+ title: "",
+ userType: UserType.USER,
+ }),
+ roles: [],
+ };
};
-export const unknownUser = () => {
+export const unknownUser = (): ComposedUser => {
return {
...emptyUser(),
name: UNKNOWN_USER_NAME,
@@ -27,7 +34,7 @@ export const unknownUser = () => {
export const ALL_USERS_USER_ID = "2";
export const ALL_USERS_USER_EMAIL = "allUsers";
// Pseudo allUsers account.
-export const allUsersUser = () => {
+export const allUsersUser = (): ComposedUser => {
return {
...emptyUser(),
name: `users/${ALL_USERS_USER_ID}`,
@@ -37,7 +44,10 @@ export const allUsersUser = () => {
};
};
-export const filterUserListByKeyword = (userList: User[], keyword: string) => {
+export const filterUserListByKeyword = (
+ userList: ComposedUser[],
+ keyword: string
+) => {
keyword = keyword.trim().toLowerCase();
if (!keyword) return userList;
return userList.filter((user) => {
diff --git a/frontend/src/utils/common.ts b/frontend/src/utils/common.ts
index 015a64e94e..76f7efbdfe 100644
--- a/frontend/src/utils/common.ts
+++ b/frontend/src/utils/common.ts
@@ -1,25 +1,21 @@
-import { User } from "@/types/proto/v1/auth_service";
+import { unknownUser, emptyUser, type ComposedUser } from "@/types";
import { Environment } from "@/types/proto/v1/environment_service";
export type ResourceType = "USER" | "ENVIRONMENT";
interface ResourceMaker {
- (type: "USER"): User;
+ (type: "USER"): ComposedUser;
(type: "ENVIRONMENT"): Environment;
}
const makeUnknown = (type: ResourceType) => {
- const UNKNOWN_USER: User = User.fromPartial({
- title: "<<Unknown user>>",
- });
-
const UNKNOWN_ENVIRONMENT: Environment = Environment.fromPartial({
title: "<<Unknown environment>>",
});
switch (type) {
case "USER":
- return UNKNOWN_USER;
+ return unknownUser();
case "ENVIRONMENT":
return UNKNOWN_ENVIRONMENT;
}
@@ -28,13 +24,11 @@ const makeUnknown = (type: ResourceType) => {
export const unknown = makeUnknown as ResourceMaker;
const makeEmpty = (type: ResourceType) => {
- const EMPTY_USER: User = User.fromPartial({});
-
const EMPTY_ENVIRONMENT: Environment = Environment.fromPartial({});
switch (type) {
case "USER":
- return EMPTY_USER;
+ return emptyUser();
case "ENVIRONMENT":
return EMPTY_ENVIRONMENT;
}
diff --git a/frontend/src/utils/iam/permission-utils.ts b/frontend/src/utils/iam/permission-utils.ts
index 5f83e0b333..400db614d7 100644
--- a/frontend/src/utils/iam/permission-utils.ts
+++ b/frontend/src/utils/iam/permission-utils.ts
@@ -1,16 +1,15 @@
-import type { ComposedDatabase, ComposedProject } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedDatabase, ComposedProject, ComposedUser } from "@/types";
import { hasProjectPermissionV2 } from "./permission";
export const hasPermissionToCreateRequestGrantIssueInProject = (
project: ComposedProject,
- user: User
+ user: ComposedUser
) => {
return hasProjectPermissionV2(project, user, "bb.issues.create");
};
export const hasPermissionToCreateRequestGrantIssue = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
) => {
return hasPermissionToCreateRequestGrantIssueInProject(
database.projectEntity,
@@ -20,7 +19,7 @@ export const hasPermissionToCreateRequestGrantIssue = (
export const hasPermissionToCreateChangeDatabaseIssueInProject = (
project: ComposedProject,
- user: User
+ user: ComposedUser
) => {
return (
hasProjectPermissionV2(project, user, "bb.issues.create") &&
@@ -30,7 +29,7 @@ export const hasPermissionToCreateChangeDatabaseIssueInProject = (
};
export const hasPermissionToCreateChangeDatabaseIssue = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
) => {
return hasPermissionToCreateChangeDatabaseIssueInProject(
database.projectEntity,
@@ -40,7 +39,7 @@ export const hasPermissionToCreateChangeDatabaseIssue = (
export const hasPermissionToCreateDataExportIssueInProject = (
project: ComposedProject,
- user: User
+ user: ComposedUser
) => {
return (
hasProjectPermissionV2(project, user, "bb.issues.create") &&
@@ -50,7 +49,7 @@ export const hasPermissionToCreateDataExportIssueInProject = (
};
export const hasPermissionToCreateDataExportIssue = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
) => {
return hasPermissionToCreateDataExportIssueInProject(
database.projectEntity,
@@ -60,13 +59,13 @@ export const hasPermissionToCreateDataExportIssue = (
export const hasPermissionToCreatePlanInProject = (
project: ComposedProject,
- user: User
+ user: ComposedUser
) => {
return hasProjectPermissionV2(project, user, "bb.plans.create");
};
export const hasPermissionToCreateReviewIssueIssue = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
) => {
return hasPermissionToCreatePlanInProject(database.projectEntity, user);
};
diff --git a/frontend/src/utils/iam/permission.ts b/frontend/src/utils/iam/permission.ts
index da16486a33..1adac3b949 100644
--- a/frontend/src/utils/iam/permission.ts
+++ b/frontend/src/utils/iam/permission.ts
@@ -3,11 +3,11 @@ import type {
ComposedProject,
ProjectPermission,
WorkspacePermission,
+ ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
export const hasWorkspacePermissionV2 = (
- user: User,
+ user: ComposedUser,
permission: WorkspacePermission
): boolean => {
const permissions =
@@ -18,7 +18,7 @@ export const hasWorkspacePermissionV2 = (
// hasProjectPermissionV2 checks if the user has the given permission on the project.
export const hasProjectPermissionV2 = (
project: ComposedProject | undefined,
- user: User,
+ user: ComposedUser,
permission: ProjectPermission
): boolean => {
const permissionStore = usePermissionStore();
@@ -46,7 +46,7 @@ export const hasProjectPermissionV2 = (
// hasWorkspaceLevelProjectPermission checks if the user has the given permission on workspace-level-assigned project roles
export const hasWorkspaceLevelProjectPermission = (
- user: User,
+ user: ComposedUser,
permission: ProjectPermission
): boolean => {
const permissions =
@@ -56,7 +56,7 @@ export const hasWorkspaceLevelProjectPermission = (
// hasWorkspaceLevelProjectPermission checks if the user has the given permission on ANY project in the workspace.
export const hasWorkspaceLevelProjectPermissionInAnyProject = (
- user: User,
+ user: ComposedUser,
permission: ProjectPermission
): boolean => {
const { projectList } = useProjectV1List();
diff --git a/frontend/src/utils/v1/database.ts b/frontend/src/utils/v1/database.ts
index 4d6dc01b46..60579e9b91 100644
--- a/frontend/src/utils/v1/database.ts
+++ b/frontend/src/utils/v1/database.ts
@@ -10,8 +10,7 @@ import {
instanceNamePrefix,
} from "@/store/modules/v1/common";
import { UNKNOWN_ID } from "@/types";
-import type { ComposedDatabase } from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
+import type { ComposedDatabase, ComposedUser } from "@/types";
import { Engine, State } from "@/types/proto/v1/common";
import { DataSourceType } from "@/types/proto/v1/instance_service";
import {
@@ -83,7 +82,7 @@ export const isArchivedDatabaseV1 = (db: ComposedDatabase): boolean => {
// isDatabaseV1Alterable checks if database alterable for user.
export const isDatabaseV1Alterable = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
): boolean => {
if (!hasFeature("bb.feature.access-control")) {
// The current plan doesn't have access control feature.
@@ -109,7 +108,7 @@ export const isDatabaseV1Alterable = (
// isDatabaseV1Queryable checks if database allowed to query in SQL Editor.
export const isDatabaseV1Queryable = (
database: ComposedDatabase,
- user: User
+ user: ComposedUser
): boolean => {
if (!hasFeature("bb.feature.access-control")) {
// The current plan doesn't have access control feature.
@@ -135,7 +134,7 @@ export const isTableQueryable = (
database: ComposedDatabase,
schema: string,
table: string,
- user: User
+ user: ComposedUser
): boolean => {
if (hasWorkspaceLevelProjectPermission(user, "bb.databases.query")) {
// The current user has the super privilege to access all databases.
@@ -219,7 +218,7 @@ export function allowGhostMigrationV1(
export function allowDatabaseV1Access(
database: ComposedDatabase,
- user: User,
+ user: ComposedUser,
type: DataSourceType
): boolean {
// "ADMIN" data source should only be used by the system, thus it shouldn't
diff --git a/frontend/src/utils/v1/iam.ts b/frontend/src/utils/v1/iam.ts
new file mode 100644
index 0000000000..6568e50914
--- /dev/null
+++ b/frontend/src/utils/v1/iam.ts
@@ -0,0 +1,154 @@
+import { orderBy, uniq } from "lodash-es";
+import { extractUserEmail, useUserStore, useUserGroupStore } from "@/store";
+import { userNamePrefix, roleNamePrefix } from "@/store/modules/v1/common";
+import {
+ ALL_USERS_USER_EMAIL,
+ PresetRoleType,
+ groupBindingPrefix,
+ PRESET_WORKSPACE_ROLES,
+ type ComposedUser,
+ unknownUser,
+} from "@/types";
+import { getUserEmailInBinding } from "@/types";
+import type { IamPolicy, Binding } from "@/types/proto/v1/iam_policy";
+import { convertFromExpr } from "@/utils/issue/cel";
+
+export const isBindingPolicyExpired = (binding: Binding): boolean => {
+ if (binding.parsedExpr?.expr) {
+ const conditionExpr = convertFromExpr(binding.parsedExpr.expr);
+ if (conditionExpr.expiredTime) {
+ const expiration = new Date(conditionExpr.expiredTime);
+ if (expiration < new Date()) {
+ return true;
+ }
+ }
+ }
+ return false;
+};
+
+export const getUserEmailListInBinding = (binding: Binding): string[] => {
+ if (isBindingPolicyExpired(binding)) {
+ return [];
+ }
+
+ const groupStore = useUserGroupStore();
+ const userStore = useUserStore();
+ const emailList = [];
+
+ for (const member of binding.members) {
+ if (member.startsWith(groupBindingPrefix)) {
+ const group = groupStore.getGroupByIdentifier(member);
+ if (!group) {
+ continue;
+ }
+
+ emailList.push(...group.members.map((m) => extractUserEmail(m.member)));
+ } else {
+ const email = extractUserEmail(member);
+ if (email === ALL_USERS_USER_EMAIL) {
+ return userStore.activeUserList.map((user) => user.email);
+ } else {
+ emailList.push(email);
+ }
+ }
+ }
+ return uniq(emailList);
+};
+
+export const memberListInIAM = (iamPolicy: IamPolicy) => {
+ const userStore = useUserStore();
+
+ const emailList = [];
+ // rolesMapByEmail is Map<email, role list>
+ const rolesMapByEmail = new Map<string, Set<string>>();
+ for (const binding of iamPolicy.bindings) {
+ if (isBindingPolicyExpired(binding)) {
+ continue;
+ }
+
+ const emails = getUserEmailListInBinding(binding);
+
+ for (const email of emails) {
+ if (!rolesMapByEmail.has(email)) {
+ rolesMapByEmail.set(email, new Set());
+ }
+ rolesMapByEmail.get(email)?.add(binding.role);
+ }
+ emailList.push(...emails);
+ }
+
+ for (const workspaceLevelProjectMember of userStore.workspaceLevelProjectMembers) {
+ emailList.push(workspaceLevelProjectMember.email);
+ if (!rolesMapByEmail.has(workspaceLevelProjectMember.email)) {
+ rolesMapByEmail.set(workspaceLevelProjectMember.email, new Set());
+ }
+ for (const role of workspaceLevelProjectMember.roles) {
+ if (PRESET_WORKSPACE_ROLES.includes(role)) {
+ continue;
+ }
+ rolesMapByEmail.get(workspaceLevelProjectMember.email)?.add(role);
+ }
+ }
+
+ const distinctEmailList = uniq(emailList);
+ const userList = distinctEmailList.map((email) => {
+ const user: ComposedUser = userStore.getUserByEmail(email) ?? unknownUser();
+ return user;
+ });
+
+ const composedUserList = userList.map((user) => {
+ const roleList = rolesMapByEmail.get(user.email) ?? new Set<string>();
+ return { user, roleList: [...roleList] };
+ });
+
+ return orderBy(
+ composedUserList,
+ [
+ (item) => (item.roleList.includes(PresetRoleType.PROJECT_OWNER) ? 0 : 1),
+ (item) => item.user.email,
+ ],
+ ["asc", "asc"]
+ );
+};
+
+export const roleListInIAM = (iamPolicy: IamPolicy, email: string) => {
+ const groupStore = useUserGroupStore();
+ const userInBinding = getUserEmailInBinding(email);
+
+ const roles = iamPolicy.bindings
+ .filter((binding) => {
+ if (binding.role === PresetRoleType.WORKSPACE_MEMBER) {
+ return false;
+ }
+ if (isBindingPolicyExpired(binding)) {
+ return false;
+ }
+ for (const member of binding.members) {
+ if (member === ALL_USERS_USER_EMAIL) {
+ return true;
+ }
+ if (member === userInBinding) {
+ return true;
+ }
+
+ if (member.startsWith(groupBindingPrefix)) {
+ const group = groupStore.getGroupByIdentifier(member);
+ if (!group) {
+ continue;
+ }
+
+ return group.members.some(
+ (m) => m.member === `${userNamePrefix}${email}`
+ );
+ }
+ }
+ return false;
+ })
+ .map((binding) => binding.role);
+
+ if (!roles.some((role) => role.startsWith(`${roleNamePrefix}workspace`))) {
+ roles.push(PresetRoleType.WORKSPACE_MEMBER);
+ }
+
+ return roles;
+};
diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.ts
index 8f048450e8..c0c2ad61a1 100644
--- a/frontend/src/utils/v1/index.ts
+++ b/frontend/src/utils/v1/index.ts
@@ -17,3 +17,4 @@ export * from "./changeHistory";
export * from "./changelist";
export * from "./cel";
export * from "./advanced-search";
+export * from "./iam";
diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.ts
index 197485cd07..6cf1216773 100644
--- a/frontend/src/utils/v1/project.ts
+++ b/frontend/src/utils/v1/project.ts
@@ -1,33 +1,12 @@
-import { orderBy, uniq } from "lodash-es";
-import { extractUserEmail, useUserStore, useUserGroupStore } from "@/store";
import { usePermissionStore } from "@/store/modules/v1/permission";
import {
- ALL_USERS_USER_EMAIL,
DEFAULT_PROJECT_NAME,
- UNKNOWN_ID,
PresetRoleType,
- groupBindingPrefix,
- PRESET_WORKSPACE_ROLES,
type ComposedProject,
+ type ComposedUser,
} from "@/types";
-import { User } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
-import type { IamPolicy, Binding } from "@/types/proto/v1/iam_policy";
import type { Project } from "@/types/proto/v1/project_service";
-import { convertFromExpr } from "@/utils/issue/cel";
-
-export const isBindingPolicyExpired = (binding: Binding): boolean => {
- if (binding.parsedExpr?.expr) {
- const conditionExpr = convertFromExpr(binding.parsedExpr.expr);
- if (conditionExpr.expiredTime) {
- const expiration = new Date(conditionExpr.expiredTime);
- if (expiration < new Date()) {
- return true;
- }
- }
- }
- return false;
-};
export const extractProjectResourceName = (name: string) => {
const pattern = /(?:^|\/)projects\/([^/]+)(?:$|\/)/;
@@ -35,11 +14,17 @@ export const extractProjectResourceName = (name: string) => {
return matches?.[1] ?? "";
};
-export const isMemberOfProjectV1 = (project: ComposedProject, user: User) => {
+export const isMemberOfProjectV1 = (
+ project: ComposedProject,
+ user: ComposedUser
+) => {
return usePermissionStore().roleListInProjectV1(project, user).length > 0;
};
-export const isOwnerOfProjectV1 = (project: ComposedProject, user: User) => {
+export const isOwnerOfProjectV1 = (
+ project: ComposedProject,
+ user: ComposedUser
+) => {
return usePermissionStore()
.roleListInProjectV1(project, user)
.includes(PresetRoleType.PROJECT_OWNER);
@@ -47,110 +32,22 @@ export const isOwnerOfProjectV1 = (project: ComposedProject, user: User) => {
export const isDeveloperOfProjectV1 = (
project: ComposedProject,
- user: User
+ user: ComposedUser
) => {
return usePermissionStore()
.roleListInProjectV1(project, user)
.includes(PresetRoleType.PROJECT_DEVELOPER);
};
-export const isViewerOfProjectV1 = (project: ComposedProject, user: User) => {
+export const isViewerOfProjectV1 = (
+ project: ComposedProject,
+ user: ComposedUser
+) => {
return usePermissionStore()
.roleListInProjectV1(project, user)
.includes(PresetRoleType.PROJECT_VIEWER);
};
-export const getUserEmailListInBinding = (binding: Binding): string[] => {
- if (isBindingPolicyExpired(binding)) {
- return [];
- }
-
- const groupStore = useUserGroupStore();
- const userStore = useUserStore();
- const emailList = [];
-
- for (const member of binding.members) {
- if (member.startsWith(groupBindingPrefix)) {
- const group = groupStore.getGroupByIdentifier(member);
- if (!group) {
- continue;
- }
-
- emailList.push(...group.members.map((m) => extractUserEmail(m.member)));
- } else {
- const email = extractUserEmail(member);
- if (email === ALL_USERS_USER_EMAIL) {
- return userStore.activeUserList.map((user) => user.email);
- } else {
- emailList.push(email);
- }
- }
- }
- return uniq(emailList);
-};
-
-export const memberListInProjectV1 = (iamPolicy: IamPolicy) => {
- const userStore = useUserStore();
-
- const emailList = [];
- // rolesMapByEmail is Map<email, role list>
- const rolesMapByEmail = new Map<string, Set<string>>();
- for (const binding of iamPolicy.bindings) {
- if (isBindingPolicyExpired(binding)) {
- continue;
- }
-
- const emails = getUserEmailListInBinding(binding);
-
- for (const email of emails) {
- if (!rolesMapByEmail.has(email)) {
- rolesMapByEmail.set(email, new Set());
- }
- rolesMapByEmail.get(email)?.add(binding.role);
- }
- emailList.push(...emails);
- }
-
- for (const workspaceLevelProjectMember of userStore.workspaceLevelProjectMembers) {
- emailList.push(workspaceLevelProjectMember.email);
- if (!rolesMapByEmail.has(workspaceLevelProjectMember.email)) {
- rolesMapByEmail.set(workspaceLevelProjectMember.email, new Set());
- }
- for (const role of workspaceLevelProjectMember.roles) {
- if (PRESET_WORKSPACE_ROLES.includes(role)) {
- continue;
- }
- rolesMapByEmail.get(workspaceLevelProjectMember.email)?.add(role);
- }
- }
-
- const distinctEmailList = uniq(emailList);
- const userList = distinctEmailList.map((email) => {
- const user =
- userStore.getUserByEmail(email) ??
- User.fromJSON({
- name: `users/${UNKNOWN_ID}`,
- email,
- title: "<<Unknown user>>",
- });
- return user;
- });
-
- const composedUserList = userList.map((user) => {
- const roleList = rolesMapByEmail.get(user.email) ?? new Set<string>();
- return { user, roleList: [...roleList] };
- });
-
- return orderBy(
- composedUserList,
- [
- (item) => (item.roleList.includes(PresetRoleType.PROJECT_OWNER) ? 0 : 1),
- (item) => item.user.email,
- ],
- ["asc", "asc"]
- );
-};
-
export function projectV1Name(project: Project) {
if (project.name === DEFAULT_PROJECT_NAME) {
return "Unassigned";
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 0c820e4a7b..1b9acb8a47 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -265,14 +265,14 @@ import {
unknownUser,
SYSTEM_BOT_USER_NAME,
ALL_USERS_USER_EMAIL,
+ type ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { UpdateUserRequest, UserType } from "@/types/proto/v1/auth_service";
import { displayRoleTitle, hasWorkspacePermissionV2, sortRoles } from "@/utils";
interface LocalState {
editing: boolean;
- editingUser?: User;
+ editingUser?: ComposedUser;
passwordConfirm: string;
showFeatureModal: boolean;
showDisable2FAConfirmModal: boolean;
@@ -379,7 +379,10 @@ onMounted(async () => {
}
});
-const updateUser = <K extends keyof User>(field: K, value: User[K]) => {
+const updateUser = <K extends keyof ComposedUser>(
+ field: K,
+ value: ComposedUser[K]
+) => {
if (!state.editingUser) return;
state.editingUser[field] = value;
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index 371c3fc4f7..62e0a5996a 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -182,8 +182,8 @@ import {
ALL_USERS_USER_EMAIL,
PresetRoleType,
filterUserListByKeyword,
+ type ComposedUser,
} from "@/types";
-import type { User } from "@/types/proto/v1/auth_service";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import { WorkspaceProfileSetting } from "@/types/proto/v1/setting_service";
@@ -203,7 +203,7 @@ type LocalState = {
showInactiveUserList: boolean;
showCreateUserDrawer: boolean;
showCreateGroupDrawer: boolean;
- editingUser?: User;
+ editingUser?: ComposedUser;
editingGroup?: UserGroup;
};
@@ -383,7 +383,7 @@ const handleCreateUser = () => {
state.showCreateUserDrawer = true;
};
-const handleUpdateUser = (user: User) => {
+const handleUpdateUser = (user: ComposedUser) => {
state.editingUser = user;
state.showCreateUserDrawer = true;
};
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index fa5400fd52..c8a71a8580 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -14079,14 +14079,6 @@ components:
description: |-
Should be a valid E.164 compliant phone number.
Could be empty.
- roles:
- type: array
- items:
- type: string
- description: |-
- The roles of the user.
- This filed is to supersede the `user_role` field.
- TODO(ed): deprecate roles field.
UserGroup:
type: object
properties:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 9eb67d1b1a..0390663729 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -1535,7 +1535,6 @@ The user&#39;s `name` field is used to identify the user to update. Format: user
| mfa_secret | [string](#string) | | The mfa_secret is the temporary secret using in two phase verification. |
| recovery_codes | [string](#string) | repeated | The recovery_codes is the temporary recovery codes using in two phase verification. |
| phone | [string](#string) | | Should be a valid E.164 compliant phone number. Could be empty. |
-| roles | [string](#string) | repeated | The roles of the user. This filed is to supersede the `user_role` field. TODO(ed): deprecate roles field. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 83e18cf23e..8807803eea 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -4949,15 +4949,6 @@ Format: users/{user}. {user} is a system-generated unique ID. </p></td>
Could be empty. </p></td>
</tr>
- <tr>
- <td>roles</td>
- <td><a href="#string">string</a></td>
- <td>repeated</td>
- <td><p>The roles of the user.
-This filed is to supersede the `user_role` field.
-TODO(ed): deprecate roles field. </p></td>
- </tr>
-
</tbody>
</table>
diff --git a/proto/generated-go/v1/auth_service.pb.go b/proto/generated-go/v1/auth_service.pb.go
index 0c5f6dcf60..94414cf024 100644
--- a/proto/generated-go/v1/auth_service.pb.go
+++ b/proto/generated-go/v1/auth_service.pb.go
@@ -881,10 +881,6 @@ type User struct {
// Should be a valid E.164 compliant phone number.
// Could be empty.
Phone string `protobuf:"bytes,12,opt,name=phone,proto3" json:"phone,omitempty"`
- // The roles of the user.
- // This filed is to supersede the `user_role` field.
- // TODO(ed): deprecate roles field.
- Roles []string `protobuf:"bytes,13,rep,name=roles,proto3" json:"roles,omitempty"`
}
func (x *User) Reset() {
@@ -996,13 +992,6 @@ func (x *User) GetPhone() string {
return ""
}
-func (x *User) GetRoles() []string {
- if x != nil {
- return x.Roles
- }
- return nil
-}
-
var File_v1_auth_service_proto protoreflect.FileDescriptor
var file_v1_auth_service_proto_rawDesc = []byte{
@@ -1111,7 +1100,7 @@ var file_v1_auth_service_proto_rawDesc = []byte{
0x66, 0x61, 0x54, 0x65, 0x6d, 0x70, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01, 0x01, 0x42, 0x11,
0x0a, 0x0f, 0x5f, 0x6d, 0x66, 0x61, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x74, 0x6f, 0x6b, 0x65,
0x6e, 0x22, 0x0f, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
- 0x73, 0x74, 0x22, 0x8c, 0x03, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x04, 0x6e,
+ 0x73, 0x74, 0x22, 0xfc, 0x02, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x03, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,
@@ -1134,9 +1123,8 @@ var file_v1_auth_service_proto_rawDesc = []byte{
0x76, 0x65, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09,
0x52, 0x0d, 0x72, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x73, 0x12,
0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
- 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x18, 0x0d,
- 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x4a, 0x04, 0x08, 0x06, 0x10,
- 0x07, 0x2a, 0x54, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a,
+ 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4a, 0x04, 0x08, 0x06, 0x10, 0x07, 0x4a, 0x04, 0x08, 0x0d, 0x10,
+ 0x0e, 0x2a, 0x54, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a,
0x15, 0x55, 0x53, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45,
0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x55, 0x53, 0x45, 0x52,
0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x42, 0x4f, 0x54,
diff --git a/proto/v1/auth_service.proto b/proto/v1/auth_service.proto
index 0ec377ab13..0402eabe38 100644
--- a/proto/v1/auth_service.proto
+++ b/proto/v1/auth_service.proto
@@ -183,7 +183,7 @@ message LoginResponse {
message LogoutRequest {}
message User {
- reserved 6;
+ reserved 6, 13;
// The name of the user.
// Format: users/{user}. {user} is a system-generated unique ID.
@@ -213,11 +213,6 @@ message User {
// Should be a valid E.164 compliant phone number.
// Could be empty.
string phone = 12;
-
- // The roles of the user.
- // This filed is to supersede the `user_role` field.
- // TODO(ed): deprecate roles field.
- repeated string roles = 13;
}
enum UserType {