-
Notifications
You must be signed in to change notification settings - Fork 160
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
compose_box: Replace compose box with a banner when cannot post in a channel #886
Open
sm-sayedi
wants to merge
8
commits into
zulip:main
Choose a base branch
from
sm-sayedi:issue-674-hide-compose-box-according-channel-posting-policy
base: main
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.
+338
−95
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ffb3238
api: Add `realmWaitingPeriodThreshold` to `InitialSnapshot`
sm-sayedi 9616005
store: Add `realmWaitingPeriodThreshold` to `PerAccountStore`
sm-sayedi 6cf3dd9
model: Add `hasPassedWaitingPeriod` helper method to `User`
sm-sayedi d1c16a9
model: Add `hasPostingPermission` helper method to `ZulipStream`
sm-sayedi 5aaad2d
test [nfc]: Have `eg.user` accept `dateJoined` and `role`
sm-sayedi dc9a330
compose_box test [nfc]: Have `prepareComposeBox` accept additional pa…
sm-sayedi 58276c3
test [nfc]: Add `stream`s and `eg.selfUser` to `store` in several tests
sm-sayedi be0d74d
compose_box: Replace compose box with a banner when cannot post in a …
sm-sayedi 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 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 |
---|---|---|
|
@@ -315,6 +315,11 @@ enum UserRole{ | |
final int? apiValue; | ||
|
||
int? toJson() => apiValue; | ||
|
||
bool isAtLeast(UserRole threshold) { | ||
// Roles with more privilege have lower [apiValue]. | ||
return (apiValue ?? 0) <= (threshold.apiValue ?? 0); | ||
} | ||
} | ||
|
||
/// As in `streams` in the initial snapshot. | ||
|
@@ -382,6 +387,19 @@ class ZulipStream { | |
_$ZulipStreamFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ZulipStreamToJson(this); | ||
|
||
bool hasPostingPermission(User user, {required DateTime byDate, required int realmWaitingPeriodThreshold}) { | ||
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. nit: let's break this into multiple lines |
||
final role = user.role; | ||
return switch (channelPostPolicy) { | ||
ChannelPostPolicy.any => true, | ||
ChannelPostPolicy.fullMembers => role.isAtLeast(UserRole.member) && (role == UserRole.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. nit: by turning this into |
||
? user.hasPassedWaitingPeriod(byDate, realmWaitingPeriodThreshold) | ||
: true), | ||
ChannelPostPolicy.moderators => role.isAtLeast(UserRole.moderator), | ||
ChannelPostPolicy.administrators => role.isAtLeast(UserRole.administrator), | ||
ChannelPostPolicy.unknown => true, | ||
}; | ||
} | ||
} | ||
|
||
/// The name of a property of [ZulipStream] that gets updated | ||
|
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.
Looking at this, I was thinking about why
0
is chosen as the default value for both operands. Considering the context this helper is used, I suppose that we want to fallback to the behavior that, when the role has an unknown value, we allow the user to post.This consideration is specific to the posting permission feature we are implementing here. I think the best thing to do is to assert that both api values are non-null; then we handle the case when either of them is null in
hasPostingPermission
.