/
EnterBucketPassphraseDialog.vue
210 lines (182 loc) · 7.01 KB
/
EnterBucketPassphraseDialog.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-dialog
v-model="model"
:persistent="isLoading"
width="400px"
transition="fade-transition"
>
<v-card ref="innerContent" rounded="xlg">
<v-card-item class="pa-5 pl-7">
<template #prepend>
<img class="d-block" src="@/assets/createAccessGrantFlow/accessEncryption.svg" alt="icon">
</template>
<v-card-title class="font-weight-bold">
Enter passphrase
</v-card-title>
<template #append>
<v-btn
icon="$close"
variant="text"
size="small"
color="default"
:disabled="isLoading"
@click="model = false"
/>
</template>
</v-card-item>
<v-divider />
<v-card-item class="pa-7 pb-3">
<v-form v-model="formValid" @submit.prevent="onContinue">
<v-row>
<v-col cols="12">
<p>
Enter your encryption passphrase to view and manage the data in this project.
</p>
</v-col>
<v-col cols="12">
<v-text-field
id="Encryption Passphrase"
v-model="passphrase"
:base-color="isWarningState ? 'warning' : ''"
label="Encryption Passphrase"
:type="isPassphraseVisible ? 'text' : 'password'"
variant="outlined"
:hide-details="false"
:rules="[ RequiredRule ]"
autofocus
required
>
<template #append-inner>
<password-input-eye-icons
:is-visible="isPassphraseVisible"
type="passphrase"
@toggleVisibility="isPassphraseVisible = !isPassphraseVisible"
/>
</template>
</v-text-field>
</v-col>
</v-row>
</v-form>
<v-alert
v-if="isWarningState"
class="mt-3"
density="compact"
type="warning"
text="Object count mismatch: files may be uploaded with a different passphrase, or files have been recently deleted and are not reflected yet."
/>
</v-card-item>
<v-divider />
<v-card-actions class="pa-4">
<v-col>
<v-btn
variant="outlined"
color="default"
block
:disabled="isLoading"
@click="model = false"
>
Cancel
</v-btn>
</v-col>
<v-col>
<v-btn
:color="isWarningState ? 'default' : 'primary'"
:variant="isWarningState ? 'outlined' : 'flat'"
block
:loading="isLoading"
:disabled="!formValid"
@click="onContinue"
>
Continue ->
</v-btn>
</v-col>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script setup lang="ts">
import { Component, computed, ref, watch } from 'vue';
import { VForm, VRow, VCol, VTextField, VCardItem, VDivider, VCardTitle, VBtn, VCard, VCardActions, VDialog, VAlert } from 'vuetify/components';
import { RequiredRule } from '@/types/common';
import { useAnalyticsStore } from '@/store/modules/analyticsStore';
import { useBucketsStore } from '@/store/modules/bucketsStore';
import { useAppStore } from '@/store/modules/appStore';
import { Bucket } from '@/types/buckets';
import { useProjectsStore } from '@/store/modules/projectsStore';
import { useLoading } from '@/composables/useLoading';
import { AnalyticsErrorEventSource } from '@/utils/constants/analyticsEventNames';
import { useNotify } from '@/utils/hooks';
import PasswordInputEyeIcons from '@/components/PasswordInputEyeIcons.vue';
const analyticsStore = useAnalyticsStore();
const bucketsStore = useBucketsStore();
const appStore = useAppStore();
const projectsStore = useProjectsStore();
const notify = useNotify();
const { isLoading, withLoading } = useLoading();
const passphrase = ref<string>('');
const isPassphraseVisible = ref<boolean>(false);
const isWarningState = ref<boolean>(false);
const innerContent = ref<Component | null>(null);
const formValid = ref<boolean>(false);
const model = defineModel<boolean>({ required: true });
const emit = defineEmits<{
(event: 'passphraseEntered'): void,
}>();
/**
* Returns chosen bucket name from store.
*/
const bucketName = computed((): string => {
return bucketsStore.state.fileComponentBucketName;
});
/**
* Returns selected bucket name object count.
*/
const bucketObjectCount = computed((): number => {
const data: Bucket | undefined = bucketsStore.state.page.buckets.find(
(bucket: Bucket) => bucket.name === bucketName.value,
);
return data?.objectCount ?? 0;
});
/**
* Sets access and navigates to object browser.
*/
async function onContinue(): Promise<void> {
if (isLoading.value) return;
if (isWarningState.value) {
bucketsStore.setPromptForPassphrase(false);
model.value = false;
emit('passphraseEntered');
return;
}
isLoading.value = true;
try {
bucketsStore.setPassphrase(passphrase.value);
await bucketsStore.setS3Client(projectsStore.state.selectedProject.id);
const count: number = await bucketsStore.getObjectsCount(bucketName.value);
if (count === 0 && bucketObjectCount.value > 0) {
isWarningState.value = true;
isLoading.value = false;
return;
}
bucketsStore.setPromptForPassphrase(false);
isLoading.value = false;
} catch (error) {
notify.notifyError(error, AnalyticsErrorEventSource.OPEN_BUCKET_MODAL);
isLoading.value = false;
return;
}
model.value = false;
emit('passphraseEntered');
}
watch(innerContent, comp => {
if (!comp) {
passphrase.value = '';
isWarningState.value = false;
}
});
watch(passphrase, () => {
if (isWarningState.value) isWarningState.value = false;
});
</script>