From ddb803a82fc9093f4b684a551c53956bed9ad05e Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Thu, 6 Feb 2025 19:04:30 +0000 Subject: [PATCH] introduces 1st batch of permissions and usage quota control --- src/App.vue | 18 ++++++---- src/components/AddSheet.vue | 52 +++++++++++++++++++++++++---- src/components/ArchiveUrl.vue | 59 +++++++++++++++++++++++++++++++-- src/components/ManageSheets.vue | 13 +++++--- src/store/index.js | 46 ++++++++++++++++++++----- src/views/ArchivesView.vue | 2 -- 6 files changed, 159 insertions(+), 31 deletions(-) diff --git a/src/App.vue b/src/App.vue index ec4f7f2..c729bb6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,7 +4,7 @@ - + - This tool uses Bellingcat's Auto Archiver to - archive online content. -
For more information see - our Github repository - and the API and the UI. +
+ This tool uses Bellingcat's Auto Archiver under the hood to archive online content. +
+ For more information about it see associated article. +
@@ -70,10 +71,13 @@ html { padding: 0.2em 0.4em; } -footer, .v-footer, .v-footer div { +footer, +.v-footer, +.v-footer div { margin: 0px; padding: 0px; } + .v-footer { max-height: 125px; } diff --git a/src/components/AddSheet.vue b/src/components/AddSheet.vue index 793ad15..a1dead4 100644 --- a/src/components/AddSheet.vue +++ b/src/components/AddSheet.vue @@ -12,8 +12,8 @@ - + Detected Spreadsheet id: {{ spreadsheetId }} @@ -30,6 +30,28 @@ Add Existing Sheet + + + Quota and rules for group {{ group }}: +
    +
  • + Active sheets: + {{ groupUsage.total_sheets || 0 }} out of + {{ displayPermissionValue(groupPermissions?.max_sheets, "")}} + maxed out +
  • +
  • Monthly URLs: {{ groupUsage.monthly_urls || 0 }} out of {{ + displayPermissionValue(groupPermissions?.max_monthly_urls, " URLs") }}
  • +
  • Monthly MBs: {{ groupUsage.monthly_mbs || 0 }} out of {{ + displayPermissionValue(groupPermissions?.max_monthly_mbs, " MBs") }}
  • +
  • How long will we store these archives: {{ + displayPermissionValue(groupPermissions?.max_archive_lifespan_months, " months") }} +
  • +
  • You {{ groupPermissions?.manually_trigger_sheet?"can":"cannot" }} manually trigger sheeets in this group.
  • +
+
+
+ @@ -63,8 +85,7 @@ export default { group: "please select", - availableFrequencies: ["daily", "hourly"].map(f => ({ title: f, value: f })), - frequency: "daily", + frequency: "please select group", newSheetId: "", }; @@ -74,14 +95,27 @@ export default { return this.$store.state.user; }, requiredData() { - return this.sheetName && this.availableGroups?.some(g => g.value === this.group) && this.availableFrequencies?.some(f => f.value === this.frequency); + return this.sheetName && this.availableGroups?.some(g => g.value === this.group) && this.availableFrequencies?.some(f => f === this.frequency) && !this.maxedOutGroupQuota; }, requiredDataExisting() { - return this.sheetName && this.spreadsheetId && this.availableGroups?.some(g => g.value === this.group) && this.availableFrequencies?.some(f => f.value === this.frequency); + return this.sheetName && this.spreadsheetId && this.availableGroups?.some(g => g.value === this.group) && this.availableFrequencies?.some(f => f === this.frequency) && !this.maxedOutGroupQuota; }, availableGroups() { return (this.$store.state.user?.groups || []).map(g => ({ title: g, value: g })); }, + availableFrequencies() { + return this.$store.state.user?.permissions?.[this.group]?.sheet_frequency || []; + }, + groupPermissions() { + return this.$store.state.user?.permissions?.[this.group] || {}; + }, + groupUsage() { + return this.$store.state.user?.usage?.["groups"]?.[this.group] || {}; + }, + maxedOutGroupQuota(){ + if (this.groupPermissions.max_sheets === -1) return false; + return this.groupUsage.total_sheets >= this.groupPermissions.max_sheets; + }, spreadsheetId() { if ( this.sheetUrlId.startsWith("http") && @@ -107,6 +141,7 @@ export default { this.loading = true; this.newSheetId = ""; this.$store.dispatch("createSheet", this.sheetName).then((res) => { + this.$store.dispatch("checkUserUsage"); if (!res.success) throw new Error(res.result); this.newSheetId = res.result; this.addSheetToAPI(this.newSheetId); @@ -140,6 +175,7 @@ export default { if (response.status === 201) { this.showSnackbar(`Sheet created successfully!`, "green"); this.$store.dispatch("getSheets"); + this.$store.dispatch("checkUserUsage"); } else { throw new Error(JSON.stringify(j)); } @@ -152,6 +188,10 @@ export default { this.sheetUrlId = ""; this.group = "please select"; }); + }, + displayPermissionValue(value, extraWord) { + if (value === undefined) { return "not set"; } + return value == -1 ? "no limit" : value + extraWord; } }, }; diff --git a/src/components/ArchiveUrl.vue b/src/components/ArchiveUrl.vue index 33fe94e..0bc56c0 100644 --- a/src/components/ArchiveUrl.vue +++ b/src/components/ArchiveUrl.vue @@ -1,5 +1,5 @@