Skip to content

fix: Suspended users cannot authenticate #1849

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 18 commits into from
May 31, 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
Currently "activate" on ui does nothing
  • Loading branch information
Emyrk committed May 27, 2022
commit 55c5fe6ccef1826cdbb827cfaf057377ebb147b6
5 changes: 5 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export const updateProfile = async (
return response.data
}

export const activateUser = async (userId: TypesGen.User["id"]): Promise<TypesGen.User> => {
const response = await axios.put<TypesGen.User>(`/api/v2/users/${userId}/status/active`)
return response.data
}

export const suspendUser = async (userId: TypesGen.User["id"]): Promise<TypesGen.User> => {
const response = await axios.put<TypesGen.User>(`/api/v2/users/${userId}/status/suspend`)
return response.data
Expand Down
29 changes: 18 additions & 11 deletions site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export const UsersTable: React.FC<UsersTableProps> = ({
<TableCell>
<AvatarData title={u.username} subtitle={u.email} />
</TableCell>
<TableCell>
{u.status}
</TableCell>
<TableCell>{u.status}</TableCell>
<TableCell>
{canEditUsers ? (
<RoleSelect
Expand All @@ -86,16 +84,25 @@ export const UsersTable: React.FC<UsersTableProps> = ({
data={u}
menuItems={
// Return either suspend or activate depending on status
(u.status == "active" ? [{
label: Language.suspendMenuItem,
onClick: onSuspendUser,
}] : [{
label: Language.activateMenuItem,
onClick: onSuspendUser,
}]).concat({
(u.status == "active"
? [
{
label: Language.suspendMenuItem,
onClick: onSuspendUser,
},
]
: [
{
label: Language.activateMenuItem,
// TODO: Activate user
onClick: function () {},
},
]
).concat({
label: Language.resetPasswordMenuItem,
onClick: onResetUserPassword,
})}
})
}
/>
</TableCell>
)}
Expand Down
7 changes: 4 additions & 3 deletions site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { makeStyles } from "@material-ui/core/styles"
import { useActor } from "@xstate/react"
import React, { useContext } from "react"
import { Navigate, useLocation } from "react-router-dom"
import { isApiError } from "../../api/errors"
import { Footer } from "../../components/Footer/Footer"
import { SignInForm } from "../../components/SignInForm/SignInForm"
import { retrieveRedirect } from "../../util/redirect"
import { XServiceContext } from "../../xServices/StateContext"
import { AxiosError } from "axios"
import {isApiError} from "../../api/errors";

export const useStyles = makeStyles((theme) => ({
root: {
Expand Down Expand Up @@ -35,7 +34,9 @@ export const LoginPage: React.FC = () => {
const [authState, authSend] = useActor(xServices.authXService)
const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search)
const authErrorMessage = isApiError(authState.context.authError) ? authState.context.authError.response.data.message : undefined
const authErrorMessage = isApiError(authState.context.authError)
? authState.context.authError.response.data.message
: undefined
const getMethodsError = authState.context.getMethodsError
? (authState.context.getMethodsError as Error).message
: undefined
Expand Down
2 changes: 1 addition & 1 deletion site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AxiosError } from "axios"
import { assign, createMachine } from "xstate"
import * as API from "../../api/api"
import * as TypesGen from "../../api/typesGenerated"
import { displayError, displaySuccess } from "../../components/GlobalSnackbar/utils"
import { AxiosError } from "axios"

export const Language = {
successProfileUpdate: "Updated settings.",
Expand Down