Skip to content

Commit 0104dd2

Browse files
committed
helper.py: Add method unauthorised_warning to update footer
This method acts as an sanitary check when a normal user is sending message to a stream where only organization admins are allowed to send. The method also updates the footer with appropriate warning.
1 parent 114ec0d commit 0104dd2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

zulipterminal/helper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,43 @@ def match_topics(topic_names: List[str], search_text: str) -> List[str]:
519519
DataT = TypeVar('DataT')
520520

521521

522+
def unauthorised_warning(model: Any, stream_identifier: Any):
523+
"""
524+
Identify target stream based on stream id or stream name
525+
and update footer based on the user rights.
526+
"""
527+
stream_id = None
528+
if isinstance(stream_identifier, int):
529+
stream_id = stream_identifier
530+
elif isinstance(stream_identifier, str):
531+
for s_id, stream in model.stream_dict.items():
532+
if stream['name'] == stream_identifier:
533+
stream_id = s_id
534+
break
535+
536+
if not stream_id:
537+
msg_footer = (
538+
model.controller.view.set_footer_text(
539+
"Specified stream does not exist.",
540+
5))
541+
return True
542+
else:
543+
if (model.stream_dict[stream_id].
544+
get('is_announcement_only', None) == 1
545+
or (model.initial_data.get('is_admin', None)
546+
or model.initial_data.get('is_owner', None)
547+
and model.stream_dict[stream_id].
548+
get('stream_post_policy', None) == 2)):
549+
msg_footer = (
550+
model.controller.view.set_footer_text(
551+
"You are not authorised to send messages "
552+
"to this stream.",
553+
5))
554+
return True
555+
else:
556+
return False
557+
558+
522559
def match_stream(data: List[Tuple[DataT, str]], search_text: str,
523560
pinned_streams: List[StreamData]
524561
) -> Tuple[List[DataT], List[str]]:

0 commit comments

Comments
 (0)