Repository navigation
feat(teams): one access decision for routed calls from teammates, off by default #868
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
Open
bvsr365
wants to merge
4
commits into
master
Choose a base branch
from
teams-access-decision
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fad5eb5
feat(teams): one access decision for calls from another person
bvsr365 dab1254
feat(net): a netTeams flag, off by default and stored only while on
bvsr365 b757ec4
feat(bridge): only rows marked crossUser are open to teammates, behin…
bvsr365 ad151c8
feat(threads): a per-person thread filter for teammates
bvsr365 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * The one access decision for a routed call from another person (`docs/plans/teams-architecture.md` §6.5.3). | ||
| * Pure: the caller hands in the flag, the row, the target thread and the team directory. | ||
| */ | ||
| import type { NodeId, UserId } from '../../shared/net/ids' | ||
| import type { | ||
| TeamAccessDecision, | ||
| TeamDirectory, | ||
| TeamId, | ||
| ThreadAccess | ||
| } from '../../shared/teams/types' | ||
|
|
||
| /** Knows no team, so it refuses every other person. The default until a team's Space provides one. */ | ||
| export const DENY_ALL_TEAM_DIRECTORY: TeamDirectory = Object.freeze({ | ||
| teamOf: () => undefined, | ||
| isActiveMember: () => false, | ||
| threadAccess: () => undefined | ||
| }) | ||
|
|
||
| /** The thread a call acts on, as this computer knows it. */ | ||
| export interface TeamAccessTarget { | ||
| threadId: string | ||
| /** Kept on this computer only (`Thread.localOnly`, including by lineage). */ | ||
| localOnly: boolean | ||
| } | ||
|
|
||
| export interface TeamAccessInput { | ||
| peer: { user: UserId; node: NodeId } | ||
| self: { user: UserId; node: NodeId } | ||
| /** The routed row the call names; undefined for any other Net method. */ | ||
| row: { crossUser?: true } | undefined | ||
| /** Undefined when the call names no thread (or it is not known here). */ | ||
| target: TeamAccessTarget | undefined | ||
| flags: { netTeams?: boolean } | ||
| directory: TeamDirectory | ||
| } | ||
|
|
||
| const deny = (reason: Extract<TeamAccessDecision, { kind: 'deny' }>['reason']): TeamAccessDecision => ({ | ||
| kind: 'deny', | ||
| reason | ||
| }) | ||
|
|
||
| /** Whether `access` lets `user` reach the thread: its owner, a listed person, or any member when it is open to the team. */ | ||
| export function threadAccessAllows(access: ThreadAccess | undefined, user: UserId): boolean { | ||
| return ( | ||
| !!access && (access.owner === user || access.people.includes(user) || access.openToTeam === true) | ||
| ) | ||
| } | ||
|
|
||
| /** Whether `user`, a member of `team`, may see the thread. A thread kept on this computer only never is. */ | ||
| export function personMaySeeThread( | ||
| directory: TeamDirectory, | ||
| team: TeamId | undefined, | ||
| user: UserId, | ||
| thread: { id: string; localOnly: boolean } | ||
| ): boolean { | ||
| return ( | ||
| !thread.localOnly && | ||
| team !== undefined && | ||
| directory.isActiveMember(team, user) && | ||
| threadAccessAllows(directory.threadAccess(thread.id), user) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Same person: today's checks, unchanged. Anyone else is refused unless every step passes, in this order: | ||
| * the flag is on, the row is marked `crossUser`, the thread is not kept on this computer only, the person is | ||
| * an active member of this computer's team, and the thread is open to them. | ||
| */ | ||
| export function teamAccess({ | ||
| peer, | ||
| self, | ||
| row, | ||
| target, | ||
| flags, | ||
| directory | ||
| }: TeamAccessInput): TeamAccessDecision { | ||
| if (peer.user === self.user) return { kind: 'same_person' } | ||
| if (flags.netTeams !== true) return deny('teams_off') | ||
| if (row?.crossUser !== true) return deny('row_not_cross_user') | ||
| if (!target) return deny('no_thread_access') | ||
| if (target.localOnly) return deny('local_only') | ||
| const team = directory.teamOf(self.node) | ||
| if (team === undefined || !directory.isActiveMember(team, peer.user)) return deny('not_team_member') | ||
| return threadAccessAllows(directory.threadAccess(target.threadId), peer.user) | ||
| ? { kind: 'allow' } | ||
| : deny('no_thread_access') | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R1. Keep a child hidden when its lineage root is unknown.
Older child records can lack their own
localOnlyflag. The new filter defaultsinventoryto the supplied rows, so if the root is missing from that inventory,isLocalOnlyThread()returns false. An otherwise eligible child can then appear despite the filter’s local-only guarantee. Require full inventory at this boundary and treat unresolved root IDs as unshareable. Add a visibility test where the existingkeptChildfixture is passed without its root.