-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Effect: Port UpdateFolder
#1142
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
20 commits
Select commit
Hold shift + click to select a range
8b22e76
wip
oscartbeaumont 889d4df
wip
oscartbeaumont ff8026c
more wip
oscartbeaumont bb4b418
wip
oscartbeaumont d87ff5d
fix error
oscartbeaumont bdeb269
cleanup `"use server"`'s
oscartbeaumont d7a6485
add policy for parent folder
oscartbeaumont 4793982
improve logic
oscartbeaumont ba5bf6b
do it goodly
oscartbeaumont 40a756f
drop em
oscartbeaumont 5d0f267
cleanup
oscartbeaumont 249bc4f
introduce more branded types
oscartbeaumont 012c3be
drop it
oscartbeaumont 5b08df3
Merge branch 'main' into effect-upload-folder
oscartbeaumont e842cba
format
oscartbeaumont e085078
use repo in most places
Brendonovich aaa4083
remove organisation re-export
Brendonovich e7c2631
cleanup + fix some policy problems
Brendonovich b4402d6
fix folderspolicy too
Brendonovich 0150d81
formatting
Brendonovich 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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| "use server"; | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| export default async function EmbedPage() { | ||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| "use server"; | ||
|
|
||
| import { redirect } from "next/navigation"; | ||
|
|
||
| export default async function SharePage() { | ||
|
|
||
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 |
|---|---|---|
| @@ -1,47 +1,52 @@ | ||
| import * as Db from "@cap/database/schema"; | ||
| import { type Folder, Policy } from "@cap/web-domain"; | ||
| import * as Dz from "drizzle-orm"; | ||
| import { Effect } from "effect"; | ||
|
|
||
| import { Database } from "../Database.ts"; | ||
| import { OrganisationsPolicy } from "../Organisations/OrganisationsPolicy.ts"; | ||
| import { Spaces } from "../Spaces/index.ts"; | ||
| import { SpacesPolicy } from "../Spaces/SpacesPolicy.ts"; | ||
| import { FoldersRepo } from "./FoldersRepo.ts"; | ||
|
|
||
| export class FoldersPolicy extends Effect.Service<FoldersPolicy>()( | ||
| "FoldersPolicy", | ||
| { | ||
| effect: Effect.gen(function* () { | ||
| const db = yield* Database; | ||
| const repo = yield* FoldersRepo; | ||
| const spacesPolicy = yield* SpacesPolicy; | ||
| const orgsPolicy = yield* OrganisationsPolicy; | ||
| const spaces = yield* Spaces; | ||
|
|
||
| const canEdit = (id: Folder.FolderId) => | ||
| Policy.policy((user) => | ||
| Effect.gen(function* () { | ||
| const [folder] = yield* db.execute((db) => | ||
| db.select().from(Db.folders).where(Dz.eq(Db.folders.id, id)), | ||
| const folder = yield* (yield* repo.getById(id)).pipe( | ||
| Effect.catchTag( | ||
| "NoSuchElementException", | ||
| () => new Policy.PolicyDeniedError(), | ||
| ), | ||
| ); | ||
oscartbeaumont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // All space members can edit space properties | ||
| if (!folder?.spaceId) { | ||
| return folder?.createdById === user.id; | ||
| } | ||
|
|
||
| const { spaceId } = folder; | ||
| const [spaceMember] = yield* db.execute((db) => | ||
| db | ||
| .select() | ||
| .from(Db.spaceMembers) | ||
| .where( | ||
| Dz.and( | ||
| Dz.eq(Db.spaceMembers.userId, user.id), | ||
| Dz.eq(Db.spaceMembers.spaceId, spaceId), | ||
| ), | ||
| ), | ||
| ); | ||
| if (folder.spaceId === null) return folder.createdById === user.id; | ||
|
|
||
| const spaceOrOrg = yield* spaces.getSpaceOrOrg(folder.spaceId); | ||
| if (!spaceOrOrg) return false; | ||
|
|
||
| if (spaceOrOrg.variant === "space") | ||
| yield* spacesPolicy.isMember(spaceOrOrg.space.id); | ||
| else yield* orgsPolicy.isOwner(spaceOrOrg.organization.id); | ||
|
|
||
| return spaceMember !== undefined; | ||
| return true; | ||
| }), | ||
| ); | ||
|
|
||
| return { canEdit }; | ||
| }), | ||
| dependencies: [Database.Default], | ||
| dependencies: [ | ||
| FoldersRepo.Default, | ||
| Database.Default, | ||
| Spaces.Default, | ||
| SpacesPolicy.Default, | ||
| OrganisationsPolicy.Default, | ||
| ], | ||
| }, | ||
| ) {} | ||
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.