-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reading role permissions generates 500 errors (#3009)
- Loading branch information
1 parent
41d4dea
commit de5cf9d
Showing
12 changed files
with
299 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const groupWithRoleService = service | ||
.enhanceEndpoints({ addTagTypes: ['GroupWithRole', 'RolePermissionGroup'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
deleteGroupWithRole: builder.mutation< | ||
Res['groupWithRole'], | ||
Req['deleteGroupWithRole'] | ||
>({ | ||
invalidatesTags: [{ type: 'GroupWithRole' }, { type: 'RolePermissionGroup' }], | ||
query: (query: Req['deleteGroupWithRole']) => ({ | ||
body: query, | ||
method: 'DELETE', | ||
url: `organisations/${query.org_id}/groups/${query.group_id}/roles/${query.role_id}/`, | ||
}), | ||
transformResponse: () => { | ||
toast('Group role was removed') | ||
}, | ||
}), | ||
getGroupWithRole: builder.query< | ||
Res['groupWithRole'], | ||
Req['getGroupWithRole'] | ||
>({ | ||
providesTags: (result, error, group) => { | ||
const tags = result ? [{ id: group.id, type: 'GroupWithRole' }] : [] | ||
return tags | ||
}, | ||
query: (query: Req['getGroupWithRole']) => ({ | ||
url: `organisations/${query.org_id}/groups/${query.group_id}/roles/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function deleteGroupWithRole( | ||
store: any, | ||
data: Req['deleteGroupWithRole'], | ||
options?: Parameters< | ||
typeof groupWithRoleService.endpoints.deleteGroupWithRole.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
groupWithRoleService.endpoints.deleteGroupWithRole.initiate(data, options), | ||
) | ||
} | ||
export async function getGroupWithRole( | ||
store: any, | ||
data: Req['getGroupWithRole'], | ||
options?: Parameters< | ||
typeof groupWithRoleService.endpoints.getGroupWithRole.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
groupWithRoleService.endpoints.getGroupWithRole.initiate(data, options), | ||
) | ||
} | ||
|
||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useDeleteGroupWithRoleMutation, | ||
useGetGroupWithRoleQuery, | ||
// END OF EXPORTS | ||
} = groupWithRoleService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetGroupWithRoleQuery({ id: 2 }, {}) //get hook | ||
const [createGroupWithRole, { isLoading, data, isSuccess }] = useCreateGroupWithRoleMutation() //create hook | ||
groupWithRoleService.endpoints.getGroupWithRole.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const userWithRolesService = service | ||
.enhanceEndpoints({ addTagTypes: ['User-role', 'RolesUser'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
deleteUserWithRoles: builder.mutation< | ||
Res['User-role'], | ||
Req['deleteUserWithRoles'] | ||
>({ | ||
invalidatesTags: [{ type: 'User-role' }, { type: 'RolesUser' }], | ||
query: (query: Req['deleteUserWithRoles']) => ({ | ||
method: 'DELETE', | ||
url: `organisations/${query.org_id}/users/${query.user_id}/roles/${query.role_id}/`, | ||
}), | ||
transformResponse: () => { | ||
toast('User role was removed') | ||
}, | ||
}), | ||
getUserWithRoles: builder.query< | ||
Res['userWithRoles'], | ||
Req['getUserWithRoles'] | ||
>({ | ||
invalidatesTags: [{ type: 'User-role' }], | ||
providesTags: (result, error, userId) => { | ||
const tags = result ? [{ id: userId, type: 'User-role' }] : [] | ||
return tags | ||
}, | ||
query: (query: Req['getUserWithRoles']) => ({ | ||
url: `organisations/${query.org_id}/users/${query.user_id}/roles/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getUserWithRoles( | ||
store: any, | ||
data: Req['getUserWithRoles'], | ||
options?: Parameters< | ||
typeof userWithRolesService.endpoints.getUserWithRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
userWithRolesService.endpoints.getUserWithRoles.initiate(data, options), | ||
) | ||
} | ||
|
||
export async function deleteUserRole( | ||
store: any, | ||
data: Req['deleteUserWithRoles'], | ||
options?: Parameters< | ||
typeof UserRoleService.endpoints.deleteUserWithRoles.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
UserRoleService.endpoints.deleteUserWithRoles.initiate(data, options), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useDeleteUserWithRolesMutation, | ||
useGetUserWithRolesQuery, | ||
// END OF EXPORTS | ||
} = userWithRolesService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useUserWithRolesQuery({ id: 2 }, {}) //get hook | ||
userWithRolesService.endpoints.getUserWithRoles.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
de5cf9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./docs
docs-git-main-flagsmith.vercel.app
docs.bullet-train.io
docs-flagsmith.vercel.app
docs.flagsmith.com
de5cf9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-preview – ./frontend
flagsmith-frontend-production-native.vercel.app
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
flagsmith-frontend-preview-flagsmith.vercel.app
de5cf9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-staging – ./frontend
flagsmith-frontend-staging-git-main-flagsmith.vercel.app
flagsmith-staging-frontend.vercel.app
flagsmith-frontend-staging-flagsmith.vercel.app
staging.flagsmith.com