Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Add admin only setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Jan 24, 2024
1 parent 014d0cb commit 210e88f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cypress/integration/distroSettings/general_section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("general section", () => {
cy.getInputByLabel("Disable shallow clone for this distro").check({
force: true,
});
cy.getInputByLabel("Admin only").check({ force: true });
save();
cy.validateToast("success");

Expand All @@ -29,13 +30,15 @@ describe("general section", () => {
cy.getInputByLabel("Disable shallow clone for this distro").should(
"be.checked",
);
cy.getInputByLabel("Admin only").should("be.checked");

// Undo changes.
cy.dataCy("delete-item-button").click();
cy.getInputByLabel("Notes").clear();
cy.getInputByLabel("Disable shallow clone for this distro").uncheck({
force: true,
});
cy.getInputByLabel("Admin only").uncheck({ force: true });
save();
cy.validateToast("success");
});
Expand Down
1 change: 1 addition & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5730,6 +5730,7 @@ export type DistroQuery = {
__typename?: "Query";
distro?: {
__typename?: "Distro";
adminOnly: boolean;
aliases: Array<string>;
arch: Arch;
authorizedKeysFile: string;
Expand Down
1 change: 1 addition & 0 deletions src/gql/queries/distro.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query Distro($distroId: String!) {
distro(distroId: $distroId) {
adminOnly
aliases
arch
authorizedKeysFile
Expand Down
9 changes: 9 additions & 0 deletions src/pages/distroSettings/tabs/GeneralTab/getFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export const getFormSchema = (
type: "object" as "object",
title: "Distro Options",
properties: {
adminOnly: {
type: "boolean" as "boolean",
title: "Admin only",
default: false,
},
isCluster: {
type: "boolean" as "boolean",
title: "Mark distro as cluster",
Expand Down Expand Up @@ -88,6 +93,10 @@ export const getFormSchema = (
},
distroOptions: {
"ui:ObjectFieldTemplate": CardFieldTemplate,
adminOnly: {
"ui:description":
"Admin-only distros are not selectable by general users (e.g. when spawning a host). They do not have their access controlled beyond being hidden.",
},
isCluster: {
"ui:description":
"Jobs will not be run on this host. Used for special purposes.",
Expand Down
2 changes: 2 additions & 0 deletions src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const generalForm: GeneralFormState = {
aliases: ["rhel71-power8", "rhel71-power8-build"],
},
distroOptions: {
adminOnly: true,
isCluster: false,
disableShallowClone: true,
disabled: false,
Expand All @@ -31,6 +32,7 @@ const generalForm: GeneralFormState = {
const generalGql: DistroInput = {
...distroData,
name: "rhel71-power8-large",
adminOnly: true,
aliases: ["rhel71-power8", "rhel71-power8-build"],
isCluster: false,
disableShallowClone: true,
Expand Down
13 changes: 11 additions & 2 deletions src/pages/distroSettings/tabs/GeneralTab/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ type Tab = DistroSettingsTabRoutes.General;
export const gqlToForm = ((data) => {
if (!data) return null;

const { aliases, disableShallowClone, disabled, isCluster, name, note } =
data;
const {
adminOnly,
aliases,
disableShallowClone,
disabled,
isCluster,
name,
note,
} = data;

return {
distroName: {
Expand All @@ -17,6 +24,7 @@ export const gqlToForm = ((data) => {
aliases,
},
distroOptions: {
adminOnly,
isCluster,
disableShallowClone,
disabled,
Expand All @@ -31,6 +39,7 @@ export const formToGql = ((
) => ({
...distro,
name: distroName.identifier,
adminOnly: distroOptions.adminOnly,
aliases: distroAliases.aliases,
note: distroOptions.note,
isCluster: distroOptions.isCluster,
Expand Down
1 change: 1 addition & 0 deletions src/pages/distroSettings/tabs/GeneralTab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface GeneralFormState {
aliases: string[];
};
distroOptions: {
adminOnly: boolean;
isCluster: boolean;
disableShallowClone: boolean;
disabled: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/pages/distroSettings/tabs/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

const distroData: DistroQuery["distro"] = {
__typename: "Distro",
adminOnly: false,
aliases: ["rhel71-power8", "rhel71-power8-build"],
arch: Arch.Linux_64Bit,
authorizedKeysFile: "",
Expand Down

0 comments on commit 210e88f

Please sign in to comment.