Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add or remove user and groups from roles #2791

Merged
merged 43 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
67644a5
Add roles tab and roles modal
novakzaballa Aug 9, 2023
be9641a
add CollapsibleNestedList to CreateRole modal
novakzaballa Aug 10, 2023
c5fe1ef
Update design
novakzaballa Aug 11, 2023
1d9a813
Add chevron Icon
novakzaballa Aug 11, 2023
572cbc5
Create useRole
novakzaballa Aug 11, 2023
9b01360
Update useRoles
novakzaballa Aug 11, 2023
55adcaa
the CRUD operations for roles were implemented
novakzaballa Aug 15, 2023
1954b35
Manage rolePermissions
novakzaballa Aug 17, 2023
b5b2fdc
collapsibleList bug fixed and display toast when permission are saved
novakzaballa Aug 17, 2023
cd0b1af
Refresh role list when are created, updated, and deleted
novakzaballa Aug 17, 2023
ca013e5
Refresh role permission list when are created or updated
novakzaballa Aug 17, 2023
61b26f6
Display error toast
novakzaballa Aug 17, 2023
cb01326
Add role description
novakzaballa Aug 18, 2023
a1743f3
Info message, and confirmdialog added
novakzaballa Aug 18, 2023
c806ce1
Add permissions summary
novakzaballa Aug 21, 2023
24d8263
Display unsaved changes alert
novakzaballa Aug 23, 2023
ae9e3a8
Merge branch 'main' into feat/api-token-management
novakzaballa Aug 24, 2023
29d524a
Fix role desing
novakzaballa Aug 25, 2023
2883bed
Merge branch 'main' into feat/api-token-management
novakzaballa Aug 28, 2023
4a9b65e
Change description to role tab
novakzaballa Sep 4, 2023
de4a400
Wrap role management with the "show_role_management" flag
novakzaballa Sep 4, 2023
85b765d
fix: PermissionsSummary
novakzaballa Sep 8, 2023
4b9f269
feat: Add/remove roles in the modal editPermission modal from users a…
novakzaballa Sep 13, 2023
3d11c82
feat: Changes in EF
novakzaballa Sep 13, 2023
6043c4d
Merge branch 'feat/api-token-management' into feat/add-or-remove-user…
novakzaballa Sep 13, 2023
6564554
feat: UI desing in create Role modal
novakzaballa Sep 18, 2023
74cc7d1
feat: Add CRUD to user and group roles
novakzaballa Sep 19, 2023
d49e684
Merge branch 'main' into feat/add-or-remove-user-and-groups-from-roles
novakzaballa Sep 19, 2023
58bc783
feat: Edit role permissions for projects and environments
novakzaballa Sep 20, 2023
b5b24da
feat: Changes in users and groups lists
novakzaballa Sep 21, 2023
b41e4b8
fix: Delete role-store
novakzaballa Sep 22, 2023
33d53ce
fix: Add styles to Sistem desing
novakzaballa Sep 25, 2023
d8b3c74
fix: Border radius
novakzaballa Sep 25, 2023
bc0e802
fix: Wrap some features with the show_role_management flag
novakzaballa Sep 27, 2023
c548c70
fix: Update the description, panel title and no result message in the…
novakzaballa Sep 28, 2023
3b17630
fix: Updated Roles tab in Project and environment settings, resolved …
novakzaballa Sep 29, 2023
1bdbf8a
feat: Update the name of the members tab to permissions and tab title
novakzaballa Sep 29, 2023
eadda61
fix: Delete unnecessary TODO comment
novakzaballa Oct 3, 2023
c3be7b1
Add search box in Edit project and environment permissions
novakzaballa Oct 24, 2023
0fbe0ec
Merge branch 'main' into feat/add-or-remove-user-and-groups-from-roles
novakzaballa Oct 24, 2023
9560b14
Edit Role type
novakzaballa Nov 1, 2023
dc29c40
RTK code simplification
novakzaballa Nov 6, 2023
0d3c83b
Return 2 functions removed in RTK
novakzaballa Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions frontend/common/services/useRole.ts
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
*/
227 changes: 227 additions & 0 deletions frontend/common/services/useRolePermission.ts
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
*/
Loading