Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: simplify the setting permission check (#10401)

ecmadao0aff87e7b525
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
index f9f18678ee..be95a6898a 100644
--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
@@ -82,7 +82,7 @@
<div class="flex justify-end">
<NButton
type="primary"
- :disabled="!allowSave"
+ :disabled="!allowEdit || !allowSave"
@click.prevent="updateOpenAIKeyEndpoint"
>
{{ $t("common.update") }}
@@ -103,9 +103,8 @@
import scrollIntoView from "scroll-into-view-if-needed";
import { computed, onMounted, reactive, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import { hasFeature, pushNotification, useCurrentUserV1 } from "@/store";
+import { hasFeature, pushNotification } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-import { hasWorkspacePermissionV2 } from "@/utils";
interface LocalState {
openAIKey: string;
@@ -113,9 +112,12 @@ interface LocalState {
showFeatureModal: boolean;
}
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const containerRef = ref<HTMLDivElement>();
const state = reactive<LocalState>({
@@ -136,18 +138,13 @@ watchEffect(() => {
state.openAIEndpoint = openAIEndpointSetting?.value?.stringValue ?? "";
});
-const allowEdit = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
-
const allowSave = computed((): boolean => {
const openAIKeyUpdated =
state.openAIKey !== maskKey(openAIKeySetting?.value?.stringValue) ||
(state.openAIKey && !state.openAIKey.includes("***"));
return (
- allowEdit.value &&
- (openAIKeyUpdated ||
- state.openAIEndpoint !== openAIEndpointSetting?.value?.stringValue)
+ openAIKeyUpdated ||
+ state.openAIEndpoint !== openAIEndpointSetting?.value?.stringValue
);
});
@@ -163,10 +160,6 @@ const updateOpenAIKeyEndpoint = async () => {
return;
}
- if (!allowSave.value) {
- return;
- }
-
if (
state.openAIKey !== maskKey(openAIKeySetting?.value?.stringValue) ||
!state.openAIKey.includes("***")
diff --git a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
index ad1e4e8bf4..036af7c81d 100644
--- a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
+++ b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
@@ -97,7 +97,7 @@
<div class="flex justify-end">
<NButton
type="primary"
- :disabled="!allowSave"
+ :disabled="!allowEdit || !allowSave"
@click.prevent="updateAnnouncementSetting"
>
{{ $t("common.update") }}
@@ -119,22 +119,24 @@ import { cloneDeep, isEqual } from "lodash-es";
import { computed, reactive, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { AnnouncementLevelSelect } from "@/components/v2";
-import { pushNotification, useCurrentUserV1, featureToRef } from "@/store";
+import { pushNotification, featureToRef } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import {
Announcement,
Announcement_AlertLevel,
} from "@/types/proto/v1/setting_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
interface LocalState {
announcement: Announcement;
showFeatureModal: boolean;
}
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const hasAnnouncementSetting = featureToRef("bb.feature.announcement");
const defaultAnnouncement = function (): Announcement {
@@ -157,15 +159,7 @@ watchEffect(() => {
}
});
-const allowEdit = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
-
const allowSave = computed((): boolean => {
- if (!allowEdit.value) {
- return false;
- }
-
if (
settingV1Store.workspaceProfileSetting?.announcement === undefined &&
state.announcement.text === ""
@@ -185,10 +179,6 @@ const updateAnnouncementSetting = async () => {
return;
}
- if (!allowSave.value) {
- return;
- }
-
if (state.announcement.text === "" && state.announcement.link !== "") {
state.announcement.link = "";
}
diff --git a/frontend/src/components/GeneralSetting/BrandingSetting.vue b/frontend/src/components/GeneralSetting/BrandingSetting.vue
index 34b555533f..bedf65e7aa 100644
--- a/frontend/src/components/GeneralSetting/BrandingSetting.vue
+++ b/frontend/src/components/GeneralSetting/BrandingSetting.vue
@@ -79,7 +79,10 @@
</NTooltip>
</div>
<div class="flex justify-end gap-x-3">
- <NPopconfirm v-if="allowDelete" @positive-click="deleteLogo">
+ <NPopconfirm
+ v-if="allowEdit && allowDelete"
+ @positive-click="deleteLogo"
+ >
<template #trigger>
<NButton :disabled="!allowEdit">
{{ $t("common.delete") }}
@@ -91,7 +94,7 @@
</NPopconfirm>
<NButton
type="primary"
- :disabled="!allowSave"
+ :disabled="!allowEdit || !allowSave"
@click.prevent="uploadLogo"
>
<FeatureBadge
@@ -115,9 +118,8 @@
import { NPopconfirm } from "naive-ui";
import { computed, reactive, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification, useCurrentUserV1 } from "@/store";
+import { featureToRef, pushNotification } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-import { hasWorkspacePermissionV2 } from "@/utils";
interface LocalState {
displayName?: string;
@@ -127,6 +129,10 @@ interface LocalState {
showFeatureModal: boolean;
}
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const maxFileSizeInMiB = 2;
const supportImageExtensions = [".jpg", ".jpeg", ".png", ".webp", ".svg"];
@@ -154,25 +160,16 @@ watchEffect(() => {
state.logoUrl = settingV1Store.brandingLogo;
});
-const currentUserV1 = useCurrentUserV1();
-
-const allowEdit = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
-
const valid = computed((): boolean => {
return !!state.displayName || !!state.logoFile;
});
const allowDelete = computed(() => {
- if (!allowEdit.value) return false;
return settingV1Store.brandingLogo !== "";
});
const allowSave = computed((): boolean => {
- return (
- allowEdit.value && state.logoFile !== null && valid.value && !state.loading
- );
+ return state.logoFile !== null && valid.value && !state.loading;
});
const hasBrandingFeature = featureToRef("bb.feature.branding");
@@ -206,9 +203,6 @@ const deleteLogo = async () => {
};
const uploadLogo = async () => {
- if (!allowSave.value) {
- return;
- }
if (!hasBrandingFeature.value) {
state.showFeatureModal = true;
return;
diff --git a/frontend/src/components/GeneralSetting/NetworkSetting.vue b/frontend/src/components/GeneralSetting/NetworkSetting.vue
index 51dc63e90a..df028609b5 100644
--- a/frontend/src/components/GeneralSetting/NetworkSetting.vue
+++ b/frontend/src/components/GeneralSetting/NetworkSetting.vue
@@ -66,7 +66,7 @@
<div class="flex justify-end">
<NButton
type="primary"
- :disabled="!allowSave"
+ :disabled="!allowEdit || !allowSave"
@click.prevent="updateNetworkSetting"
>
{{ $t("common.update") }}
@@ -80,9 +80,12 @@
<script lang="ts" setup>
import { computed, reactive, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import { pushNotification, useCurrentUserV1 } from "@/store";
+import { pushNotification } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-import { hasWorkspacePermissionV2 } from "@/utils";
+
+defineProps<{
+ allowEdit: boolean;
+}>();
interface LocalState {
externalUrl: string;
@@ -91,7 +94,6 @@ interface LocalState {
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>({
externalUrl: "",
@@ -104,15 +106,7 @@ watchEffect(() => {
settingV1Store.workspaceProfileSetting?.gitopsWebhookUrl ?? "";
});
-const allowEdit = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
-
const allowSave = computed((): boolean => {
- if (!allowEdit.value) {
- return false;
- }
-
const externalUrlChanged =
state.externalUrl !==
(settingV1Store.workspaceProfileSetting?.externalUrl ?? "");
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index 6db1651904..01b326cd00 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -112,7 +112,7 @@
}}
</div>
</div>
- <SignInFrequencySetting />
+ <SignInFrequencySetting :allow-edit="allowEdit" />
</div>
</div>
@@ -131,7 +131,6 @@ import { useI18n } from "vue-i18n";
import {
featureToRef,
pushNotification,
- useCurrentUserV1,
useActuatorV1Store,
usePolicyV1Store,
} from "@/store";
@@ -141,16 +140,19 @@ import {
PolicyResourceType,
PolicyType,
} from "@/types/proto/v1/org_policy_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
import SignInFrequencySetting from "./SignInFrequencySetting.vue";
interface LocalState {
featureNameForModal?: FeatureType;
}
+
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const state = reactive<LocalState>({});
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const actuatorStore = useActuatorV1Store();
const policyV1Store = usePolicyV1Store();
@@ -159,9 +161,6 @@ const hasWatermarkFeature = featureToRef("bb.feature.branding");
const has2FAFeature = featureToRef("bb.feature.2fa");
const hasDisallowSignupFeature = featureToRef("bb.feature.disallow-signup");
-const allowEdit = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
const watermarkEnabled = computed((): boolean => {
return (
settingV1Store.getSettingByName("bb.workspace.watermark")?.value
diff --git a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
index e1da96134c..37bd59b7c3 100644
--- a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
+++ b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
@@ -9,18 +9,21 @@
<p class="text-sm text-gray-400 mt-1">
{{ $t("settings.general.workspace.sign-in-frequency.description") }}
</p>
- <NTooltip placement="top-start" :disabled="allowEdit">
+ <NTooltip placement="top-start" :disabled="allowChangeSetting">
<template #trigger>
<div class="mt-3 w-full flex flex-row justify-start items-center">
<NInputNumber
v-model:value="state.inputValue"
class="w-20 mr-4"
- :disabled="!allowEdit"
+ :disabled="!allowChangeSetting"
:min="1"
:max="state.timeFormat === 'HOURS' ? 23 : undefined"
:precision="0"
/>
- <NRadioGroup v-model:value="state.timeFormat" :disabled="!allowEdit">
+ <NRadioGroup
+ v-model:value="state.timeFormat"
+ :disabled="!allowChangeSetting"
+ >
<NRadio
:value="'HOURS'"
:label="$t('settings.general.workspace.sign-in-frequency.hours')"
@@ -50,11 +53,10 @@ import { useDebounceFn } from "@vueuse/core";
import { NInputNumber, NRadioGroup, NRadio } from "naive-ui";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification, useCurrentUserV1 } from "@/store";
+import { featureToRef, pushNotification } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import { FeatureType, defaultTokenDurationInHours } from "@/types";
import { Duration } from "@/types/proto/google/protobuf/duration";
-import { hasWorkspacePermissionV2 } from "@/utils";
const getInitialState = (): LocalState => {
const defaultState: LocalState = {
@@ -81,18 +83,18 @@ interface LocalState {
featureNameForModal?: FeatureType;
}
+const props = defineProps<{
+ allowEdit: boolean;
+}>();
+
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>(getInitialState());
const hasSecureTokenFeature = featureToRef("bb.feature.secure-token");
-const allowEdit = computed((): boolean => {
- return (
- hasSecureTokenFeature.value &&
- hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set")
- );
+const allowChangeSetting = computed(() => {
+ return hasSecureTokenFeature.value && props.allowEdit;
});
const handleValueFieldClick = () => {
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
index 93c707f85e..b09403e81e 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
@@ -15,7 +15,7 @@
v-model:value="state.category"
:options="categoryOptions"
:placeholder="$t('schema-template.form.unclassified')"
- :disabled="!allowEdit"
+ :disabled="!readonly"
:consistent-menu-width="true"
/>
</div>
@@ -28,7 +28,7 @@
<InstanceEngineRadioGrid
v-model:engine="state.engine"
:engine-list="engineList"
- :disabled="!allowEdit"
+ :disabled="!readonly"
class="grid-cols-4 gap-2"
/>
</div>
@@ -44,7 +44,7 @@
<NInput
v-model:value="state.column!.name"
placeholder="column name"
- :disabled="!allowEdit"
+ :disabled="!readonly"
/>
</div>
@@ -54,7 +54,7 @@
</label>
<div class="flex items-center gap-x-2 mt-3 text-sm">
{{ columnSemanticType?.title }}
- <div v-if="allowEdit" class="flex items-center">
+ <div v-if="readonly" class="flex items-center">
<MiniActionButton
v-if="columnSemanticType"
@click.prevent="onSemanticTypeApply('')"
@@ -79,7 +79,7 @@
:classification="state.column?.classification"
:classification-config="classificationConfig"
/>
- <div v-if="allowEdit" class="flex items-center">
+ <div v-if="readonly" class="flex items-center">
<MiniActionButton
v-if="state.column?.classification"
@click.prevent="state.column!.classification = ''"
@@ -114,7 +114,7 @@
? schemaTemplateColumnTypeOptions
: dataTypeOptions
"
- :disabled="!allowEdit"
+ :disabled="!readonly"
placeholder="column type"
@update:value="state.column!.type = $event"
/>
@@ -130,7 +130,7 @@
<DropdownInput
:value="getColumnDefaultDisplayString(state.column!)||null"
:options="defaultValueOptions"
- :disabled="!allowEdit"
+ :disabled="!readonly"
:placeholder="getColumnDefaultValuePlaceholder(state.column!)"
@update:value="handleColumnDefaultChange"
/>
@@ -146,7 +146,7 @@
<NSwitch
v-model:value="state.column!.nullable"
:text="false"
- :disabled="!allowEdit"
+ :disabled="!readonly"
/>
</div>
</div>
@@ -160,7 +160,7 @@
v-model:value="state.column!.userComment"
type="textarea"
:autosize="{ minRows: 3, maxRows: 3 }"
- :disabled="!allowEdit"
+ :disabled="!readonly"
/>
</div>
</div>
@@ -187,7 +187,7 @@
{{ $t("common.cancel") }}
</NButton>
<NButton
- v-if="allowEdit"
+ v-if="readonly"
:disabled="submitDisabled"
type="primary"
@click.prevent="submit"
@@ -242,11 +242,7 @@ import {
InstanceEngineRadioGrid,
MiniActionButton,
} from "@/components/v2";
-import {
- useSettingV1Store,
- useNotificationStore,
- useCurrentUserV1,
-} from "@/store";
+import { useSettingV1Store, useNotificationStore } from "@/store";
import {
ColumnConfig,
ColumnMetadata,
@@ -259,7 +255,6 @@ import {
getDataTypeSuggestionList,
convertKVListToLabels,
convertLabelsToKVList,
- hasWorkspacePermissionV2,
} from "@/utils";
import ColumnDefaultValueExpressionModal from "../SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue";
import SemanticTypesDrawer from "../SensitiveData/components/SemanticTypesDrawer.vue";
@@ -296,14 +291,7 @@ const state = reactive<LocalState>({
kvList: [],
});
const { t } = useI18n();
-const currentUser = useCurrentUserV1();
const settingStore = useSettingV1Store();
-const allowEdit = computed(() => {
- return (
- hasWorkspacePermissionV2(currentUser.value, "bb.settings.set") &&
- !props.readonly
- );
-});
const semanticTypeList = computed(() => {
return (
diff --git a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue b/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
index 8435d3e006..0b3d7e1719 100644
--- a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
+++ b/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
@@ -17,7 +17,7 @@
v-model:value="state.category"
:options="categoryOptions"
:placeholder="$t('schema-template.form.unclassified')"
- :disabled="!allowEdit"
+ :disabled="!readonly"
:consistent-menu-width="true"
/>
</div>
@@ -30,7 +30,7 @@
<InstanceEngineRadioGrid
v-model:engine="state.engine"
:engine-list="engineList"
- :disabled="!allowEdit"
+ :disabled="!readonly"
class="grid-cols-4 gap-2"
/>
</div>
@@ -44,7 +44,7 @@
:classification="state.table?.classification"
:classification-config="classificationConfig"
/>
- <div v-if="allowEdit" class="flex">
+ <div v-if="readonly" class="flex">
<MiniActionButton
v-if="state.table?.classification"
@click.prevent="state.table!.classification = ''"
@@ -71,7 +71,7 @@
<NInput
v-model:value="state.table!.name"
placeholder="table name"
- :disabled="!allowEdit"
+ :disabled="!readonly"
/>
</div>
@@ -84,13 +84,13 @@
v-model:value="state.table!.userComment"
type="textarea"
:autosize="{ minRows: 3, maxRows: 3 }"
- :disabled="!allowEdit"
+ :disabled="!readonly"
/>
</div>
<div class="col-span-4">
<div
- v-if="allowEdit"
+ v-if="readonly"
class="w-full py-2 flex items-center space-x-2"
>
<NButton size="small" :disabled="false" @click="onColumnAdd">
@@ -112,7 +112,7 @@
</NButton>
</div>
<TableColumnEditor
- :readonly="!allowEdit"
+ :readonly="!readonly"
:show-foreign-key="false"
:table="state.table"
:engine="state.engine"
@@ -135,7 +135,7 @@
{{ $t("common.cancel") }}
</NButton>
<NButton
- v-if="allowEdit"
+ v-if="readonly"
:disabled="submitDisabled"
type="primary"
@click.prevent="onSubmit"
@@ -185,11 +185,7 @@ import {
DrawerContent,
InstanceEngineRadioGrid,
} from "@/components/v2";
-import {
- useSettingV1Store,
- useNotificationStore,
- useCurrentUserV1,
-} from "@/store";
+import { useSettingV1Store, useNotificationStore } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import { ColumnMetadata, TableConfig } from "@/types/proto/v1/database_service";
import {
@@ -203,11 +199,7 @@ import {
Table,
convertColumnMetadataToColumn,
} from "@/types/v1/schemaEditor";
-import {
- arraySwap,
- hasWorkspacePermissionV2,
- instanceV1AllowsReorderColumns,
-} from "@/utils";
+import { arraySwap, instanceV1AllowsReorderColumns } from "@/utils";
import FieldTemplates from "@/views/SchemaTemplate/FieldTemplates.vue";
import { engineList, categoryList, classificationConfig } from "./utils";
@@ -241,14 +233,7 @@ const state = reactive<LocalState>({
showFieldTemplateDrawer: false,
});
const { t } = useI18n();
-const currentUser = useCurrentUserV1();
const settingStore = useSettingV1Store();
-const allowEdit = computed(() => {
- return (
- hasWorkspacePermissionV2(currentUser.value, "bb.settings.set") &&
- !props.readonly
- );
-});
const categoryOptions = computed(() => {
return categoryList.value.map<SelectOption>((category) => ({
diff --git a/frontend/src/layouts/SettingLayout.vue b/frontend/src/layouts/SettingLayout.vue
index 914a708564..5a8dbdc119 100644
--- a/frontend/src/layouts/SettingLayout.vue
+++ b/frontend/src/layouts/SettingLayout.vue
@@ -1,6 +1,6 @@
<template>
<div class="px-6 pb-6 pt-2">
- <router-view v-if="hasPermission" />
+ <router-view v-if="hasPermission" :allow-edit="allowEdit" v-bind="$attrs" />
<NoPermissionPlaceholder v-else />
</div>
</template>
@@ -25,4 +25,8 @@ const hasPermission = computed(() => {
hasWorkspacePermissionV2(currentUser.value, permission)
);
});
+
+const allowEdit = computed((): boolean => {
+ return hasWorkspacePermissionV2(currentUser.value, "bb.settings.set");
+});
</script>
diff --git a/frontend/src/views/SettingWorkspaceCustomApproval.vue b/frontend/src/views/SettingWorkspaceCustomApproval.vue
index ae72c719bb..1da9e27143 100644
--- a/frontend/src/views/SettingWorkspaceCustomApproval.vue
+++ b/frontend/src/views/SettingWorkspaceCustomApproval.vue
@@ -23,7 +23,7 @@
</template>
<script lang="ts" setup>
-import { computed, onMounted, reactive, ref, toRef } from "vue";
+import { onMounted, reactive, ref, toRef } from "vue";
import {
CustomApproval,
ApprovalRuleDialog,
@@ -35,16 +35,18 @@ import { useRouteHash } from "@/composables/useRouteHash";
import {
featureToRef,
useWorkspaceApprovalSettingStore,
- useCurrentUserV1,
useRiskStore,
} from "@/store";
-import { hasWorkspacePermissionV2 } from "@/utils";
interface LocalState {
ready: boolean;
showFeatureModal: boolean;
}
+const props = defineProps<{
+ allowEdit: boolean;
+}>();
+
const state = reactive<LocalState>({
ready: false,
showFeatureModal: false,
@@ -52,15 +54,10 @@ const state = reactive<LocalState>({
const tab = useRouteHash("rules", TabValueList, "replace");
const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
-const currentUserV1 = useCurrentUserV1();
-const allowAdmin = computed(() => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
-
provideCustomApprovalContext({
hasFeature: hasCustomApprovalFeature,
showFeatureModal: toRef(state, "showFeatureModal"),
- allowAdmin,
+ allowAdmin: toRef(props, "allowEdit"),
ready: toRef(state, "ready"),
tab,
dialog: ref(),
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index 7ea423e5e0..128c922849 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -1,10 +1,10 @@
<template>
<div class="space-y-4 divide-y divide-block-border">
- <NetworkSetting v-if="!isSaaSMode" />
- <BrandingSetting />
- <SecuritySetting />
- <AIAugmentationSetting />
- <AnnouncementSetting />
+ <NetworkSetting v-if="!isSaaSMode" :allow-edit="allowEdit" />
+ <BrandingSetting :allow-edit="allowEdit" />
+ <SecuritySetting :allow-edit="allowEdit" />
+ <AIAugmentationSetting :allow-edit="allowEdit" />
+ <AnnouncementSetting :allow-edit="allowEdit" />
</div>
</template>
@@ -21,6 +21,10 @@ import {
import { useActuatorV1Store } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const actuatorStore = useActuatorV1Store();
onMounted(async () => {
diff --git a/frontend/src/views/SettingWorkspaceMailDelivery.vue b/frontend/src/views/SettingWorkspaceMailDelivery.vue
index b3bfa3aa24..6d6d121494 100644
--- a/frontend/src/views/SettingWorkspaceMailDelivery.vue
+++ b/frontend/src/views/SettingWorkspaceMailDelivery.vue
@@ -183,14 +183,13 @@ import { SelectOption, NCheckbox } from "naive-ui";
import { ClientError } from "nice-grpc-web";
import { computed, onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
-import { pushNotification, useCurrentUserV1 } from "@/store";
+import { pushNotification } from "@/store";
import { useWorkspaceMailDeliverySettingStore } from "@/store/modules/workspaceMailDeliverySetting";
import {
SMTPMailDeliverySettingValue,
SMTPMailDeliverySettingValue_Authentication,
SMTPMailDeliverySettingValue_Encryption,
} from "@/types/proto/v1/setting_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
interface LocalState {
originMailDeliverySetting?: SMTPMailDeliverySettingValue;
@@ -200,6 +199,11 @@ interface LocalState {
isCreateOrUpdateLoading: boolean;
useEmptyPassword: boolean;
}
+
+const props = defineProps<{
+ allowEdit: boolean;
+}>();
+
const { t } = useI18n();
const defaultMailDeliverySetting = function (): SMTPMailDeliverySettingValue {
@@ -216,7 +220,6 @@ const defaultMailDeliverySetting = function (): SMTPMailDeliverySettingValue {
};
};
-const currentUser = useCurrentUserV1();
const state = reactive<LocalState>({
mailDeliverySetting: defaultMailDeliverySetting(),
testMailTo: "",
@@ -227,10 +230,6 @@ const state = reactive<LocalState>({
const store = useWorkspaceMailDeliverySettingStore();
-const hasPermission = computed(() => {
- return hasWorkspacePermissionV2(currentUser.value, "bb.settings.set");
-});
-
const mailDeliverySettingButtonText = computed(() => {
return state.originMailDeliverySetting === undefined
? t("common.create")
@@ -238,7 +237,7 @@ const mailDeliverySettingButtonText = computed(() => {
});
const allowMailDeliveryActionButton = computed(() => {
return (
- hasPermission.value &&
+ props.allowEdit &&
(state.useEmptyPassword ||
!isEqual(state.originMailDeliverySetting, state.mailDeliverySetting))
);
diff --git a/frontend/src/views/SettingWorkspaceSchemaTemplate.vue b/frontend/src/views/SettingWorkspaceSchemaTemplate.vue
index 0461d29715..d45e6672ce 100644
--- a/frontend/src/views/SettingWorkspaceSchemaTemplate.vue
+++ b/frontend/src/views/SettingWorkspaceSchemaTemplate.vue
@@ -8,7 +8,7 @@
>
<FieldTemplates
:show-engine-filter="true"
- :readonly="!hasFeature || !hasPermission"
+ :readonly="!hasFeature || !allowEdit"
/>
</NTabPane>
<NTabPane
@@ -17,14 +17,14 @@
>
<TableTemplates
:show-engine-filter="true"
- :readonly="!hasFeature || !hasPermission"
+ :readonly="!hasFeature || !allowEdit"
/>
</NTabPane>
<NTabPane
name="COLUMN_TYPE_RESTRICTION"
:tab="$t('schema-template.column-type-restriction.self')"
>
- <ColumnTypes :readonly="!hasFeature || !hasPermission" />
+ <ColumnTypes :readonly="!hasFeature || !allowEdit" />
</NTabPane>
</NTabs>
</div>
@@ -33,10 +33,8 @@
<script lang="ts" setup>
import { NTabs, NTabPane } from "naive-ui";
import { reactive, watch } from "vue";
-import { computed } from "vue";
import { useRoute, useRouter } from "vue-router";
-import { featureToRef, useCurrentUserV1 } from "@/store";
-import { hasWorkspacePermissionV2 } from "@/utils";
+import { featureToRef } from "@/store";
import ColumnTypes from "@/views/SchemaTemplate/ColumnTypes.vue";
import FieldTemplates from "@/views/SchemaTemplate/FieldTemplates.vue";
import TableTemplates from "@/views/SchemaTemplate/TableTemplates.vue";
@@ -45,17 +43,17 @@ interface LocalState {
selectedTab: "FIELD_TEMPLATE" | "COLUMN_TYPE_RESTRICTION" | "TABLE_TEMPLATE";
}
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const route = useRoute();
const router = useRouter();
const state = reactive<LocalState>({
selectedTab: "FIELD_TEMPLATE",
});
-const currentUser = useCurrentUserV1();
const hasFeature = featureToRef("bb.feature.schema-template");
-const hasPermission = computed(() => {
- return hasWorkspacePermissionV2(currentUser.value, "bb.settings.set");
-});
watch(
() => route.hash,
diff --git a/frontend/src/views/SettingWorkspaceSubscription.vue b/frontend/src/views/SettingWorkspaceSubscription.vue
index 5b92908830..36b5dd6e1f 100644
--- a/frontend/src/views/SettingWorkspaceSubscription.vue
+++ b/frontend/src/views/SettingWorkspaceSubscription.vue
@@ -56,7 +56,7 @@
{{ $t("subscription.instance-assignment.used-and-total-license") }}
</dt>
<dd
- v-if="canManageSubscription"
+ v-if="allowEdit"
class="mt-1 text-4xl flex items-center gap-x-2 cursor-pointer group"
@click="state.showInstanceAssignmentDrawer = true"
>
@@ -72,10 +72,7 @@
</dt>
<dd class="mt-1 text-4xl">{{ expireAt || "n/a" }}</dd>
</div>
- <div
- v-if="subscriptionStore.canTrial && canManageSubscription"
- class="my-3"
- >
+ <div v-if="subscriptionStore.canTrial && allowEdit" class="my-3">
<dt class="text-gray-400">
{{ $t("subscription.try-for-free") }}
</dt>
@@ -109,7 +106,7 @@
</div>
</dl>
<div
- v-if="canManageSubscription && subscriptionStore.isSelfHostLicense"
+ v-if="allowEdit && subscriptionStore.isSelfHostLicense"
class="w-full mt-4 flex flex-col"
>
<NInput
@@ -154,13 +151,11 @@ import { useI18n } from "vue-i18n";
import { useLanguage } from "@/composables/useLanguage";
import {
pushNotification,
- useCurrentUserV1,
useInstanceV1Store,
useSubscriptionV1Store,
} from "@/store";
import { ENTERPRISE_INQUIRE_LINK } from "@/types";
import { PlanType } from "@/types/proto/v1/subscription_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
import PricingTable from "../components/PricingTable/";
interface LocalState {
@@ -171,11 +166,14 @@ interface LocalState {
showInstanceAssignmentDrawer: boolean;
}
+defineProps<{
+ allowEdit: boolean;
+}>();
+
const subscriptionStore = useSubscriptionV1Store();
const instanceV1Store = useInstanceV1Store();
const { t } = useI18n();
const { locale } = useLanguage();
-const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>({
loading: false,
@@ -258,8 +256,4 @@ const inquireEnterprise = () => {
window.open(ENTERPRISE_INQUIRE_LINK, "_blank");
}
};
-
-const canManageSubscription = computed((): boolean => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.settings.set");
-});
</script>