Skip to content

Commit

Permalink
Access type (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx authored Sep 20, 2024
1 parent 87b542b commit 122e3fa
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ export function CustomLLMProviderUpdateForm({
}) {
const { mutate } = useSWRConfig();

const isPaidEnterpriseFeaturesEnabled = usePaidEnterpriseFeaturesEnabled();

// EE only
const { data: userGroups, isLoading: userGroupsIsLoading } = useUserGroups();

const [isTesting, setIsTesting] = useState(false);
const [testError, setTestError] = useState<string>("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ export default function AddConnector({
indexingStart,
refreshFreq,
auto_sync_options,
is_public,
...connector_specific_config
} = values;

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/IsPublicGroupSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState, useEffect } from "react";
import { FormikProps, FieldArray, ArrayHelpers, ErrorMessage } from "formik";
import { Text, Divider } from "@tremor/react";
import { FiUsers } from "react-icons/fi";
import { UserGroup, User, UserRole } from "@/lib/types";
import { UserGroup, UserRole } from "@/lib/types";
import { useUserGroups } from "@/lib/hooks";
import { BooleanFormField } from "@/components/admin/connectors/Field";
import { useUser } from "./user/UserProvider";
Expand Down
63 changes: 38 additions & 25 deletions web/src/components/admin/connectors/AccessTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { Text, Title } from "@tremor/react";
import { useUser } from "@/components/user/UserProvider";
import { useField } from "formik";
import { AutoSyncOptions } from "./AutoSyncOptions";
import { useContext } from "react";
import { SettingsContext } from "@/components/settings/SettingsProvider";
import { usePaidEnterpriseFeaturesEnabled } from "@/components/settings/usePaidEnterpriseFeaturesEnabled";

function isValidAutoSyncSource(
value: ConfigurableSources
Expand All @@ -24,6 +27,8 @@ export function AccessTypeForm({
const [access_type, meta, access_type_helpers] =
useField<AccessType>("access_type");

const isPaidEnterpriseEnabled = usePaidEnterpriseFeaturesEnabled();
const settings = useContext(SettingsContext);
const isAutoSyncSupported = isValidAutoSyncSource(connector);
const { isLoadingUser, isAdmin } = useUser();

Expand Down Expand Up @@ -55,34 +60,42 @@ export function AccessTypeForm({
}

return (
<div>
<div className="flex gap-x-2 items-center">
<label className="text-text-950 font-medium">Document Access</label>
</div>
<p className="text-sm text-text-500 mb-2">
Control who has access to the documents indexed by this connector.
</p>

{isAdmin && (
<>
{isPaidEnterpriseEnabled && (
<>
<DefaultDropdown
options={options}
selected={access_type.value}
onSelect={(selected) =>
access_type_helpers.setValue(selected as AccessType)
}
includeDefault={false}
/>

{access_type.value === "sync" && isAutoSyncSupported && (
<div className="mt-6">
<AutoSyncOptions
connectorType={connector as ValidAutoSyncSources}
/>
<div>
<div className="flex gap-x-2 items-center">
<label className="text-text-950 font-medium">
Document Access
</label>
</div>
)}
<p className="text-sm text-text-500 mb-2">
Control who has access to the documents indexed by this connector.
</p>

{isAdmin && (
<>
<DefaultDropdown
options={options}
selected={access_type.value}
onSelect={(selected) =>
access_type_helpers.setValue(selected as AccessType)
}
includeDefault={false}
/>

{access_type.value === "sync" && isAutoSyncSupported && (
<div className="mt-6">
<AutoSyncOptions
connectorType={connector as ValidAutoSyncSources}
/>
</div>
)}
</>
)}
</div>
</>
)}
</div>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { useUser } from "@/components/user/UserProvider";

// This should be included for all forms that require groups / public access
// to be set, and access to this / permissioning should be handled within this component itself.

export type AccessTypeGroupSelectorFormType = {
access_type: AccessType;
groups: number[];
};

export function AccessTypeGroupSelector({}: {}) {
const { data: userGroups, isLoading: userGroupsIsLoading } = useUserGroups();
const { isAdmin, user, isLoadingUser, isCurator } = useUser();
Expand Down
6 changes: 4 additions & 2 deletions web/src/lib/connectors/connectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Yup from "yup";
import { IsPublicGroupSelectorFormType } from "@/components/IsPublicGroupSelector";
import { ConfigurableSources, ValidInputTypes, ValidSources } from "../types";
import { AccessTypeGroupSelectorFormType } from "@/components/admin/connectors/AccessTypeGroupSelector";

export type InputType =
| "list"
Expand Down Expand Up @@ -845,13 +846,13 @@ For example, specifying .*-support.* as a "channel" will cause the connector to
};
export function createConnectorInitialValues(
connector: ConfigurableSources
): Record<string, any> & IsPublicGroupSelectorFormType {
): Record<string, any> & AccessTypeGroupSelectorFormType {
const configuration = connectorConfigs[connector];

return {
name: "",
groups: [],
is_public: true,
access_type: "public",
...configuration.values.reduce(
(acc, field) => {
if (field.type === "select") {
Expand All @@ -876,6 +877,7 @@ export function createConnectorValidationSchema(
const configuration = connectorConfigs[connector];

return Yup.object().shape({
access_type: Yup.string().required("Access Type is required"),
name: Yup.string().required("Connector Name is required"),
...configuration.values.reduce(
(acc, field) => {
Expand Down

0 comments on commit 122e3fa

Please sign in to comment.