-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add or remove user and groups from roles (#2791)
- Loading branch information
1 parent
eee1c0a
commit c2d0c11
Showing
21 changed files
with
2,568 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const roleService = service | ||
.enhanceEndpoints({ addTagTypes: ['Role'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
createRole: builder.mutation<Res['roles'], Req['createRoles']>({ | ||
invalidatesTags: [{ id: 'LIST', type: 'Role' }], | ||
query: (query: Req['createRoles']) => ({ | ||
body: query, | ||
method: 'POST', | ||
url: `organisations/${query.organisation_id}/roles/`, | ||
}), | ||
}), | ||
deleteRole: builder.mutation<Res['roles'], Req['deleteRolesById']>({ | ||
invalidatesTags: [{ id: 'LIST', type: 'DeleteRole' }], | ||
query: (query: Req['deleteRole']) => ({ | ||
method: 'DELETE', | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/`, | ||
}), | ||
}), | ||
getRole: builder.query<Res['roles'], Req['getRolesById']>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'RolesById' }], | ||
query: (query: Req['getRolesById']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/`, | ||
}), | ||
}), | ||
getRoles: builder.query<Res['roles'], Req['getRoles']>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'Role' }], | ||
query: (query: Req['getRoles']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/`, | ||
}), | ||
}), | ||
updateRole: builder.mutation<Res['roles'], Req['updateRolesById']>({ | ||
invalidatesTags: (res) => [ | ||
{ id: 'LIST', type: 'RolesById' }, | ||
{ id: res?.id, type: 'RolesById' }, | ||
], | ||
query: (query: Req['updateRole']) => ({ | ||
body: query.body, | ||
method: 'PUT', | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function createRole( | ||
store: any, | ||
data: Req['createRoles'], | ||
options?: Parameters<typeof roleService.endpoints.createRoles.initiate>[1], | ||
) { | ||
store.dispatch(roleService.endpoints.createRoles.initiate(data, options)) | ||
return Promise.all(store.dispatch(roleService.util.getRunningQueriesThunk())) | ||
} | ||
export async function getRoles( | ||
store: any, | ||
data: Req['getRoles'], | ||
options?: Parameters<typeof roleService.endpoints.getRoles.initiate>[1], | ||
) { | ||
return store.dispatch(roleService.endpoints.getRoles.initiate(data, options)) | ||
} | ||
export async function deleteRole( | ||
store: any, | ||
data: Req['deleteRolesById'], | ||
options?: Parameters< | ||
typeof rolesByIdService.endpoints.deleteRolesById.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolesByIdService.endpoints.deleteRolesById.initiate(data, options), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolesByIdService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
export async function getRole( | ||
store: any, | ||
data: Req['getRolesById'], | ||
options?: Parameters< | ||
typeof rolesByIdService.endpoints.getRolesById.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolesByIdService.endpoints.getRolesById.initiate(data, options), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolesByIdService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
export async function updateRole( | ||
store: any, | ||
data: Req['updateRolesById'], | ||
options?: Parameters< | ||
typeof rolesByIdService.endpoints.updateRolesById.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolesByIdService.endpoints.updateRolesById.initiate(data, options), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolesByIdService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useCreateRoleMutation, | ||
useDeleteRoleMutation, | ||
useGetRoleQuery, | ||
useGetRolesQuery, | ||
useUpdateRoleMutation, | ||
// END OF EXPORTS | ||
} = roleService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetRolesQuery({ id: 2 }, {}) //get hook | ||
const [createRole, { isLoading, data, isSuccess }] = useCreateRoleMutation() //create hook | ||
roleService.endpoints.getRoles.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const rolePermissionService = service | ||
.enhanceEndpoints({ addTagTypes: ['rolePermission'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
createRolePermissions: builder.mutation< | ||
Res['rolePermission'], | ||
Req['createRolePermission'] | ||
>({ | ||
invalidatesTags: (res) => [ | ||
{ id: 'LIST', type: 'rolePermission' }, | ||
{ id: res?.id, type: 'rolePermission' }, | ||
], | ||
query: (query: Req['updateRolePermission']) => ({ | ||
body: query.body, | ||
method: 'POST', | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/${query.level}-permissions/`, | ||
}), | ||
transformErrorResponse: () => { | ||
toast('Failed to Save', 'danger') | ||
}, | ||
}), | ||
|
||
getRoleEnvironmentPermissions: builder.query< | ||
Res['rolePermission'], | ||
Req['getRolePermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'rolePermission' }], | ||
query: (query: Req['getRolePermission']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/environments-permissions/?environment=${query.env_id}`, | ||
}), | ||
}), | ||
getRoleOrganisationPermissions: builder.query< | ||
Res['rolePermission'], | ||
Req['getRolePermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'rolePermission' }], | ||
query: (query: Req['getRolePermission']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/organisation-permissions/`, | ||
}), | ||
}), | ||
getRoleProjectPermissions: builder.query< | ||
Res['rolePermission'], | ||
Req['getRolePermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }], | ||
query: (query: Req['getRolePermission']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/projects-permissions/?project=${query.project_id}`, | ||
}), | ||
}), | ||
|
||
getRolesEnvironmentPermissions: builder.query< | ||
Res['rolePermission'], | ||
Req['getRolePermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }], | ||
query: (query: Req['getRolePermission']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/environments-permissions/?environment=${query.env_id}`, | ||
}), | ||
}), | ||
|
||
getRolesProjectPermissions: builder.query< | ||
Res['rolePermission'], | ||
Req['getRolePermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }], | ||
query: (query: Req['getRolePermission']) => ({ | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/projects-permissions/?project=${query.project_id}`, | ||
}), | ||
}), | ||
|
||
updateRolePermissions: builder.mutation< | ||
Res['rolePermission'], | ||
Req['updateRolePermission'] | ||
>({ | ||
invalidatesTags: [{ id: 'LIST', type: 'rolePermission' }], | ||
query: (query: Req['updateRolePermission']) => ({ | ||
body: query.body, | ||
method: 'PUT', | ||
url: `organisations/${query.organisation_id}/roles/${query.role_id}/${query.level}-permissions/${query.id}/`, | ||
}), | ||
transformErrorResponse: () => { | ||
toast('Failed to Save', 'danger') | ||
}, | ||
}), | ||
|
||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getRoleOrganisationPermissions( | ||
store: any, | ||
data: Req['getRolePermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.getRoleOrganisationPermissions.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolePermissionService.endpoints.getRoleOrganisationPermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolePermissionService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
export async function updateRolePermissions( | ||
store: any, | ||
data: Req['updateRolePermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.updateRolePermissions.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolePermissionService.endpoints.updateRolePermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolePermissionService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
|
||
export async function getRoleProjectPermissions( | ||
store: any, | ||
data: Req['getRolePermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.getRoleProjectPermissions.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolePermissionService.endpoints.getRoleProjectPermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolePermissionService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
|
||
export async function getRoleEnvironmentPermissions( | ||
store: any, | ||
data: Req['getRolePermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.getRoleEnvironmentPermissions.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolePermissionService.endpoints.getRoleEnvironmentPermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolePermissionService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
|
||
export async function createRolePermissions( | ||
store: any, | ||
data: Req['updateRolePermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.createRolePermissions.initiate | ||
>[1], | ||
) { | ||
store.dispatch( | ||
rolePermissionService.endpoints.createRolePermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
return Promise.all( | ||
store.dispatch(rolePermissionService.util.getRunningQueriesThunk()), | ||
) | ||
} | ||
export async function getRolesProjectPermissions( | ||
store: any, | ||
data: Req['getRolesPermission'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.getRolesProjectPermissions.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
rolePermissionService.endpoints.getRolesProjectPermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
|
||
export async function getRolesEnvironmentPermissions( | ||
store: any, | ||
data: Req['getRolesEnvironment'], | ||
options?: Parameters< | ||
typeof rolePermissionService.endpoints.getRolesProjectPermissions.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
rolePermissionService.endpoints.getRolesEnvironmentPermissions.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
|
||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useCreateRolePermissionsMutation, | ||
useGetRoleEnvironmentPermissionsQuery, | ||
useGetRoleOrganisationPermissionsQuery, | ||
useGetRoleProjectPermissionsQuery, | ||
useUpdateRolePermissionsMutation, | ||
// END OF EXPORTS | ||
} = rolePermissionService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetRoleOrganisationPermissionsQuery({ id: 2 }, {}) //get hook | ||
const [createRolePermission, { isLoading, data, isSuccess }] = useCreateRolePermissionMutation() //create hook | ||
rolePermissionService.endpoints.getRolePermission.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
Oops, something went wrong.
c2d0c11
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
c2d0c11
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-flagsmith.vercel.app
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
c2d0c11
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