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

fix: Reading role permissions generates 500 errors #3009

Merged
merged 30 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
67ac16f
fix: Reading role permissions generates 500 errors
novakzaballa Nov 20, 2023
38c076d
Add todo
novakzaballa Nov 21, 2023
61aff35
Add issue
novakzaballa Nov 21, 2023
cc95b3f
fix assign roles in user permissions
novakzaballa Nov 22, 2023
487283f
Add roles to user serializer
novakzaballa Nov 28, 2023
dc0dc4d
UPdate editpermission for user roles
novakzaballa Nov 28, 2023
85322bf
delete logs and update users
novakzaballa Nov 28, 2023
f52fb32
Update style for the roles in CreateRole Modal
novakzaballa Nov 29, 2023
4a071a8
Fix bug when try open editPermission modal
novakzaballa Nov 30, 2023
e9c3e70
Fix bug when try open editPermission modal
novakzaballa Nov 30, 2023
e386f40
Merge branch 'main' into fix/reading-role-permissions-generates-500-e…
novakzaballa Nov 30, 2023
8787d43
Solve merge errors
novakzaballa Nov 30, 2023
cbd44cf
fix: Reading role permissions generates 500 error backend
novakzaballa Nov 30, 2023
abeb1d1
Add exception in get_user_roles
novakzaballa Nov 30, 2023
0aa8d4e
update user when role is deleted
novakzaballa Dec 1, 2023
672b280
Merge branch 'fix/reading-role-permissions-generates-500-error-be' in…
novakzaballa Dec 1, 2023
4d17bf3
Add new url for user roles
novakzaballa Dec 1, 2023
8ab42d1
Use new RBAC endpoint for get user with their roles
novakzaballa Dec 1, 2023
92281ba
Add confitional chaining
novakzaballa Dec 1, 2023
5bb6235
revert force getOrganisation
novakzaballa Dec 5, 2023
3633b37
revert changes in backend
novakzaballa Dec 5, 2023
d5967f1
Add and implement delete user roles endpoint
novakzaballa Dec 7, 2023
95b9045
Add user-roles url
novakzaballa Dec 7, 2023
1dac921
Clean code
novakzaballa Dec 7, 2023
cfd05de
Merge branch 'main' into fix/reading-role-permissions-generates-500-e…
novakzaballa Dec 11, 2023
c08f9ee
Update roles groups
novakzaballa Dec 18, 2023
2805763
Update roles RTK
novakzaballa Dec 18, 2023
b54b420
Merge branch 'main' into fix/reading-role-permissions-generates-500-e…
novakzaballa Dec 22, 2023
4b98c2a
Solve error 500 in project, and environment settings page
novakzaballa Jan 8, 2024
cd8afba
Merge branch 'main' into fix/reading-role-permissions-generates-500-e…
novakzaballa Jan 8, 2024
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
5 changes: 4 additions & 1 deletion api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class UserListSerializer(serializers.ModelSerializer):
join_date = serializers.SerializerMethodField(read_only=True)

default_fields = ("id", "email", "first_name", "last_name", "last_login")
organisation_users_fields = ("role", "date_joined")
organisation_users_fields = (
"role",
"date_joined",
)

class Meta:
model = FFAdminUser
Expand Down
74 changes: 74 additions & 0 deletions frontend/common/services/useGroupWithRole.ts
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
*/
10 changes: 5 additions & 5 deletions frontend/common/services/useRolePermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const rolePermissionService = service
>({
invalidatesTags: (res) => [
{ id: 'LIST', type: 'rolePermission' },
{ id: res?.id, type: 'rolePermission' },
{ type: 'rolePermission' },
],
query: (query: Req['updateRolePermission']) => ({
body: query.body,
Expand Down Expand Up @@ -46,7 +46,7 @@ export const rolePermissionService = service
Res['rolePermission'],
Req['getRolePermission']
>({
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }],
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}`,
}),
Expand All @@ -56,7 +56,7 @@ export const rolePermissionService = service
Res['rolePermission'],
Req['getRolePermission']
>({
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }],
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}`,
}),
Expand All @@ -66,7 +66,7 @@ export const rolePermissionService = service
Res['rolePermission'],
Req['getRolePermission']
>({
providesTags: (res) => [{ id: res?.id, type: 'RolePermission' }],
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}`,
}),
Expand All @@ -76,7 +76,7 @@ export const rolePermissionService = service
Res['rolePermission'],
Req['updateRolePermission']
>({
invalidatesTags: [{ id: 'LIST', type: 'rolePermission' }],
invalidatesTags: [{ type: 'rolePermission' }],
query: (query: Req['updateRolePermission']) => ({
body: query.body,
method: 'PUT',
Expand Down
12 changes: 9 additions & 3 deletions frontend/common/services/useRolePermissionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Req } from 'common/types/requests'
import { service } from 'common/service'

export const rolePermissionGroupService = service
.enhanceEndpoints({ addTagTypes: ['RolePermissionGroup'] })
.enhanceEndpoints({ addTagTypes: ['RolePermissionGroup', 'GroupWithRole'] })
.injectEndpoints({
endpoints: (builder) => ({
createRolePermissionGroup: builder.mutation<
Res['rolePermissionGroup'],
Req['createRolePermissionGroup']
>({
invalidatesTags: [{ id: 'LIST', type: 'RolePermissionGroup' }],
invalidatesTags: [
{ id: 'LIST', type: 'RolePermissionGroup' },
{ type: 'GroupWithRole' },
],
query: (query: Req['createRolePermissionGroup']) => ({
body: query.data,
method: 'POST',
Expand All @@ -21,7 +24,10 @@ export const rolePermissionGroupService = service
Res['rolePermissionGroup'],
Req['deleteRolePermissionGroup']
>({
invalidatesTags: [{ id: 'LIST', type: 'RolePermissionGroup' }],
invalidatesTags: [
{ type: 'RolePermissionGroup' },
{ type: 'GroupWithRole' },
],
query: (query: Req['deleteRolePermissionGroup']) => ({
body: query,
method: 'DELETE',
Expand Down
15 changes: 12 additions & 3 deletions frontend/common/services/useRolesUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Req } from 'common/types/requests'
import { service } from 'common/service'

export const rolesUserService = service
.enhanceEndpoints({ addTagTypes: ['RolesUser'] })
.enhanceEndpoints({ addTagTypes: ['RolesUser', 'User-role'] })
.injectEndpoints({
endpoints: (builder) => ({
createRolesPermissionUsers: builder.mutation<
Res['rolesUsers'],
Req['createRolesPermissionUsers']
>({
invalidatesTags: [{ id: 'LIST', type: 'RolesUser' }],
invalidatesTags: [
{ type: 'User-role' },
{ id: 'LIST', type: 'RolesUser' },
],
query: (query: Req['createRolesPermissionUsers']) => ({
body: query.data,
method: 'POST',
Expand All @@ -21,12 +24,18 @@ export const rolesUserService = service
Res['rolesUsers'],
Req['deleteRolesPermissionUsers']
>({
invalidatesTags: [{ id: 'LIST', type: 'RolesUser' }],
invalidatesTags: [
{ type: 'User-role' },
{ type: 'RolesUser' },
],
query: (query: Req['deleteRolesPermissionUsers']) => ({
body: query,
method: 'DELETE',
url: `organisations/${query.organisation_id}/roles/${query.role_id}/users/${query.user_id}/`,
}),
transformResponse: () => {
toast('User role was removed')
},
}),
getRolesPermissionUsers: builder.query<
Res['rolesUsers'],
Expand Down
73 changes: 73 additions & 0 deletions frontend/common/services/useUserWithRole.ts
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
*/
4 changes: 4 additions & 0 deletions frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export type Req = {
createLaunchDarklyProjectImport: { project_id: string }
getLaunchDarklyProjectImport: { project_id: string }
getLaunchDarklyProjectsImport: { project_id: string; import_id: string }
getUserWithRoles: { org_id: string; user_id: string }
deleteUserWihRole: { org_id: string; user_id: string; role_id: string }
getGroupWithRole: { org_id: string; group_id: string }
deleteGroupWithRole: { org_id: string; group_id: string; role_id: string }
getChangeRequests: PagedRequest<{
search?: string
environmentId: string
Expand Down
2 changes: 2 additions & 0 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ export type Res = {
environment: Environment
launchDarklyProjectImport: LaunchDarklyProjectImport
launchDarklyProjectsImport: LaunchDarklyProjectImport[]
userWithRoles: PagedResponse<Roles>
groupWithRole: PagedResponse<Roles>
changeRequests: PagedResponse<ChangeRequestSummary>
groupSummaries: UserGroupSummary[]
// END OF TYPES
Expand Down
Loading