-
-
Notifications
You must be signed in to change notification settings - Fork 672
permission selectors: Add, with getCanCreateWebPublicStreams #5384
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
9 commits
Select commit
Hold shift + click to select a range
759e00d
example data [nfc]: Group properties in action.register_complete expl…
chrisbobbe ce0e327
example data: Sync action.register_complete with what recent servers do
chrisbobbe a8a174f
realm reducer: Start live-updating enableSpectatorAccess from event
chrisbobbe d2453ea
flow [nfc]: Move objectEntries to a more general flowPonyfill module
gnprice bfa1246
flow: Add objectValues as type-ponyfill for Object.values
gnprice 51ace1c
api types: Be more precise about UserOrBot.role type
chrisbobbe 5c1938f
realm reducer tests [nfc]: Remove unused conditional
chrisbobbe 55d1e43
api types: Be more precise about realm_create_web_public_stream_policy
chrisbobbe 41e50a7
permission selectors: Add, with getCanCreateWebPublicStreams
chrisbobbe 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* @flow strict-local */ | ||
| import invariant from 'invariant'; | ||
|
|
||
| import { tryGetActiveAccountState } from '../selectors'; | ||
| import { | ||
| Role, | ||
| type RoleT, | ||
| CreateWebPublicStreamPolicy, | ||
| type CreateWebPublicStreamPolicyT, | ||
| } from '../api/permissionsTypes'; | ||
| import { getCanCreateWebPublicStreams } from '../permissionSelectors'; | ||
| import rootReducer from '../boot/reducers'; | ||
| import { EVENT_USER_UPDATE } from '../actionConstants'; | ||
| import * as eg from './lib/exampleData'; | ||
|
|
||
| describe('getCanCreateWebPublicStreams', () => { | ||
| const { AdminOrAbove, ModeratorOrAbove, Nobody, OwnerOnly } = CreateWebPublicStreamPolicy; | ||
| const { Owner, Admin, Moderator, Member, Guest } = Role; | ||
|
|
||
| test('returns false when webPublicStreamsEnabled is false', () => { | ||
| const globalState = [ | ||
| { | ||
| type: EVENT_USER_UPDATE, | ||
| id: 0, | ||
| userId: eg.selfUser.user_id, | ||
| person: { user_id: eg.selfUser.user_id, role: Owner }, | ||
| }, | ||
| ].reduce( | ||
| rootReducer, | ||
| eg.reduxStatePlus({ | ||
| realm: { | ||
| ...eg.plusReduxState.realm, | ||
| webPublicStreamsEnabled: false, | ||
| enableSpectatorAccess: true, | ||
| createWebPublicStreamPolicy: ModeratorOrAbove, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const state = tryGetActiveAccountState(globalState); | ||
| invariant(state, 'expected per-account state'); | ||
|
|
||
| expect(getCanCreateWebPublicStreams(state)).toBeFalse(); | ||
| }); | ||
|
|
||
| test('returns false when enableSpectatorAccess is false', () => { | ||
| const globalState = [ | ||
| { | ||
| type: EVENT_USER_UPDATE, | ||
| id: 0, | ||
| userId: eg.selfUser.user_id, | ||
| person: { user_id: eg.selfUser.user_id, role: Owner }, | ||
| }, | ||
| ].reduce( | ||
| rootReducer, | ||
| eg.reduxStatePlus({ | ||
| realm: { | ||
| ...eg.plusReduxState.realm, | ||
| webPublicStreamsEnabled: true, | ||
| enableSpectatorAccess: false, | ||
| createWebPublicStreamPolicy: ModeratorOrAbove, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const state = tryGetActiveAccountState(globalState); | ||
| invariant(state, 'expected per-account state'); | ||
|
|
||
| expect(getCanCreateWebPublicStreams(state)).toBeFalse(); | ||
| }); | ||
|
|
||
| test.each` | ||
| policy | role | expected | ||
| ${AdminOrAbove} | ${Owner} | ${true} | ||
| ${AdminOrAbove} | ${Admin} | ${true} | ||
| ${AdminOrAbove} | ${Moderator} | ${false} | ||
| ${AdminOrAbove} | ${Member} | ${false} | ||
| ${AdminOrAbove} | ${Guest} | ${false} | ||
| ${ModeratorOrAbove} | ${Owner} | ${true} | ||
| ${ModeratorOrAbove} | ${Admin} | ${true} | ||
|
Comment on lines
+72
to
+80
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat! |
||
| ${ModeratorOrAbove} | ${Moderator} | ${true} | ||
| ${ModeratorOrAbove} | ${Member} | ${false} | ||
| ${ModeratorOrAbove} | ${Guest} | ${false} | ||
| ${Nobody} | ${Owner} | ${false} | ||
| ${Nobody} | ${Admin} | ${false} | ||
| ${Nobody} | ${Moderator} | ${false} | ||
| ${Nobody} | ${Member} | ${false} | ||
| ${Nobody} | ${Guest} | ${false} | ||
| ${OwnerOnly} | ${Owner} | ${true} | ||
| ${OwnerOnly} | ${Admin} | ${false} | ||
| ${OwnerOnly} | ${Moderator} | ${false} | ||
| ${OwnerOnly} | ${Member} | ${false} | ||
| ${OwnerOnly} | ${Guest} | ${false} | ||
| `( | ||
| 'returns $expected when policy is $policy and role is $role', | ||
| async ({ | ||
| policy, | ||
| role, | ||
| expected, | ||
| }: { | ||
| policy: CreateWebPublicStreamPolicyT, | ||
| role: RoleT, | ||
| expected: boolean, | ||
| }) => { | ||
| const globalState = [ | ||
| { | ||
| type: EVENT_USER_UPDATE, | ||
| id: 0, | ||
| userId: eg.selfUser.user_id, | ||
| person: { user_id: eg.selfUser.user_id, role }, | ||
| }, | ||
| ].reduce( | ||
| rootReducer, | ||
| eg.reduxStatePlus({ | ||
| realm: { | ||
| ...eg.plusReduxState.realm, | ||
| webPublicStreamsEnabled: true, | ||
| enableSpectatorAccess: true, | ||
| createWebPublicStreamPolicy: policy, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const state = tryGetActiveAccountState(globalState); | ||
| invariant(state, 'expected per-account state'); | ||
|
|
||
| expect(getCanCreateWebPublicStreams(state)).toBe(expected); | ||
| }, | ||
| ); | ||
| }); | ||
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.
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.
I think it might be nice to use a completely empty initial state here, then apply changes like
createWebPublicStreamPolicyin a minimally modifiedeg.action.register_complete. The problem is thateg.reduxStatePlusgives us boring things that we need, like puttingselfUserinstate.users, that we don't get fromeg.action.register_complete.What do we think about a TODO to change
eg.action.register_complete's interface such that it would make a blank state look more likeeg.plusReduxState? We could even constructeg.plusReduxStateusing this modifiedeg.action.register_complete.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.
Yeah, that sounds like a good direction.
I'm not sure if we have a use case that needs a "minimal" version of the action, which is what that's currently documented as. Would have to look at the use sites of it to see. If we do, we could potentially have both -- first the minimal, then also one that's defined by starting from that and adding things we need to add.