Skip to content

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

chore: expiration time precise to the second (#14505)

ecmadaoae06f0a8bc84
diff --git a/frontend/src/components/ExpirationSelector.vue b/frontend/src/components/ExpirationSelector.vue
index 56316cc923..e4ccafb31d 100644
--- a/frontend/src/components/ExpirationSelector.vue
+++ b/frontend/src/components/ExpirationSelector.vue
@@ -1,9 +1,10 @@
<template>
<NRadioGroup
v-bind="$attrs"
- v-model:value="state.value"
+ :value="state.selected"
class="w-full !grid grid-cols-3 gap-2"
name="radiogroup"
+ @update:value="onSelect"
>
<div
v-for="option in options"
@@ -14,18 +15,18 @@
</div>
<div class="col-span-3 flex flex-row justify-start items-center">
<NRadio :value="-1" :label="$t('issue.grant-request.custom')" />
- <NInputNumber
- v-model:value="state.customValue"
- class="!w-24 ml-2"
- :disabled="!useCustom"
- :min="1"
- :max="maximumRoleExpiration"
- :show-button="false"
- :placeholder="''"
- >
- <template #suffix>{{ $t("common.date.days") }}</template>
- </NInputNumber>
-
+ <NDatePicker
+ :value="
+ state.selected === -1 ? state.expirationTimestampInMS : undefined
+ "
+ :disabled="state.selected !== -1"
+ :actions="null"
+ :update-value-on-close="true"
+ type="datetime"
+ :is-date-disabled="(date: number) => date < Date.now()"
+ clearable
+ @update:value="(val) => (state.expirationTimestampInMS = val)"
+ />
<span v-if="maximumRoleExpiration" class="ml-3 textinfolabel">
{{ $t("settings.general.workspace.maximum-role-expiration.self") }}:
{{ $t("common.date.days", { days: maximumRoleExpiration }) }}
@@ -35,8 +36,8 @@
</template>
<script lang="ts" setup>
-import { NRadio, NRadioGroup, NInputNumber } from "naive-ui";
-import { computed, reactive, watch } from "vue";
+import { NRadio, NRadioGroup, NDatePicker } from "naive-ui";
+import { computed, reactive, watch, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { useSettingV1Store } from "@/store";
@@ -46,28 +47,25 @@ interface ExpirationOption {
}
interface LocalState {
- value: number;
- customValue: number;
+ selected: number;
+ expirationTimestampInMS?: number;
}
const props = defineProps<{
- value: number;
+ timestampInMs?: number;
}>();
const emit = defineEmits<{
- (event: "update", value: number): void;
+ (event: "update:timestampInMs", timestampInMS: number | undefined): void;
}>();
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const state = reactive<LocalState>({
- value: props.value,
- customValue: 7,
+ selected: props.timestampInMs === undefined ? 0 : -1,
});
-const useCustom = computed(() => state.value === -1);
-
const maximumRoleExpiration = computed(() => {
const seconds =
settingV1Store.workspaceProfileSetting?.maximumRoleExpiration?.seconds?.toNumber();
@@ -113,10 +111,27 @@ const options = computed((): ExpirationOption[] => {
return options;
});
+const onSelect = (value: number) => {
+ if (value >= 0) {
+ state.expirationTimestampInMS = value * 24 * 60 * 60 * 1000;
+ } else {
+ state.expirationTimestampInMS = undefined;
+ }
+ state.selected = value;
+};
+
+onMounted(() => {
+ let value = state.selected;
+ if (!options.value.find((o) => o.value === state.selected)) {
+ value = options.value[0].value;
+ }
+ onSelect(value);
+});
+
watch(
- () => [state.value, state.customValue],
+ () => state.expirationTimestampInMS,
() => {
- emit("update", useCustom.value ? state.customValue : state.value);
+ emit("update:timestampInMs", state.expirationTimestampInMS);
}
);
</script>
diff --git a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
index 9d8c871e62..63b9c45ba0 100644
--- a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
+++ b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
@@ -43,9 +43,8 @@
<RequiredStar />
</span>
<ExpirationSelector
+ v-model:timestamp-in-ms="state.expirationTimestampInMS"
class="grid-cols-3 sm:grid-cols-4"
- :value="state.expireDays"
- @update="state.expireDays = $event"
/>
</div>
<div class="w-full flex flex-col justify-start items-start">
@@ -104,7 +103,7 @@ import MaxRowCountSelect from "./MaxRowCountSelect.vue";
interface LocalState {
databaseResources: DatabaseResource[];
- expireDays: number;
+ expirationTimestampInMS?: number;
description: string;
maxRowCount: number;
}
@@ -151,7 +150,7 @@ const extractDatabaseResourcesFromProps = (): Pick<
const currentUser = useCurrentUserV1();
const state = reactive<LocalState>({
...extractDatabaseResourcesFromProps(),
- expireDays: 1,
+ expirationTimestampInMS: undefined,
description: "",
maxRowCount: 1000,
});
@@ -166,6 +165,9 @@ const allowCreate = computed(() => {
) {
return false;
}
+ if (state.expirationTimestampInMS === undefined) {
+ return false;
+ }
return true;
});
@@ -195,12 +197,12 @@ const doCreateIssue = async () => {
if (state.databaseResources) {
expression.push(stringifyDatabaseResources(state.databaseResources));
}
- const expireDays = state.expireDays;
- if (expireDays > 0) {
+ const expirationTimestampInMS = state.expirationTimestampInMS;
+ if (expirationTimestampInMS && expirationTimestampInMS > 0) {
expression.push(
- `request.time < timestamp("${dayjs()
- .add(expireDays, "days")
- .toISOString()}")`
+ `request.time < timestamp("${dayjs(
+ expirationTimestampInMS
+ ).toISOString()}")`
);
}
if (props.role === PresetRoleType.PROJECT_EXPORTER) {
@@ -217,9 +219,9 @@ const doCreateIssue = async () => {
expression: celExpressionString,
});
}
- if (expireDays > 0) {
+ if (expirationTimestampInMS && expirationTimestampInMS > 0) {
newIssue.grantRequest.expiration = Duration.fromPartial({
- seconds: expireDays * 24 * 60 * 60,
+ seconds: dayjs(expirationTimestampInMS).unix() - dayjs().unix(),
});
}
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index 7c4f33530b..4fa8de0690 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -62,9 +62,8 @@
<div class="w-full flex flex-col gap-y-2">
<span>{{ $t("common.expiration") }}</span>
<ExpirationSelector
+ v-model:timestamp-in-ms="state.expirationTimestampInMS"
class="grid-cols-3 sm:grid-cols-4"
- :value="state.expireDays"
- @update="state.expireDays = $event"
/>
</div>
</div>
@@ -81,7 +80,6 @@ import QuerierDatabaseResourceForm from "@/components/GrantRequestPanel/Database
import MaxRowCountSelect from "@/components/GrantRequestPanel/MaxRowCountSelect.vue";
import MembersBindingSelect from "@/components/Member/MembersBindingSelect.vue";
import { ProjectRoleSelect } from "@/components/v2/Select";
-import { useSettingV1Store } from "@/store";
import type { ComposedProject, DatabaseResource } from "@/types";
import { PresetRoleType } from "@/types";
import { Expr } from "@/types/proto/google/type/expr";
@@ -103,7 +101,7 @@ interface LocalState {
memberList: string[];
role?: string;
reason: string;
- expireDays: number;
+ expirationTimestampInMS?: number;
// Querier and exporter options.
databaseResources?: DatabaseResource[];
// Exporter options.
@@ -116,26 +114,12 @@ const getInitialState = (): LocalState => {
memberList: props.binding.members,
reason: "",
// Default to never expire.
- expireDays: 0,
maxRowCount: 1000,
};
- if (maximumRoleExpiration.value) {
- defaultState.expireDays = maximumRoleExpiration.value;
- }
return defaultState;
};
-const maximumRoleExpiration = computed(() => {
- const seconds =
- settingV1Store.workspaceProfileSetting?.maximumRoleExpiration?.seconds?.toNumber();
- if (!seconds) {
- return undefined;
- }
- return Math.floor(seconds / (60 * 60 * 24));
-});
-
-const settingV1Store = useSettingV1Store();
const state = reactive<LocalState>(getInitialState());
watch(
@@ -157,10 +141,10 @@ watch(
props.binding.role = state.role;
}
const expression: string[] = [];
- if (state.expireDays > 0) {
- const now = dayjs();
- const expiresAt = now.add(state.expireDays, "days");
- expression.push(`request.time < timestamp("${expiresAt.toISOString()}")`);
+ if (state.expirationTimestampInMS && state.expirationTimestampInMS > 0) {
+ expression.push(
+ `request.time < timestamp("${dayjs(state.expirationTimestampInMS).toISOString()}")`
+ );
}
if (
state.role === PresetRoleType.SQL_EDITOR_USER ||
@@ -214,10 +198,10 @@ const generateConditionTitle = () => {
}
title.push(conditionSuffix);
}
- if (state.expireDays > 0) {
- const now = dayjs();
- const expiresAt = now.add(state.expireDays, "days");
- title.push(`${now.format("L")}-${expiresAt.format("L")}`);
+ if (state.expirationTimestampInMS && state.expirationTimestampInMS > 0) {
+ title.push(
+ `${dayjs().format("L")}-${dayjs(state.expirationTimestampInMS).format("L")}`
+ );
}
return title.join(" ");
@@ -245,7 +229,13 @@ defineExpose({
if (state.memberList.length <= 0) {
return false;
}
- if ((!state.expireDays && state.expireDays !== 0) || state.expireDays < 0) {
+ if (state.expirationTimestampInMS === undefined) {
+ return false;
+ }
+ if (
+ (!state.expirationTimestampInMS && state.expirationTimestampInMS !== 0) ||
+ state.expirationTimestampInMS < 0
+ ) {
return false;
}
// undefined databaseResources means all databases
diff --git a/frontend/src/components/SensitiveData/GrantAccessForm.vue b/frontend/src/components/SensitiveData/GrantAccessForm.vue
index d9fe8ee969..44a08241bd 100644
--- a/frontend/src/components/SensitiveData/GrantAccessForm.vue
+++ b/frontend/src/components/SensitiveData/GrantAccessForm.vue
@@ -64,6 +64,8 @@
v-model:value="state.expirationTimestamp"
style="width: 100%"
type="datetime"
+ :actions="null"
+ :update-value-on-close="true"
:is-date-disabled="(date: number) => date < Date.now()"
clearable
/>
diff --git a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
index 343df9dadf..22e3df54db 100644
--- a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
+++ b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
@@ -394,6 +394,7 @@ const accessTableColumns = computed(
value={item.expirationTimestamp}
style={"width: 100%"}
type={"datetime"}
+ actions={["confirm"]}
isDateDisabled={(date: number) => date < Date.now()}
clearable={true}
disabled={!hasPermission.value || props.disabled}