-
Notifications
You must be signed in to change notification settings - Fork 22
feat(ui): Restrict shot upload according to title id and community #403
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 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dcab27f
chore(ui): unify canPost logic
ashquarky 3a89aa9
feat(ui): restrict shot to parent community
ashquarky b764001
feat(api): restrict shot to parent community
ashquarky ea5e6f9
feat(ui): implement allow/block/force system for shots, extra title ids
ashquarky 51d6256
Merge branch 'dev' into work/upload-controls
ashquarky b582cc0
fix(ui): Communities DB schema typescript
ashquarky 17fad5f
chore(db): Deprecate title_ids
ashquarky 1f89584
fix(all): use Mongoose enum for communities.shot_mode
ashquarky 4ff77c7
fix(admin): strip NaN and Inf from title id controls
ashquarky 03f9c81
fix(ui): factor out comma-seperated list zod schema
ashquarky ddd520b
Merge branch 'dev' into work/upload-controls
ashquarky 1f5b918
chore(admin): Use CommunityShotModes for zod schemas
ashquarky 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
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
55 changes: 55 additions & 0 deletions
55
apps/juxtaposition-ui/src/services/juxt-web/routes/permissions.ts
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,55 @@ | ||
| import type { InferSchemaType } from 'mongoose'; | ||
| import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc'; | ||
| import type { CommunitySchema } from '@/models/communities'; | ||
| import type { PostSchema } from '@/models/post'; | ||
| import type { HydratedSettingsDocument } from '@/models/settings'; | ||
| import type { PostDto } from '@/api/post'; | ||
| import type { ParamPack } from '@/types/common/param-pack'; | ||
|
|
||
| export function isPostingAllowed(community: InferSchemaType<typeof CommunitySchema>, userSettings: HydratedSettingsDocument, parentPost: InferSchemaType<typeof PostSchema> | PostDto | null, user: GetUserDataResponse): boolean { | ||
| const isReply = !!parentPost; | ||
| const isPublicPostableCommunity = community.type >= 0 && community.type < 2; | ||
| const isOpenCommunity = community.permissions.open; | ||
|
|
||
| const isCommunityAdmin = (community.admins ?? []).includes(user.pid); | ||
| const isUserLimitedFromPosting = userSettings.account_status !== 0; | ||
| const hasAccessLevelRequirement = isReply | ||
| ? user.accessLevel >= community.permissions.minimum_new_comment_access_level | ||
| : user.accessLevel >= community.permissions.minimum_new_post_access_level; | ||
|
|
||
| if (isUserLimitedFromPosting) { | ||
| return false; | ||
| } | ||
|
|
||
| if (isCommunityAdmin) { | ||
| return true; // admins can always post (if not limited) | ||
| } | ||
|
|
||
| if (!hasAccessLevelRequirement) { | ||
| return false; | ||
| } | ||
|
|
||
| return isReply ? isOpenCommunity : isPublicPostableCommunity; | ||
| } | ||
|
|
||
| export type ShotMode = 'allow' | 'block' | 'force'; | ||
| const shotModes = ['allow', 'block', 'force']; | ||
|
|
||
| export function getShotMode(community: InferSchemaType<typeof CommunitySchema>, pack: ParamPack | null): ShotMode { | ||
| if (pack === null) { | ||
| return 'block'; | ||
| } | ||
|
|
||
| // Shots only on matching communities | ||
| if (!community.title_id.includes(pack.title_id) && | ||
| !community.shot_extra_title_id?.includes(pack.title_id)) { | ||
| return 'block'; | ||
| } | ||
|
|
||
| // Check for bad community schema | ||
| if (!shotModes.includes(community.shot_mode ?? '')) { | ||
| return 'allow'; // default | ||
| } | ||
|
|
||
| return community.shot_mode as ShotMode; // type check above | ||
| } | ||
|
mrjvs marked this conversation as resolved.
Outdated
|
||
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
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.