mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add server flag to disable user custom quiet hours (#11124)
This commit is contained in:
Generated
+2
@@ -1368,12 +1368,14 @@ export interface UserLoginType {
|
||||
// From codersdk/deployment.go
|
||||
export interface UserQuietHoursScheduleConfig {
|
||||
readonly default_schedule: string;
|
||||
readonly allow_user_custom: boolean;
|
||||
}
|
||||
|
||||
// From codersdk/users.go
|
||||
export interface UserQuietHoursScheduleResponse {
|
||||
readonly raw_schedule: string;
|
||||
readonly user_set: boolean;
|
||||
readonly user_can_set: boolean;
|
||||
readonly time: string;
|
||||
readonly timezone: string;
|
||||
readonly next: string;
|
||||
|
||||
@@ -8,6 +8,7 @@ const defaultArgs = {
|
||||
initialValues: {
|
||||
raw_schedule: "CRON_TZ=Australia/Sydney 0 2 * * *",
|
||||
user_set: false,
|
||||
user_can_set: true,
|
||||
time: "02:00",
|
||||
timezone: "Australia/Sydney",
|
||||
next: "2023-09-05T02:00:00+10:00",
|
||||
@@ -33,6 +34,7 @@ export const ExampleUserSet: Story = {
|
||||
initialValues: {
|
||||
raw_schedule: "CRON_TZ=America/Chicago 0 2 * * *",
|
||||
user_set: true,
|
||||
user_can_set: true,
|
||||
time: "02:00",
|
||||
timezone: "America/Chicago",
|
||||
next: "2023-09-05T02:00:00-05:00",
|
||||
|
||||
@@ -93,17 +93,24 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{!initialValues.user_can_set && (
|
||||
<Alert severity="error">
|
||||
Your administrator has disabled the ability to set a custom quiet
|
||||
hours schedule.
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Stack direction="row">
|
||||
<TextField
|
||||
{...getFieldHelpers("time")}
|
||||
disabled={isLoading}
|
||||
disabled={isLoading || !initialValues.user_can_set}
|
||||
label="Start time"
|
||||
type="time"
|
||||
fullWidth
|
||||
/>
|
||||
<TextField
|
||||
{...getFieldHelpers("timezone")}
|
||||
disabled={isLoading}
|
||||
disabled={isLoading || !initialValues.user_can_set}
|
||||
label="Timezone"
|
||||
select
|
||||
fullWidth
|
||||
@@ -126,7 +133,7 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
|
||||
<div>
|
||||
<LoadingButton
|
||||
loading={isLoading}
|
||||
disabled={isLoading}
|
||||
disabled={isLoading || !initialValues.user_can_set}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
>
|
||||
|
||||
@@ -37,6 +37,7 @@ const submitForm = async () => {
|
||||
const defaultQuietHoursResponse = {
|
||||
raw_schedule: "CRON_TZ=America/Chicago 0 0 * * *",
|
||||
user_set: false,
|
||||
user_can_set: true,
|
||||
time: "00:00",
|
||||
timezone: "America/Chicago",
|
||||
next: "", // not consumed by the frontend
|
||||
@@ -52,7 +53,6 @@ const cronTests = [
|
||||
|
||||
describe("SchedulePage", () => {
|
||||
beforeEach(() => {
|
||||
// appear logged out
|
||||
server.use(
|
||||
rest.get(`/api/v2/users/${MockUser.id}/quiet-hours`, (req, res, ctx) => {
|
||||
return res(ctx.status(200), ctx.json(defaultQuietHoursResponse));
|
||||
@@ -72,7 +72,6 @@ describe("SchedulePage", () => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
response: {},
|
||||
raw_schedule: data.schedule,
|
||||
user_set: true,
|
||||
time: `${test.hour.toString().padStart(2, "0")}:${test.minute
|
||||
@@ -121,4 +120,39 @@ describe("SchedulePage", () => {
|
||||
expect(errorMessage).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when user custom schedule is disabled", () => {
|
||||
it("shows a warning and disables the form", async () => {
|
||||
server.use(
|
||||
rest.get(
|
||||
`/api/v2/users/${MockUser.id}/quiet-hours`,
|
||||
(req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
raw_schedule: "CRON_TZ=America/Chicago 0 0 * * *",
|
||||
user_can_set: false,
|
||||
user_set: false,
|
||||
time: "00:00",
|
||||
timezone: "America/Chicago",
|
||||
next: "", // not consumed by the frontend
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
renderWithAuth(<SchedulePage />);
|
||||
await screen.findByText(
|
||||
"Your administrator has disabled the ability to set a custom quiet hours schedule.",
|
||||
);
|
||||
|
||||
const timeInput = screen.getByLabelText("Start time");
|
||||
expect(timeInput).toBeDisabled();
|
||||
const timezoneDropdown = screen.getByLabelText("Timezone");
|
||||
expect(timezoneDropdown).toHaveClass("Mui-disabled");
|
||||
const updateButton = screen.getByText("Update schedule");
|
||||
expect(updateButton).toBeDisabled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user