mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the organization and permissions.
This commit is contained in:
@@ -17,7 +17,6 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
|||||||
const user = await currentUser();
|
const user = await currentUser();
|
||||||
const activeMember = await getActiveMember()
|
const activeMember = await getActiveMember()
|
||||||
|
|
||||||
|
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
@@ -35,12 +34,12 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
|||||||
<PageTitle className="flex items-center">
|
<PageTitle className="flex items-center">
|
||||||
Organization settings
|
Organization settings
|
||||||
{!isMember && organization.slug !== "default" && (
|
{!isMember && organization.slug !== "default" && (
|
||||||
<EditButtonSettings />
|
<EditButtonSettings/>
|
||||||
)}
|
)}
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
<PageActions>
|
<PageActions>
|
||||||
{!isMember && organization.slug !== "default" && (
|
{!isMember && organization.slug !== "default" && (
|
||||||
<DeleteOrganizationButton organizationSlug={organization.slug} />
|
<DeleteOrganizationButton organizationSlug={organization.slug}/>
|
||||||
)}
|
)}
|
||||||
</PageActions>
|
</PageActions>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
@@ -48,7 +47,7 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
|||||||
{/* Manage your organization settings.*/}
|
{/* Manage your organization settings.*/}
|
||||||
{/*</PageDescription>*/}
|
{/*</PageDescription>*/}
|
||||||
<PageContent>
|
<PageContent>
|
||||||
<SettingsOrganizationMembersTable organization={organization} />
|
<SettingsOrganizationMembersTable organization={organization}/>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -22,8 +22,8 @@ export const DeleteOrganizationButton = (props: DeleteOrganizationButtonProps) =
|
|||||||
organizationSlug: "default",
|
organizationSlug: "default",
|
||||||
});
|
});
|
||||||
router.push("/");
|
router.push("/");
|
||||||
|
|
||||||
toast.success(result.data.actionSuccess?.message || "Organization deleted.");
|
toast.success(result.data.actionSuccess?.message || "Organization deleted.");
|
||||||
|
router.refresh()
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const errorMsg = result?.data?.actionError?.message || result?.data?.actionError?.messageParams?.message || "Failed to delete the organization.";
|
const errorMsg = result?.data?.actionError?.message || result?.data?.actionError?.messageParams?.message || "Failed to delete the organization.";
|
||||||
|
|||||||
@@ -222,7 +222,13 @@ export const deleteOrganizationAction = userAction.schema(z.string()).action(
|
|||||||
let deletedOrganization: Organization;
|
let deletedOrganization: Organization;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
deletedOrganization = await deleteOrganization(org.id) as Organization;
|
// TODO : Improve with better auth, always getting 403 error
|
||||||
|
// deletedOrganization = await deleteOrganization(org.id) as Organization;
|
||||||
|
[deletedOrganization] = await db
|
||||||
|
.delete(drizzleDb.schemas.organization)
|
||||||
|
.where(eq(drizzleDb.schemas.organization.id, org.id))
|
||||||
|
.returning();
|
||||||
|
|
||||||
} catch (authError: any) {
|
} catch (authError: any) {
|
||||||
console.error("Auth deletion failed:", authError);
|
console.error("Auth deletion failed:", authError);
|
||||||
return {
|
return {
|
||||||
|
|||||||
+17
-9
@@ -5,24 +5,32 @@ import { v4 as uuidv4 } from "uuid";
|
|||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
|
import {authClient} from "@/lib/auth/auth-client";
|
||||||
|
import {auth} from "@/lib/auth/auth";
|
||||||
|
|
||||||
|
|
||||||
export const deleteUserAction = userAction.schema(z.string()).action(async ({ parsedInput, ctx }) => {
|
export const deleteUserAction = userAction.schema(z.string()).action(async ({ parsedInput, ctx }) => {
|
||||||
const userId = parsedInput.length > 0 ? parsedInput : ctx.user.id;
|
const userId = parsedInput.length > 0 ? parsedInput : ctx.user.id;
|
||||||
const uuid = uuidv4();
|
const uuid = uuidv4();
|
||||||
|
|
||||||
const [updatedUser] = await db
|
|
||||||
.update(drizzleDb.schemas.user)
|
// const [updatedUser] = await db
|
||||||
.set({
|
// .update(drizzleDb.schemas.user)
|
||||||
email: `${uuid}@portabase.com`,
|
// .set({
|
||||||
name: `${uuid}`,
|
// email: `${uuid}@portabase.com`,
|
||||||
//deleted: true,
|
// name: `${uuid}`,
|
||||||
//todo: add deleted
|
// //deleted: true,
|
||||||
})
|
// //todo: add deleted
|
||||||
|
// })
|
||||||
|
// .where(eq(drizzleDb.schemas.user.id, userId))
|
||||||
|
// .returning();
|
||||||
|
const [deletedUser] = await db
|
||||||
|
.delete(drizzleDb.schemas.user)
|
||||||
.where(eq(drizzleDb.schemas.user.id, userId))
|
.where(eq(drizzleDb.schemas.user.id, userId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: updatedUser,
|
data: deletedUser,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ const superadmin = ac.newRole({
|
|||||||
...adminAc.statements,
|
...adminAc.statements,
|
||||||
...orgAdminAc.statements,
|
...orgAdminAc.statements,
|
||||||
...orgOwnerAc.statements,
|
...orgOwnerAc.statements,
|
||||||
...orgMemberAc.statements
|
...orgMemberAc.statements,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const admin = ac.newRole({
|
const admin = ac.newRole({
|
||||||
|
|||||||
Reference in New Issue
Block a user