Skip to content

Commit

Permalink
Merge pull request #771 from karrioapi/insiders-admin
Browse files Browse the repository at this point in the history
[feat] Insiders admin upgrade
  • Loading branch information
danh91 authored Feb 1, 2025
2 parents 461832a + d1f6877 commit 23dbcea
Show file tree
Hide file tree
Showing 81 changed files with 6,267 additions and 3,771 deletions.
6 changes: 1 addition & 5 deletions apps/api/karrio/server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,8 @@
("APPS_MANAGEMENT", bool),
("DOCUMENTS_MANAGEMENT", bool),
("DATA_IMPORT_EXPORT", bool),
("CUSTOM_CARRIER_DEFINITION", bool),
("PERSIST_SDK_TRACING", bool),
("ORDER_DATA_RETENTION", int),
("TRACKER_DATA_RETENTION", int),
("SHIPMENT_DATA_RETENTION", int),
("API_LOGS_DATA_RETENTION", int),
("WORKFLOW_MANAGEMENT", bool),
("WORKFLOW_MANAGEMENT", bool),
]

Expand Down
109 changes: 108 additions & 1 deletion apps/api/karrio/server/settings/constance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
""" Dynamic configuration editable on runtime powered by django-constance."""

from decouple import config
import karrio.server.settings.base as base
from karrio.server.settings.email import (
EMAIL_USE_TLS,
EMAIL_HOST_USER,
Expand All @@ -8,9 +10,11 @@
EMAIL_PORT,
EMAIL_FROM_ADDRESS,
)
import importlib.util

CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_DATABASE_PREFIX = "constance:core:"

DATA_ARCHIVING_SCHEDULE = config("DATA_ARCHIVING_SCHEDULE", default=168, cast=int)

GOOGLE_CLOUD_API_KEY = config("GOOGLE_CLOUD_API_KEY", default="")
Expand All @@ -23,6 +27,107 @@
SHIPMENT_DATA_RETENTION = config("SHIPMENT_DATA_RETENTION", default=183, cast=int)
API_LOGS_DATA_RETENTION = config("API_LOGS_DATA_RETENTION", default=92, cast=int)

# Create feature flags config only for modules that exist
FEATURE_FLAGS_CONFIG = {
"AUDIT_LOGGING": (
(
base.AUDIT_LOGGING,
"Audit logging",
bool,
)
if importlib.util.find_spec("karrio.server.audit") is not None
else None
),
"ALLOW_SIGNUP": (
base.ALLOW_SIGNUP,
"Allow signup",
bool,
),
"ALLOW_ADMIN_APPROVED_SIGNUP": (
base.ALLOW_ADMIN_APPROVED_SIGNUP,
"Allow admin approved signup",
bool,
),
"ALLOW_MULTI_ACCOUNT": (
base.ALLOW_MULTI_ACCOUNT,
"Allow multi account",
bool,
),
"ADMIN_DASHBOARD": (
(
base.ADMIN_DASHBOARD,
"Admin dashboard",
bool,
)
if importlib.util.find_spec("karrio.server.admin") is not None
else None
),
"MULTI_ORGANIZATIONS": (
(
base.MULTI_ORGANIZATIONS,
"Multi organizations",
bool,
)
if importlib.util.find_spec("karrio.server.orgs") is not None
else None
),
"ORDERS_MANAGEMENT": (
(
base.ORDERS_MANAGEMENT,
"Orders management",
bool,
)
if importlib.util.find_spec("karrio.server.orders") is not None
else None
),
"APPS_MANAGEMENT": (
(
base.APPS_MANAGEMENT,
"Apps management",
bool,
)
if importlib.util.find_spec("karrio.server.apps") is not None
else None
),
"DOCUMENTS_MANAGEMENT": (
(
base.DOCUMENTS_MANAGEMENT,
"Documents management",
bool,
)
if importlib.util.find_spec("karrio.server.documents") is not None
else None
),
"DATA_IMPORT_EXPORT": (
(
base.DATA_IMPORT_EXPORT,
"Data import export",
bool,
)
if importlib.util.find_spec("karrio.server.data") is not None
else None
),
"WORKFLOW_MANAGEMENT": (
(
base.WORKFLOW_MANAGEMENT,
"Workflow management",
bool,
)
if importlib.util.find_spec("karrio.server.automation") is not None
else None
),
"PERSIST_SDK_TRACING": (
base.PERSIST_SDK_TRACING,
"Persist SDK tracing",
bool,
),
}

# Update fieldsets to only include existing feature flags
FEATURE_FLAGS_FIELDSET = [k for k, v in FEATURE_FLAGS_CONFIG.items() if v is not None]


# Filter out None values and update CONSTANCE_CONFIG
CONSTANCE_CONFIG = {
"EMAIL_USE_TLS": (
EMAIL_USE_TLS,
Expand Down Expand Up @@ -72,6 +177,7 @@
"API request and SDK tracing logs retention period (in days)",
int,
),
**{k: v for k, v in FEATURE_FLAGS_CONFIG.items() if v is not None},
}

CONSTANCE_CONFIG_FIELDSETS = {
Expand All @@ -87,10 +193,11 @@
"GOOGLE_CLOUD_API_KEY",
"CANADAPOST_ADDRESS_COMPLETE_API_KEY",
),
"Data retention": (
"Data Retention": (
"ORDER_DATA_RETENTION",
"TRACKER_DATA_RETENTION",
"SHIPMENT_DATA_RETENTION",
"API_LOGS_DATA_RETENTION",
),
"Feature Flags": tuple(FEATURE_FLAGS_FIELDSET),
}
9 changes: 8 additions & 1 deletion apps/dashboard/public/carriers/canadapost_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion apps/dashboard/public/carriers/sendle_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/accounts";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/addons";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/carriers";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "@karrio/admin/modules/platform-details";
export { default } from "@karrio/admin/modules/platform";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/staff";

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/accounts";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/addons";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/carriers";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "@karrio/admin/modules/platform-details";
export { default } from "@karrio/admin/modules/platform";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/staff";

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/accounts";
1 change: 1 addition & 0 deletions apps/dashboard/src/app/(ee)/(admin)/admin/addons/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/addons";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/carriers";

This file was deleted.

2 changes: 1 addition & 1 deletion apps/dashboard/src/app/(ee)/(admin)/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "@karrio/admin/modules/platform-details";
export { default } from "@karrio/admin/modules/platform";
1 change: 1 addition & 0 deletions apps/dashboard/src/app/(ee)/(admin)/admin/staff/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/staff";

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/accounts";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/addons";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/carriers";

This file was deleted.

2 changes: 1 addition & 1 deletion apps/dashboard/src/app/(ee)/(admin)/test/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "@karrio/admin/modules/platform-details";
export { default } from "@karrio/admin/modules/platform";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@karrio/admin/modules/staff";

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions ee/packages/console/apis/stripe-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ export async function POST(req: Request) {
switch (event.type) {
case "checkout.session.completed": {
const session = event.data.object;
const organizationId = session.metadata?.organizationId || null;
const orgId = session.metadata?.orgId || null;

if (!organizationId) {
if (!orgId) {
throw new Error("Organization ID is required");
}

// Update the organization with the stripeCustomerId
await prisma.organization.update({
where: { id: organizationId },
where: { id: orgId },
data: {
stripeCustomerId: session.customer as string,
},
});

await prisma.subscription.upsert({
where: { organizationId },
where: { orgId },
create: {
organizationId,
orgId,
stripeSubscriptionId: session.subscription as string,
stripePriceId: session.metadata?.priceId,
status: "active",
Expand Down
14 changes: 6 additions & 8 deletions ee/packages/console/components/payment-method-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { trpc } from "@karrio/console/trpc/client";
import { useState } from "react";

interface PaymentMethodFormProps {
organizationId: string;
orgId: string;
onSuccess: () => void;
clientSecret: string | null;
}

export function PaymentMethodForm({
organizationId,
orgId,
onSuccess,
clientSecret,
}: PaymentMethodFormProps) {
Expand Down Expand Up @@ -40,11 +40,9 @@ export function PaymentMethodForm({

try {
// First, create a setup intent
const { setupIntent: clientSecret } = await createSetupIntent.mutateAsync(
{
organizationId,
},
);
const { setupIntent: clientSecret } = await createSetupIntent.mutateAsync({
orgId,
});

if (!clientSecret) {
throw new Error("Failed to create setup intent");
Expand All @@ -70,7 +68,7 @@ export function PaymentMethodForm({

// Update the organization's payment method
await updatePaymentMethod.mutateAsync({
organizationId,
orgId,
paymentMethodId: setupIntent.payment_method as string,
});

Expand Down
Loading

0 comments on commit 23dbcea

Please sign in to comment.