diff --git a/web/src/api/buster_rest/users/requests.ts b/web/src/api/buster_rest/users/requests.ts index dd9a5531c..e70d6ae9c 100644 --- a/web/src/api/buster_rest/users/requests.ts +++ b/web/src/api/buster_rest/users/requests.ts @@ -49,7 +49,7 @@ export const updateOrganizationUser = async ({ }: { userId: string; name?: string; - role: OrganizationUser['role']; + role?: OrganizationUser['role']; }) => { return mainApi .put(`/users/${userId}`, params) diff --git a/web/src/api/buster_socket/index.ts b/web/src/api/buster_socket/index.ts index 2443c2636..a1cd2095a 100644 --- a/web/src/api/buster_socket/index.ts +++ b/web/src/api/buster_socket/index.ts @@ -7,11 +7,6 @@ import type { CollectionResponseTypes, CollectionResponses, CollectionsEmit } fr import type { TeamEmits, TeamResponses, TeamResponsesTypes } from './teams'; import type { DatasourceResponseTypes, DatasourceResponses, DatasourceEmits } from './datasources'; import type { TermsEmits, TermsResponses, TermsResponseTypes } from './terms'; -import type { - PermissionsEmits, - PermissionsResponses, - PermissionsResponseTypes -} from './permissions'; import type { BusterSearchEmits, SearchResponses, SearchResponseTypes } from './search'; import type { OrganizationResponses, @@ -30,7 +25,6 @@ export type BusterSocketRequest = | DatasourceEmits | SQLEmits | TermsEmits - | PermissionsEmits | BusterSearchEmits | OrganizationsEmits | ChatEmits; @@ -45,7 +39,6 @@ export type BusterSocketResponse = | DatasourceResponseTypes | SQLResponsesTypes | TermsResponseTypes - | PermissionsResponseTypes | SearchResponseTypes | OrganizationResponsesTypes | ChatResponseTypes; @@ -60,7 +53,6 @@ export type BusterSocketResponseRoute = | keyof typeof DatasourceResponses | keyof typeof SQLResponses | keyof typeof TermsResponses - | keyof typeof PermissionsResponses | keyof typeof SearchResponses | keyof typeof OrganizationResponses | keyof typeof ChatsResponses; diff --git a/web/src/api/buster_socket/permissions/index.ts b/web/src/api/buster_socket/permissions/index.ts deleted file mode 100644 index cb139a173..000000000 --- a/web/src/api/buster_socket/permissions/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './permissionRequests'; -export * from './permissionResponses'; diff --git a/web/src/api/buster_socket/permissions/permissionRequests.ts b/web/src/api/buster_socket/permissions/permissionRequests.ts deleted file mode 100644 index 725bf9387..000000000 --- a/web/src/api/buster_socket/permissions/permissionRequests.ts +++ /dev/null @@ -1,310 +0,0 @@ -import type { BusterOrganizationRole } from '../../asset_interfaces'; -import type { BusterSocketRequestBase } from '../base_interfaces'; -import type { BusterPermissionUser } from '@/api/asset_interfaces'; - -/** - * Request to list users with pagination and optional filtering - * @param page Current page number - * @param page_size Number of items per page - * @param team_id Optional team ID to filter users - * @param permission_group_id Optional permission group ID to filter users - * @param belongs_to Optional boolean to filter by belonging status - */ -export type PermissionsListUsersRequest = BusterSocketRequestBase< - '/permissions/users/list', - { - /** Current page number */ - page: number; - /** Number of items per page */ - page_size: number; - /** Optional team ID to filter users */ - team_id?: string; - /** Optional permission group ID to filter users */ - permission_group_id?: string; - /** Optional boolean to filter by belonging status */ - belongs_to?: boolean | null; - } ->; - -/** - * Request to get a specific user's permissions - * @param id User ID to retrieve - */ -export type PermissionUserRequest = BusterSocketRequestBase< - '/permissions/users/get', - { - /** User ID to retrieve */ - id: string; - } ->; - -/** - * Request to update a user's permissions and settings - * @param id User ID to update - * @param sharing_setting Optional sharing settings configuration - * @param edit_sql Optional permission to edit SQL - * @param upload_csv Optional permission to upload CSV files - * @param export_assets Optional permission to export assets - * @param email_slack_enabled Optional setting for email/slack notifications - * @param teams Optional array of team assignments with roles - * @param permission_groups Optional array of permission group IDs - * @param name Optional user name - */ -export type PermissionUserUpdateRequest = BusterSocketRequestBase< - '/permissions/users/update', - { - /** User ID to update */ - id: string; - /** Optional sharing settings configuration */ - sharing_setting?: BusterPermissionUser['sharing_setting']; - /** Optional permission to edit SQL */ - edit_sql?: boolean; - /** Optional permission to upload CSV files */ - upload_csv?: boolean; - /** Optional permission to export assets */ - export_assets?: boolean; - /** Optional setting for email/slack notifications */ - email_slack_enabled?: boolean; - /** Optional array of team assignments with roles */ - teams?: { - /** Team ID */ - id: string; - /** Organization role for the team */ - role: BusterOrganizationRole; - }[]; - /** Optional array of permission group IDs */ - permission_groups?: string[]; - /** Optional user name */ - name?: string; - } ->; - -/** - * Request to get a specific permission group - * @param id Permission group ID to retrieve - */ -export type PermissionGetPermissionGroup = BusterSocketRequestBase< - '/permissions/groups/get', - { - /** Permission group ID to retrieve */ - id: string; - } ->; - -/** - * Request to list permission groups with pagination and filtering - * @param page Current page number - * @param page_size Number of items per page - * @param team_id Optional team ID to filter groups - * @param user_id Optional user ID to filter groups - * @param belongs_to Optional boolean to filter by belonging status - */ -export type PermissionsListGroupRequest = BusterSocketRequestBase< - '/permissions/groups/list', - { - /** Current page number */ - page: number; - /** Number of items per page */ - page_size: number; - /** Optional team ID to filter groups */ - team_id?: string; - /** Optional user ID to filter groups */ - user_id?: string; - /** Optional boolean to filter by belonging status */ - belongs_to?: boolean | null; - } ->; - -/** - * Request to create a new permission group - * @param name Name of the new permission group - */ -export type PermissionPostGroupRequest = BusterSocketRequestBase< - '/permissions/groups/post', - { - /** Name of the new permission group */ - name: string; - } ->; - -/** - * Request to get a specific team's permissions - * @param id Team ID to retrieve - */ -export type PermissionGetPermissionTeam = BusterSocketRequestBase< - '/permissions/teams/get', - { - /** Team ID to retrieve */ - id: string; - } ->; - -/** - * Request to update a permission group - * @param id Permission group ID to update - * @param name Optional new name for the group - * @param users Optional array of user IDs (null for no changes, empty to clear) - * @param teams Optional array of team IDs (null for no changes, empty to clear) - * @param datasets Optional array of dataset IDs (null for no changes, empty to clear) - */ -export type PermissionGroupUpdateRequest = BusterSocketRequestBase< - '/permissions/groups/update', - { - /** Permission group ID to update */ - id: string; - /** Optional new name for the group */ - name?: string; - /** Optional array of user IDs (null for no changes, empty to clear) */ - users?: null | string[]; - /** Optional array of team IDs (null for no changes, empty to clear) */ - teams?: string[]; - /** Optional array of dataset IDs (null for no changes, empty to clear) */ - datasets?: string[]; - } ->; - -/** - * Request to list teams with pagination and filtering - * @param page Current page number - * @param page_size Number of items per page - * @param user_id Optional user ID to filter teams - * @param permission_group_id Optional permission group ID to filter teams - * @param belongs_to Optional boolean to filter by belonging status - */ -export type PermissionListTeamRequest = BusterSocketRequestBase< - '/permissions/teams/list', - { - /** Current page number */ - page: number; - /** Number of items per page */ - page_size: number; - /** Optional user ID to filter teams */ - user_id?: string; - /** Optional permission group ID to filter teams */ - permission_group_id?: string; - /** Optional boolean to filter by belonging status */ - belongs_to?: boolean | null; - } ->; - -/** - * Request to create a new team - * @param name Name of the new team - * @param description Optional description of the team - */ -export type PermissionPostTeamRequest = BusterSocketRequestBase< - '/permissions/teams/post', - { - /** Name of the new team */ - name: string; - /** Optional description of the team */ - description?: string; - } ->; - -/** - * Request to create a new user - * @param email Email address of the new user - * @param role Organization role for the new user - */ -export type PermissionPostUserRequest = BusterSocketRequestBase< - '/permissions/users/post', - { - /** Email address of the new user */ - email: string; - /** Organization role for the new user */ - role: BusterOrganizationRole; - } ->; - -/** - * Request to update a team's settings and members - * @param id Team ID to update - * @param sharing_setting Optional sharing settings configuration - * @param edit_sql Optional permission to edit SQL - * @param upload_csv Optional permission to upload CSV files - * @param export_assets Optional permission to export assets - * @param email_slack_enabled Optional setting for email/slack notifications - * @param teams Optional array of team assignments with roles - * @param permission_groups Optional array of permission group IDs - * @param name Optional team name - * @param users Optional array of user IDs and their roles - */ -export type PermissionTeamUpdateRequest = BusterSocketRequestBase< - '/permissions/teams/update', - { - /** Team ID to update */ - id: string; - /** Optional sharing settings configuration */ - sharing_setting?: BusterPermissionUser['sharing_setting']; - /** Optional permission to edit SQL */ - edit_sql?: boolean; - /** Optional permission to upload CSV files */ - upload_csv?: boolean; - /** Optional permission to export assets */ - export_assets?: boolean; - /** Optional setting for email/slack notifications */ - email_slack_enabled?: boolean; - /** Optional array of team assignments with roles */ - teams?: { - /** Team ID */ - id: string; - /** Organization role for the team */ - role: BusterOrganizationRole; - }[]; - /** Optional array of permission group IDs */ - permission_groups?: string[]; - /** Optional team name */ - name?: string; - /** Optional array of user IDs and their roles */ - users?: { - /** User ID */ - id: string; - /** Organization role for the user */ - role: BusterOrganizationRole; - }[]; - } ->; - -/** - * Request to delete permission groups - * @param ids Array of permission group IDs to delete - */ -export type PermissionGroupDeleteRequest = BusterSocketRequestBase< - '/permissions/groups/delete', - { - /** Array of permission group IDs to delete */ - ids: string[]; - } ->; - -/** - * Request to delete teams - * @param ids Array of team IDs to delete - */ -export type PermissionTeamDeleteRequest = BusterSocketRequestBase< - '/permissions/teams/delete', - { - /** Array of team IDs to delete */ - ids: string[]; - } ->; - -/** - * Union type of all permission-related requests - */ -export type PermissionsEmits = - | PermissionTeamDeleteRequest - | PermissionsListUsersRequest - | PermissionUserRequest - | PermissionGetPermissionGroup - | PermissionGetPermissionTeam - | PermissionsListGroupRequest - | PermissionListTeamRequest - | PermissionPostGroupRequest - | PermissionPostTeamRequest - | PermissionPostUserRequest - | PermissionGroupUpdateRequest - | PermissionUserUpdateRequest - | PermissionTeamUpdateRequest - | PermissionGroupDeleteRequest; diff --git a/web/src/api/buster_socket/permissions/permissionResponses.ts b/web/src/api/buster_socket/permissions/permissionResponses.ts deleted file mode 100644 index a2c6567fd..000000000 --- a/web/src/api/buster_socket/permissions/permissionResponses.ts +++ /dev/null @@ -1,117 +0,0 @@ -import type { - BusterPermissionGroup, - BusterPermissionListGroup, - BusterPermissionListTeam, - BusterPermissionListUser, - BusterPermissionTeam, - BusterPermissionUser -} from '@/api/asset_interfaces'; - -export enum PermissionsResponses { - '/permissions/users/list:listUserPermissions' = '/permissions/users/list:listUserPermissions', - '/permissions/users/get:getUserPermissions' = '/permissions/users/get:getUserPermissions', - '/permissions/users/update:updateUserPermission' = '/permissions/users/update:updateUserPermission', - '/permissions/groups/list:listPermissionGroups' = '/permissions/groups/list:listPermissionGroups', - '/permissions/groups/update:updatePermissionGroup' = '/permissions/groups/update:updatePermissionGroup', - '/permissions/groups/get:getPermissionGroup' = '/permissions/groups/get:getPermissionGroup', - '/permissions/groups/post:postPermissionGroup' = '/permissions/groups/post:postPermissionGroup', - '/permissions/teams/list:listTeamPermissions' = '/permissions/teams/list:listTeamPermissions', - '/permissions/teams/update:updateTeamPermission' = '/permissions/teams/update:updateTeamPermission', - '/permissions/teams/get:getTeamPermissions' = '/permissions/teams/get:getTeamPermissions', - '/permissions/teams/post:postTeam' = '/permissions/teams/post:postTeam', - '/permissions/groups/delete:deletePermissionGroup' = '/permissions/groups/delete:deletePermissionGroup', - '/permissions/teams/delete:deleteTeamPermission' = '/permissions/teams/delete:deleteTeamPermission' -} - -export type PermissionsResponsesUsersList_listUsers = { - route: '/permissions/users/list:listUserPermissions'; - callback: (d: BusterPermissionListUser[]) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponsesUser_getUserPermissions = { - route: '/permissions/users/get:getUserPermissions'; - callback: (d: BusterPermissionUser) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponsesGroup_listPermissionGroups = { - route: '/permissions/groups/list:listPermissionGroups'; - callback: (d: BusterPermissionListGroup[]) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseGroup_updatePermissionGroup = { - route: '/permissions/groups/update:updatePermissionGroup'; - callback: (d: BusterPermissionGroup) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseUser_updateUserPermission = { - route: '/permissions/users/update:updateUserPermission'; - callback: (d: BusterPermissionUser) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseTeam_listPermissionTeams = { - route: '/permissions/teams/list:listTeamPermissions'; - callback: (d: BusterPermissionListTeam[]) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseTeam_updateTeamPermission = { - route: '/permissions/teams/update:updateTeamPermission'; - callback: (d: BusterPermissionTeam) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseTeam_getTeamPermission = { - route: '/permissions/teams/get:getTeamPermissions'; - callback: (d: BusterPermissionTeam) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionResponseGroup_getPermissionGroup = { - route: '/permissions/groups/get:getPermissionGroup'; - callback: (d: BusterPermissionGroup) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionGroupPost_createPermissionGroup = { - route: '/permissions/groups/post:postPermissionGroup'; - callback: (d: BusterPermissionGroup) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionTeamPost_createPermissionTeam = { - route: '/permissions/teams/post:postTeam'; - callback: (d: BusterPermissionTeam) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionGroupDelete_deletePermissionGroup = { - route: '/permissions/groups/delete:deletePermissionGroup'; - callback: (d: { ids: string[] }) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionTeamDelete_deleteTeamPermission = { - route: '/permissions/teams/delete:deleteTeamPermission'; - callback: (d: { ids: string[] }) => void; - onError?: (d: unknown) => void; -}; - -export type PermissionsResponseTypes = - | PermissionsResponsesUsersList_listUsers - | PermissionResponsesUser_getUserPermissions - | PermissionResponsesGroup_listPermissionGroups - | PermissionResponseGroup_updatePermissionGroup - | PermissionResponseUser_updateUserPermission - | PermissionResponseTeam_listPermissionTeams - | PermissionResponseTeam_updateTeamPermission - | PermissionResponseTeam_getTeamPermission - | PermissionResponseGroup_getPermissionGroup - | PermissionGroupPost_createPermissionGroup - | PermissionTeamPost_createPermissionTeam - | PermissionGroupDelete_deletePermissionGroup - | PermissionTeamDelete_deleteTeamPermission; diff --git a/web/src/context/BusterWebSocket/BusterWebSocketProvider/helpers.ts b/web/src/context/BusterWebSocket/BusterWebSocketProvider/helpers.ts deleted file mode 100644 index ab1afe22f..000000000 --- a/web/src/context/BusterWebSocket/BusterWebSocketProvider/helpers.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { BusterSocketResponseRoute } from '@/api/buster_socket'; -import { DashboardResponses } from '@/api/buster_socket/dashboards'; -import { isDev } from '@/config'; -import { DatasetResponses } from '@/api/buster_socket/datasets'; -import { UserResponses } from '@/api/buster_socket/user'; -import { CollectionResponses } from '@/api/buster_socket/collections'; -import { DatasourceResponses } from '@/api/buster_socket/datasources/datasourceResponses'; -import { TermsResponses } from '@/api/buster_socket/terms/termsResponses'; -import { PermissionsResponses } from '@/api/buster_socket/permissions'; -import { TeamResponses } from '@/api/buster_socket/teams/teamResponses'; -import { SearchResponses } from '@/api/buster_socket/search'; -import { OrganizationResponses } from '@/api/buster_socket/organizations'; -import { SQLResponses } from '@/api/buster_socket/sql'; -import type { - BusterSocketResponseBase, - BusterSocketResponseMessage -} from '@/api/buster_socket/base_interfaces'; -import { ChatsResponses } from '@/api/buster_socket/chats'; - -export const createBusterResponse = ( - message: BusterSocketResponseMessage -): BusterSocketResponseBase => { - const parsedMessage = message; - const { route, payload, error, event } = parsedMessage; - const routeAndEvent = `${route}:${event}` as BusterSocketResponseRoute; - if (isDev) { - isKnownMessageRoute(parsedMessage); - } - - return { - route: routeAndEvent, - payload, - error - }; -}; - -const isKnownMessageRoute = (parsedMessage: BusterSocketResponseMessage) => { - const allResponses = { - ...DashboardResponses, - ...DatasetResponses, - ...UserResponses, - ...CollectionResponses, - ...DatasourceResponses, - ...SQLResponses, - ...TermsResponses, - ...PermissionsResponses, - ...TeamResponses, - ...SearchResponses, - ...OrganizationResponses, - ...ChatsResponses - }; - const event = parsedMessage?.event; - const route = parsedMessage?.route; - const payload = parsedMessage?.payload; - const allBusterSocketRoutes = Object.keys(allResponses); - const allValues = Object.values(allBusterSocketRoutes) as string[]; - const combinedRoute = `${route}:${event}`; - const isFound = allValues.includes(route) || allValues.includes(combinedRoute); - if (!isFound) { - console.warn('Unknown route:', combinedRoute, payload); - } -}; diff --git a/web/src/context/Users/useUserOrganization.ts b/web/src/context/Users/useUserOrganization.ts index 2190094d4..730feb58a 100644 --- a/web/src/context/Users/useUserOrganization.ts +++ b/web/src/context/Users/useUserOrganization.ts @@ -1,6 +1,7 @@ import { useMemoizedFn } from 'ahooks'; import { useSocketQueryMutation } from '@/api/buster_socket_query'; import { BusterUserResponse } from '@/api/asset_interfaces'; +import { useUpdateUser } from '@/api/buster_rest'; export const useUserOrganization = ({ userResponse, @@ -13,10 +14,8 @@ export const useUserOrganization = ({ '/organizations/post', '/organizations/post:post' ); - const { mutateAsync: updateUserInfo } = useSocketQueryMutation( - '/permissions/users/update', - '/permissions/users/update:updateUserPermission' - ); + + const { mutateAsync: updateUserInfo } = useUpdateUser(); const onCreateUserOrganization = useMemoizedFn( async ({ name, company }: { name: string; company: string }) => { @@ -24,7 +23,10 @@ export const useUserOrganization = ({ if (!alreadyHasOrganization && userResponse) { await Promise.all([ createOrganization({ name: company }), - updateUserInfo({ name, id: userResponse?.user?.id }) + updateUserInfo({ + userId: userResponse.user.id, + name + }) ]); await refetchUserResponse(); diff --git a/web/src/hooks/useWebSocket/helpers.ts b/web/src/hooks/useWebSocket/helpers.ts index ab1afe22f..6241cb465 100644 --- a/web/src/hooks/useWebSocket/helpers.ts +++ b/web/src/hooks/useWebSocket/helpers.ts @@ -6,7 +6,6 @@ import { UserResponses } from '@/api/buster_socket/user'; import { CollectionResponses } from '@/api/buster_socket/collections'; import { DatasourceResponses } from '@/api/buster_socket/datasources/datasourceResponses'; import { TermsResponses } from '@/api/buster_socket/terms/termsResponses'; -import { PermissionsResponses } from '@/api/buster_socket/permissions'; import { TeamResponses } from '@/api/buster_socket/teams/teamResponses'; import { SearchResponses } from '@/api/buster_socket/search'; import { OrganizationResponses } from '@/api/buster_socket/organizations'; @@ -43,7 +42,6 @@ const isKnownMessageRoute = (parsedMessage: BusterSocketResponseMessage) => { ...DatasourceResponses, ...SQLResponses, ...TermsResponses, - ...PermissionsResponses, ...TeamResponses, ...SearchResponses, ...OrganizationResponses,