-
Notifications
You must be signed in to change notification settings - Fork 806
Populate orgId
col on videos
table
#1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ab9e072
wip
oscartbeaumont c501a42
wip
oscartbeaumont 52729f4
wip
oscartbeaumont f0b5c6c
Merge branch 'main' into populate-orgId
oscartbeaumont 797fca5
configure default org id
oscartbeaumont 696a6cd
fixes
oscartbeaumont 46b0ff2
fix
oscartbeaumont 29325e2
fix
oscartbeaumont 8e435a1
fix
oscartbeaumont ecb8f49
permission checks on `orgId` assignment for video upload
oscartbeaumont 0a0372c
cleanup
oscartbeaumont 6204ec4
backfill script
oscartbeaumont 890c794
improve backfill script
oscartbeaumont 17a36e4
filter cluser tables + improve backfill script
oscartbeaumont fecf7de
format
oscartbeaumont fc0114e
fix backfill script
oscartbeaumont 2139d55
auth when updating `defaultOrgId`'s
oscartbeaumont 355f3b5
don't navigate with changes
oscartbeaumont 58ca316
format
oscartbeaumont 1ae12d2
fix
oscartbeaumont ffd86c7
fix
oscartbeaumont 61713b8
fix
oscartbeaumont 0d8587b
assign default properly
oscartbeaumont a6ff99c
nahhhh
oscartbeaumont 08caacb
Merge branch 'main' into populate-orgId
oscartbeaumont 88bf9df
fix types
oscartbeaumont 932cd33
fix
oscartbeaumont f910ca7
fix
oscartbeaumont 057da33
update select component
ameer2468 8aa84dd
Merge branch 'main' into populate-orgId
ameer2468 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use server"; | ||
|
||
import { db } from "@cap/database"; | ||
import { getCurrentUser } from "@cap/database/auth/session"; | ||
import { | ||
organizationMembers, | ||
organizations, | ||
users, | ||
} from "@cap/database/schema"; | ||
import { eq, or } from "drizzle-orm"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function patchAccountSettings( | ||
firstName?: string, | ||
lastName?: string, | ||
defaultOrgId?: string, | ||
) { | ||
const currentUser = await getCurrentUser(); | ||
if (!currentUser) throw new Error("Unauthorized"); | ||
|
||
const updatePayload: Partial<{ | ||
name: string; | ||
lastName: string; | ||
defaultOrgId: string; | ||
}> = {}; | ||
|
||
if (firstName !== undefined) updatePayload.name = firstName; | ||
if (lastName !== undefined) updatePayload.lastName = lastName; | ||
if (defaultOrgId !== undefined) { | ||
const userOrganizations = await db() | ||
.select({ | ||
id: organizations.id, | ||
}) | ||
.from(organizations) | ||
.leftJoin( | ||
organizationMembers, | ||
eq(organizations.id, organizationMembers.organizationId), | ||
) | ||
.where( | ||
or( | ||
// User owns the organization | ||
eq(organizations.ownerId, currentUser.id), | ||
// User is a member of the organization | ||
eq(organizationMembers.userId, currentUser.id), | ||
), | ||
) | ||
// Remove duplicates if user is both owner and member | ||
.groupBy(organizations.id); | ||
|
||
const userOrgIds = userOrganizations.map((org) => org.id); | ||
|
||
if (!userOrgIds.includes(defaultOrgId)) | ||
throw new Error( | ||
"Forbidden: User does not have access to the specified organization", | ||
); | ||
oscartbeaumont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
updatePayload.defaultOrgId = defaultOrgId; | ||
} | ||
|
||
await db() | ||
.update(users) | ||
.set(updatePayload) | ||
.where(eq(users.id, currentUser.id)); | ||
|
||
revalidatePath("/dashboard/settings/account"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.