Skip to content

feat: Add permissions for links #1407

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

Merged
merged 8 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Refactor to use generated types
  • Loading branch information
BrunoQuaresma committed May 13, 2022
commit dbd9b30bde5e76d56afc1d46a59ad9e1f4d848d4
2 changes: 1 addition & 1 deletion site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const getAuthMethods = async (): Promise<TypesGen.AuthMethods> => {
return response.data
}

export const getUserPermissions = async (
export const checkUserPermissions = async (
userId: string,
params: TypesGen.UserPermissionCheckRequest,
): Promise<TypesGen.UserPermissionCheckResponse> => {
Expand Down
2 changes: 0 additions & 2 deletions site/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ export interface ReconnectingPTYRequest {
readonly height?: number
readonly width?: number
}

export type UserPermissionCheckResponse = Record<string, boolean>
20 changes: 10 additions & 10 deletions site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface AuthContext {
updateProfileError?: Error | unknown
me?: TypesGen.User
methods?: TypesGen.AuthMethods
permissions?: Types.UserPermissionCheckResponse
getPermissionsError?: Error | unknown
permissions?: TypesGen.UserPermissionCheckResponse
checkPermissionsError?: Error | unknown
}

export type AuthEvent =
Expand Down Expand Up @@ -61,8 +61,8 @@ export const authMachine =
updateProfile: {
data: TypesGen.User
}
getPermissions: {
data: Types.UserPermissionCheckResponse
checkPermissions: {
data: TypesGen.UserPermissionCheckResponse
}
},
},
Expand Down Expand Up @@ -117,8 +117,8 @@ export const authMachine =
gettingPermissions: {
entry: "clearGetPermissionsError",
invoke: {
src: "getPermissions",
id: "getPermissions",
src: "checkPermissions",
id: "checkPermissions",
onDone: [
{
actions: ["assignPermissions"],
Expand Down Expand Up @@ -234,12 +234,12 @@ export const authMachine =

return API.updateProfile(context.me.id, event.data)
},
getPermissions: async (context) => {
checkPermissions: async (context) => {
if (!context.me) {
throw new Error("No current user found")
}

return API.getUserPermissions(context.me.id, {
return API.checkUserPermissions(context.me.id, {
checks: permissionsToCheck,
})
},
Expand Down Expand Up @@ -289,10 +289,10 @@ export const authMachine =
permissions: (_, event) => event.data,
}),
assignGetPermissionsError: assign({
getPermissionsError: (_, event) => event.data,
checkPermissionsError: (_, event) => event.data,
}),
clearGetPermissionsError: assign({
getPermissionsError: (_) => undefined,
checkPermissionsError: (_) => undefined,
}),
},
},
Expand Down