Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

feat(enterprise): gate Announcements, limit Community audit log and plans

Jonas Kaninda73981f0e962f
diff --git a/docs/docs/admin/plans.md b/docs/docs/admin/plans.md
index db6c6a7..6481876 100644
--- a/docs/docs/admin/plans.md
+++ b/docs/docs/admin/plans.md
@@ -8,6 +8,12 @@ description: Configure plans with rate limits and resource quotas
Plans define resource limits and rate quotas for workspaces. Administrators can create plans with different tiers and assign them to workspaces.
+:::info Posta Enterprise
+Posta Community manages up to **three** plans, active or not. Creating a fourth needs a
+[Posta Enterprise](https://goposta.dev/enterprise) license; installations that already
+have more keep them, and can still edit, assign and delete them.
+:::
+
:::tip
For the full request/response schema, see the interactive API Reference at `/docs` on your Posta instance.
:::
diff --git a/docs/docs/webhooks/audit-log.md b/docs/docs/webhooks/audit-log.md
index 8bc4135..cf88bee 100644
--- a/docs/docs/webhooks/audit-log.md
+++ b/docs/docs/webhooks/audit-log.md
@@ -12,6 +12,14 @@ Posta maintains two separate audit trails depending on what you need to audit.
The workspace audit log records operational activity scoped to a workspace: API key creation/revocation, template changes, SMTP server changes, webhook changes, and similar configuration actions. Requires the `admin` or `owner` workspace role.
+:::info Posta Enterprise
+Posta Community shows the last **7 days** of the workspace audit log; an older event
+answers `402`. The full history, and workspace audit events in the admin **Events** list,
+need a [Posta Enterprise](https://goposta.dev/enterprise) license. Posta records the events
+in every edition, so installing a license shows the history from before it. The personal
+security log below is part of Posta Community in full.
+:::
+
```
GET /api/v1/workspaces/current/audit-log?page=1&size=20
```
diff --git a/internal/handlers/event_handler.go b/internal/handlers/event_handler.go
index 312a1f7..f00083b 100644
--- a/internal/handlers/event_handler.go
+++ b/internal/handlers/event_handler.go
@@ -22,6 +22,7 @@ package handlers
import (
"time"
+ "github.com/goposta/posta/internal/enterprise"
"github.com/goposta/posta/internal/models"
"github.com/goposta/posta/internal/services/eventbus"
"github.com/goposta/posta/internal/storage/repositories"
@@ -29,8 +30,31 @@ import (
)
type EventHandler struct {
- repo *repositories.EventRepository
- bus *eventbus.EventBus
+ repo *repositories.EventRepository
+ bus *eventbus.EventBus
+ edition enterprise.EE
+}
+
+// CommunityAuditDays is how far back Posta Community shows a workspace audit
+// log. Its full history, and workspace audit events in the platform-wide
+// event list, need a Posta Enterprise license. Every edition records them.
+const CommunityAuditDays = 7
+
+// SetEdition decides how much of the workspace audit trail is shown.
+func (h *EventHandler) SetEdition(ee enterprise.EE) { h.edition = ee }
+
+func (h *EventHandler) licensed() bool {
+ return h.edition != nil && h.edition.Licensed()
+}
+
+// communityAuditSince is the oldest audit event Posta Community shows.
+func communityAuditSince() time.Time {
+ return time.Now().AddDate(0, 0, -CommunityAuditDays)
+}
+
+// isWorkspaceAudit reports whether e is part of a workspace audit trail.
+func isWorkspaceAudit(e *models.Event) bool {
+ return e.Category == models.EventCategoryAudit && e.WorkspaceID != nil
}
type ListEventsRequest struct {
@@ -51,7 +75,7 @@ type EventRequest struct {
// Get returns a single event by ID (admin scope, any category or workspace).
func (h *EventHandler) Get(c *okapi.Context, req *EventRequest) error {
event, err := h.repo.FindByID(uint(req.ID))
- if err != nil {
+ if err != nil || (isWorkspaceAudit(event) && !h.licensed()) {
return c.AbortNotFound("event not found")
}
return ok(c, event)
@@ -66,9 +90,9 @@ func (h *EventHandler) List(c *okapi.Context, req *ListEventsRequest) error {
var err error
if req.Category != "" {
- events, total, err = h.repo.FindByCategory(models.EventCategory(req.Category), req.Search, size, offset)
+ events, total, err = h.repo.FindByCategory(models.EventCategory(req.Category), req.Search, !h.licensed(), size, offset)
} else {
- events, total, err = h.repo.FindAll(req.Search, size, offset)
+ events, total, err = h.repo.FindAll(req.Search, !h.licensed(), size, offset)
}
if err != nil {
return c.AbortInternalServerError("failed to list events")
@@ -94,7 +118,11 @@ func (h *EventHandler) WorkspaceAuditLog(c *okapi.Context, req *ListEventsReques
wsID := c.GetInt("workspace_id")
page, size, offset := normalizePageParams(req.Page, req.Size)
- events, total, err := h.repo.FindByWorkspaceAndCategory(uint(wsID), models.EventCategoryAudit, size, offset)
+ var since time.Time
+ if !h.licensed() {
+ since = communityAuditSince()
+ }
+ events, total, err := h.repo.FindByWorkspaceAndCategory(uint(wsID), models.EventCategoryAudit, since, size, offset)
if err != nil {
return c.AbortInternalServerError("failed to list audit events")
}
@@ -119,6 +147,13 @@ func (h *EventHandler) WorkspaceAuditLogDetail(c *okapi.Context, req *AuditEvent
if event.Category != models.EventCategoryAudit || event.WorkspaceID == nil || *event.WorkspaceID != wsID {
return c.AbortNotFound("audit event not found")
}
+ if !h.licensed() && event.CreatedAt.Before(communityAuditSince()) {
+ edition := h.edition
+ if edition == nil {
+ edition = enterprise.Community()
+ }
+ return licenseAbort(c, edition.Require())
+ }
return ok(c, event)
}
@@ -141,6 +176,9 @@ func (h *EventHandler) Stream(c *okapi.Context) error {
if !ok {
return
}
+ if isWorkspaceAudit(evt) && !h.licensed() {
+ continue
+ }
select {
case msgCh <- okapi.Message{Event: evt.Type, Data: evt}:
case <-ctx.Done():
diff --git a/internal/handlers/plan_handler.go b/internal/handlers/plan_handler.go
index 5c992c4..aef2302 100644
--- a/internal/handlers/plan_handler.go
+++ b/internal/handlers/plan_handler.go
@@ -24,6 +24,7 @@ import (
"net/http"
"github.com/goposta/posta/internal/dto"
+ "github.com/goposta/posta/internal/enterprise"
"github.com/goposta/posta/internal/models"
"github.com/goposta/posta/internal/services/audit"
planpkg "github.com/goposta/posta/internal/services/plan"
@@ -39,8 +40,16 @@ type PlanHandler struct {
userRepo *repositories.UserRepository
planService *planpkg.Service
audit *audit.Logger
+ edition enterprise.EE
}
+// CommunityPlans is how many plans Posta Community configures. More need a
+// Posta Enterprise license.
+const CommunityPlans = 3
+
+// SetEdition gates plans beyond the Community allowance on the license.
+func (h *PlanHandler) SetEdition(ee enterprise.EE) { h.edition = ee }
+
func NewPlanHandler(
planRepo *repositories.PlanRepository,
workspaceRepo *repositories.WorkspaceRepository,
@@ -117,6 +126,21 @@ type WorkspacePlanRequest struct {
// Create creates a new plan.
func (h *PlanHandler) Create(c *okapi.Context, req *CreatePlanRequest) error {
+ // Installations that already have more plans keep them; only adding one
+ // beyond the allowance needs a license.
+ n, err := h.planRepo.Count()
+ if err != nil {
+ return c.AbortInternalServerError("failed to count plans")
+ }
+ if n >= CommunityPlans {
+ edition := h.edition
+ if edition == nil {
+ edition = enterprise.Community()
+ }
+ if err := edition.RequireMutable(); err != nil {
+ return licenseAbort(c, err)
+ }
+ }
userID := uint(c.GetInt("user_id"))
plan := &models.Plan{
diff --git a/internal/routes/admin_routes.go b/internal/routes/admin_routes.go
index a488e45..aeaaa1d 100644
--- a/internal/routes/admin_routes.go
+++ b/internal/routes/admin_routes.go
@@ -308,6 +308,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
Path: pathAnnouncements,
Handler: okapi.H(r.h.announcement.List),
Group: adminGroup,
+ Middlewares: r.licensed(),
Summary: "List announcements",
Description: "Platform notices that have been broadcast, newest first, with how many inboxes each reached.",
Request: &handlers.ListAnnouncementsRequest{},
@@ -318,6 +319,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
Path: pathAnnouncements,
Handler: okapi.H(r.h.announcement.Create),
Group: adminGroup,
+ Middlewares: r.licensedToChange(),
Summary: "Broadcast an announcement",
Description: "Delivers a notice to every active user's in-app inbox immediately. There is no draft state; use retract if it went out wrong.",
Request: &handlers.CreateAnnouncementRequest{},
diff --git a/internal/routes/routes.go b/internal/routes/routes.go
index ab4bb89..30b425f 100644
--- a/internal/routes/routes.go
+++ b/internal/routes/routes.go
@@ -323,6 +323,8 @@ func InitRoutes(app *okapi.Okapi, db *gorm.DB, redisClient *redis.Client, cfg *c
// Plans
r.h.plan = handlers.NewPlanHandler(planRepo, workspaceRepo, userRepo, planService, auditLogger)
+ r.h.plan.SetEdition(edition)
+ r.h.event.SetEdition(edition)
r.h.admin.SetWorkspaceRepo(workspaceRepo, planRepo)
r.h.workspace.SetSeeder(userSeeder)
r.h.workspace.SetPlanService(planService)
diff --git a/internal/routes/workspace_routes.go b/internal/routes/workspace_routes.go
index 537ddde..2eea110 100644
--- a/internal/routes/workspace_routes.go
+++ b/internal/routes/workspace_routes.go
@@ -244,7 +244,7 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
Group: wsGroup,
Middlewares: []okapi.Middleware{middlewares.RequireWorkspaceRole(models.WorkspaceRoleAdmin)},
Summary: "List workspace audit log",
- Description: "Returns the audit trail for the current workspace (admin/owner only)",
+ Description: "Returns the audit trail for the current workspace (admin/owner only). Posta Community returns the last 7 days; the full history needs Posta Enterprise.",
Request: &handlers.ListEventsRequest{},
Response: &dto.PageableResponse[models.Event]{},
Options: []okapi.RouteOption{workspaceHeaderRequired},
@@ -256,7 +256,7 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
Group: wsGroup,
Middlewares: []okapi.Middleware{middlewares.RequireWorkspaceRole(models.WorkspaceRoleAdmin)},
Summary: "Get workspace audit event",
- Description: "Returns a single audit event for the current workspace (admin/owner only)",
+ Description: "Returns a single audit event for the current workspace (admin/owner only). In Posta Community, events older than 7 days answer 402.",
Request: &handlers.AuditEventRequest{},
Response: &dto.Response[models.Event]{},
Options: []okapi.RouteOption{workspaceHeaderRequired},
diff --git a/internal/storage/repositories/event_repo.go b/internal/storage/repositories/event_repo.go
index 4ac4da2..629361b 100644
--- a/internal/storage/repositories/event_repo.go
+++ b/internal/storage/repositories/event_repo.go
@@ -47,7 +47,14 @@ func (r *EventRepository) FindByID(id uint) (*models.Event, error) {
return &event, nil
}
-func (r *EventRepository) FindAll(search string, limit, offset int) ([]models.Event, int64, error) {
+// withoutWorkspaceAudit leaves out the workspace audit trails, which Posta
+// Community records but does not show platform-wide.
+func withoutWorkspaceAudit(q *gorm.DB) *gorm.DB {
+ return q.Where("NOT (category = ? AND workspace_id IS NOT NULL)", models.EventCategoryAudit)
+}
+
+// FindAll lists events; hideWorkspaceAudit leaves out workspace audit trails.
+func (r *EventRepository) FindAll(search string, hideWorkspaceAudit bool, limit, offset int) ([]models.Event, int64, error) {
var events []models.Event
var total int64
@@ -58,6 +65,10 @@ func (r *EventRepository) FindAll(search string, limit, offset int) ([]models.Ev
countQ = countQ.Where("type ILIKE ? OR message ILIKE ? OR actor_name ILIKE ?", like, like, like)
findQ = findQ.Where("type ILIKE ? OR message ILIKE ? OR actor_name ILIKE ?", like, like, like)
}
+ if hideWorkspaceAudit {
+ countQ = withoutWorkspaceAudit(countQ)
+ findQ = withoutWorkspaceAudit(findQ)
+ }
countQ.Count(&total)
@@ -84,7 +95,9 @@ func (r *EventRepository) FindPersonalByActorAndCategory(actorID uint, category
return events, total, nil
}
-func (r *EventRepository) FindByCategory(category models.EventCategory, search string, limit, offset int) ([]models.Event, int64, error) {
+// FindByCategory lists events of a category; hideWorkspaceAudit leaves out
+// workspace audit trails.
+func (r *EventRepository) FindByCategory(category models.EventCategory, search string, hideWorkspaceAudit bool, limit, offset int) ([]models.Event, int64, error) {
var events []models.Event
var total int64
@@ -95,6 +108,10 @@ func (r *EventRepository) FindByCategory(category models.EventCategory, search s
countQ = countQ.Where("type ILIKE ? OR message ILIKE ? OR actor_name ILIKE ?", like, like, like)
findQ = findQ.Where("type ILIKE ? OR message ILIKE ? OR actor_name ILIKE ?", like, like, like)
}
+ if hideWorkspaceAudit {
+ countQ = withoutWorkspaceAudit(countQ)
+ findQ = withoutWorkspaceAudit(findQ)
+ }
countQ.Count(&total)
@@ -122,14 +139,19 @@ func (r *EventRepository) FindByWorkspaceID(workspaceID uint, limit, offset int)
return events, total, nil
}
-// FindByWorkspaceAndCategory returns paginated events for a workspace filtered by category.
-func (r *EventRepository) FindByWorkspaceAndCategory(workspaceID uint, category models.EventCategory, limit, offset int) ([]models.Event, int64, error) {
+// FindByWorkspaceAndCategory returns paginated events for a workspace filtered
+// by category, created at or after since (all of them when since is zero).
+func (r *EventRepository) FindByWorkspaceAndCategory(workspaceID uint, category models.EventCategory, since time.Time, limit, offset int) ([]models.Event, int64, error) {
var events []models.Event
var total int64
- r.db.Model(&models.Event{}).Where("workspace_id = ? AND category = ?", workspaceID, category).Count(&total)
+ q := r.db.Model(&models.Event{}).Where("workspace_id = ? AND category = ?", workspaceID, category)
+ if !since.IsZero() {
+ q = q.Where("created_at >= ?", since)
+ }
+ q.Count(&total)
- if err := r.db.Where("workspace_id = ? AND category = ?", workspaceID, category).
+ if err := q.
Order("created_at DESC").
Limit(limit).Offset(offset).
Find(&events).Error; err != nil {
diff --git a/internal/storage/repositories/plan_repo.go b/internal/storage/repositories/plan_repo.go
index 3483557..295ce93 100644
--- a/internal/storage/repositories/plan_repo.go
+++ b/internal/storage/repositories/plan_repo.go
@@ -32,6 +32,13 @@ func NewPlanRepository(db *gorm.DB) *PlanRepository {
return &PlanRepository{db: db}
}
+// Count counts the configured plans, active or not.
+func (r *PlanRepository) Count() (int64, error) {
+ var n int64
+ err := r.db.Model(&models.Plan{}).Count(&n).Error
+ return n, err
+}
+
func (r *PlanRepository) Create(plan *models.Plan) error {
return r.db.Create(plan).Error
}
diff --git a/web/src/layouts/DashboardLayout.vue b/web/src/layouts/DashboardLayout.vue
index 6fe4636..b0d18a1 100644
--- a/web/src/layouts/DashboardLayout.vue
+++ b/web/src/layouts/DashboardLayout.vue
@@ -305,7 +305,7 @@ const adminNavSections: NavSection[] = [
items: [
{ name: 'Workspaces', path: '/admin/workspaces', icon: 'briefcase' },
{ name: 'Plans', path: '/admin/plans', icon: 'layers' },
- { name: 'Announcements', path: '/admin/announcements', icon: 'bell' },
+ { name: 'Announcements', path: '/admin/announcements', icon: 'bell', enterprise: true },
],
},
{
diff --git a/web/src/views/admin/Announcements.vue b/web/src/views/admin/Announcements.vue
index 8277354..1912b8c 100644
--- a/web/src/views/admin/Announcements.vue
+++ b/web/src/views/admin/Announcements.vue
@@ -5,6 +5,8 @@ import type { Announcement, NotificationSeverity } from "../../api/inbox";
import { useNotificationStore } from "../../stores/notification";
import { useConfirm } from "../../composables/useConfirm";
import { apiMessage } from "../../composables/apiError";
+import EnterpriseLock from "../../components/EnterpriseLock.vue";
+import { useLicenseStore } from "../../stores/license";
const notify = useNotificationStore();
const { confirm } = useConfirm();
@@ -81,7 +83,12 @@ function formatDate(iso?: string | null) {
return iso ? new Date(iso).toLocaleString() : "—";
}
-onMounted(load);
+const license = useLicenseStore();
+
+onMounted(async () => {
+ await license.load();
+ if (license.licensed) await load();
+});
</script>
<template>
@@ -96,7 +103,11 @@ onMounted(load);
</div>
</div>
- <div class="card" style="margin-bottom: 20px">
+ <EnterpriseLock
+ feature="Announcements"
+ description="Put a notice in every user's in-app inbox, such as planned maintenance or a breaking upgrade. Warning and critical notices also appear on the workspace dashboard."
+ >
+ <div v-if="license.mutable" class="card" style="margin-bottom: 20px">
<div class="card-header"><h2>New announcement</h2></div>
<div class="card-body">
<div class="form-group">
@@ -168,6 +179,7 @@ onMounted(load);
</tbody>
</table>
</div>
+ </EnterpriseLock>
</div>
</template>
diff --git a/web/src/views/admin/Plans.vue b/web/src/views/admin/Plans.vue
index 060fb4b..3b00c8c 100644
--- a/web/src/views/admin/Plans.vue
+++ b/web/src/views/admin/Plans.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { ref, onMounted } from 'vue'
+import { computed, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { plansApi } from '../../api/plans'
import type { Plan, PlanInput, Pageable } from '../../api/types'
@@ -8,16 +8,25 @@ import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose'
import { usePagination } from '@/composables/usePagination'
import Pagination from '@/components/Pagination.vue'
+import { useLicenseStore } from '../../stores/license'
+import { ENTERPRISE_URL } from '../../api/license'
const router = useRouter()
const notify = useNotificationStore()
const { confirm } = useConfirm()
+const license = useLicenseStore()
const plans = ref<Plan[]>([])
const loading = ref(true)
const currentPage = ref(0)
+// Posta Community configures three plans; more need Enterprise. A search
+// filters the page total, so the unfiltered count is kept apart.
+const COMMUNITY_PLANS = 3
+const planTotal = ref(0)
+const atCommunityLimit = computed(() => !license.mutable && planTotal.value >= COMMUNITY_PLANS)
+
const showModal = ref(false)
const editing = ref<Plan | null>(null)
const saving = ref(false)
@@ -48,6 +57,7 @@ const { pageable, goToPage } = usePagination(async (page) => {
const res = await plansApi.list(page, pageable.value.size, search.value)
plans.value = res.data.data
pageable.value = res.data.pageable
+ if (!search.value) planTotal.value = res.data.pageable.total_elements
} catch (e) {
console.error('Failed to load plans', e)
} finally {
@@ -61,6 +71,8 @@ function onSearchInput() {
searchTimeout = setTimeout(() => goToPage(0), 300)
}
+onMounted(() => license.load())
+
function openCreate() {
editing.value = null
form.value = defaultForm()
@@ -151,7 +163,24 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
<h1>Plans</h1>
<p class="page-description">Manage usage plans and packages. Plans control rate limits, resource quotas, and retention policies for workspaces.</p>
</div>
- <button class="btn btn-primary" @click="openCreate">Create Plan</button>
+ <button
+ class="btn btn-primary"
+ :disabled="atCommunityLimit"
+ :title="atCommunityLimit ? 'More than three plans need Posta Enterprise' : undefined"
+ @click="openCreate"
+ >
+ Create Plan
+ </button>
+ </div>
+
+ <div v-if="atCommunityLimit" class="app-banner app-banner--info plan-limit" role="status">
+ <div class="app-banner-content">
+ <p class="app-banner-text">
+ Posta Community manages up to three plans. More plans come with <span class="ee-badge">Enterprise</span>.
+ <router-link to="/admin/license">Install a license</router-link> ·
+ <a :href="ENTERPRISE_URL" target="_blank" rel="noopener noreferrer">About Posta Enterprise</a>
+ </p>
+ </div>
</div>
<div class="card">
@@ -330,3 +359,9 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
</div>
</div>
</template>
+
+<style scoped>
+.plan-limit {
+ margin-bottom: 16px;
+}
+</style>
diff --git a/web/src/views/audit/AuditLog.vue b/web/src/views/audit/AuditLog.vue
index 325542a..9f2d5c9 100644
--- a/web/src/views/audit/AuditLog.vue
+++ b/web/src/views/audit/AuditLog.vue
@@ -5,14 +5,23 @@ import { auditApi } from '../../api/audit'
import type { Event } from '../../api/types'
import Pagination from '../../components/Pagination.vue'
import { usePagination } from '@/composables/usePagination'
+import { ENTERPRISE_URL } from '../../api/license'
+import { useAuthStore } from '../../stores/auth'
+import { useLicenseStore } from '../../stores/license'
const router = useRouter()
const events = ref<Event[]>([])
const loading = ref(true)
+const license = useLicenseStore()
+const auth = useAuthStore()
+
+// Posta Community shows the last week; the full history needs Enterprise.
+const COMMUNITY_AUDIT_DAYS = 7
const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
+ await license.load()
const res = await auditApi.list(page, pageable.value.size)
events.value = res.data.data
pageable.value = res.data.pageable
@@ -43,6 +52,19 @@ function openDetail(event: Event) {
<h1>Audit Log</h1>
</div>
+ <div v-if="license.ready && !license.licensed" class="app-banner app-banner--info audit-window" role="status">
+ <div class="app-banner-content">
+ <p class="app-banner-text">
+ Posta Community shows the last {{ COMMUNITY_AUDIT_DAYS }} days of activity. The full history, kept for as
+ long as your retention policy allows, comes with <span class="ee-badge">Enterprise</span>.
+ <router-link v-if="auth.isAdmin" to="/admin/license">Install a license</router-link>
+ <template v-if="auth.isAdmin"> · </template>
+ <a :href="ENTERPRISE_URL" target="_blank" rel="noopener noreferrer">About Posta Enterprise</a>
+ </p>
+ </div>
+ </div>
+
+
<div v-if="loading" class="loading-page">
<div class="spinner"></div>
</div>
@@ -84,6 +106,10 @@ function openDetail(event: Event) {
</template>
<style scoped>
+.audit-window {
+ margin-bottom: 16px;
+}
+
.clickable-row {
cursor: pointer;
}
diff --git a/web/src/views/audit/AuditLogDetail.vue b/web/src/views/audit/AuditLogDetail.vue
index 2b09655..b812620 100644
--- a/web/src/views/audit/AuditLogDetail.vue
+++ b/web/src/views/audit/AuditLogDetail.vue
@@ -4,6 +4,7 @@ import { useRoute, useRouter } from 'vue-router'
import { auditApi } from '../../api/audit'
import type { Event } from '../../api/types'
import { useNotificationStore } from '../../stores/notification'
+import EnterpriseLock from '../../components/EnterpriseLock.vue'
const route = useRoute()
const router = useRouter()
@@ -11,14 +12,17 @@ const notify = useNotificationStore()
const loading = ref(true)
const event = ref<Event | null>(null)
+// Posta Community answers 402 for audit events older than its window.
+const beyondWindow = ref(false)
onMounted(async () => {
try {
const id = Number(route.params.id)
const res = await auditApi.get(id)
event.value = res.data.data
- } catch {
- notify.error('Failed to load audit event')
+ } catch (e) {
+ if ((e as { response?: { status?: number } }).response?.status === 402) beyondWindow.value = true
+ else notify.error('Failed to load audit event')
} finally {
loading.value = false
}
@@ -54,6 +58,12 @@ const prettyMetadata = computed(() => {
<div class="spinner"></div>
</div>
+ <EnterpriseLock
+ v-else-if="beyondWindow"
+ feature="Audit Log history"
+ description="Posta Community shows the last 7 days of workspace activity. This event is older; the full history comes with Posta Enterprise."
+ />
+
<div v-else-if="!event" class="card">
<div class="empty-state">
<h3>Audit event not found</h3>