Repository: zulip/zulip-terminal
Pull request #1165 (2022-03-14 14:53:57)

Added stream_post_policy to the streaminfo view
**What does this PR do?**
This PR contains commit which add the `stream_post_policy` to the streaminfo view. Test case for the same have been added under `tests/ui_tools/test_popups.py`
Partial fix for #1119.

Link to discussion on chat.zulip.org:
[#zulip-terminal>Adding elements to stream info](https://chat.zulip.org/#narrow/stream/206-zulip-terminal/topic/Adding.20elements.20to.20stream.20info.20.28issue.20.23T1119.29)

**Tested?**
- [x] Manually
- [x] Existing tests (adapted, if necessary)
- [x] New tests added (for any new behavior)
- [x] Passed linting & tests (each commit)

**Commit flow**
- Contains code for adding `stream_post_policy` and the updated `test_popup_height` function

**Visual changes**

## Before the commt:
![image](https://user-images.githubusercontent.com/47925568/158197668-413f4bf8-d735-4c6b-8149-97588b0e1a35.png)

## After the commit:
![image](https://user-images.githubusercontent.com/47925568/158197971-866df257-4ced-4881-b125-1c6e4abdde8d.png)




mounilKshah: > I'm unclear if the final part of #1119 is functional on the server at this point (or will be replaced by a new implementation instead), but I suspect this can be extracted into a separate issue once we know what's happening there.

Putting it under a separate issue seems to be a good idea to me. As you had mentioned [here](https://chat.zulip.org/#narrow/stream/206-zulip-terminal/topic/Restrict.20sending.20messages.20to.20streams.20.23T1149.20.23T682/near/1331823), we can have a separate section for the user details in the stream. Apart from the user role, we can also add details like average number of messages sent by user in the stream, number of topics the user has posted on (out of total topics in the stream), etc. 

> As a follow-up to this it might be useful to discuss if we want to group/combine the related stream visibility properties to make it clearer. (we could also add a way to copy a link to the stream for web usage)

This can be a good addition to the stream info!
neiljp: @mounilKshah While I think in principal we could improve these tests, I'll be happy to merge my local slightly adjusted version if we can agree on the text for the `3` policy value, as per my message in the stream.
neiljp: @mounilKshah Thanks for this! Merging now after some minor commit text adjustments 🎉 

Patch:
diff --git a/zulipterminal/config/ui_mappings.py b/zulipterminal/config/ui_mappings.py
index 6d8de48..6d05256 100644
--- a/zulipterminal/config/ui_mappings.py
+++ b/zulipterminal/config/ui_mappings.py
@@ -40,3 +40,10 @@ ROLE_BY_ID: Dict[Optional[int], Dict[str, str]] = {
     400: {"bool": "", "name": "Member"},
     600: {"bool": "is_guest", "name": "Guest"},
 }
+
+STREAM_POST_POLICY = {
+    1: "Any user can post",
+    2: "Only organization administrators can send to this stream",
+    3: "Only organization administrators, moderators and full members can send to this stream",
+    4: "Only organization administrators and moderators can send to this stream",
+}
diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py
index 838000c..1fce22a 100644
--- a/zulipterminal/ui_tools/views.py
+++ b/zulipterminal/ui_tools/views.py
@@ -28,6 +28,7 @@ from zulipterminal.config.ui_mappings import (
     EDIT_MODE_CAPTIONS,
     ROLE_BY_ID,
     STATE_ICON,
+    STREAM_POST_POLICY,
 )
 from zulipterminal.config.ui_sizes import LEFT_WIDTH
 from zulipterminal.helper import (
@@ -1329,6 +1330,14 @@ class StreamInfoView(PopUpView):
             )
         ]
 
+        if "stream_post_policy" in stream:
+            stream_policy = STREAM_POST_POLICY[stream["stream_post_policy"]]
+        else:
+            if stream.get("is_announcement_only"):
+                stream_policy = STREAM_POST_POLICY[2]
+            else:
+                stream_policy = STREAM_POST_POLICY[1]
+
         total_members = len(stream["subscribers"])
         type_of_stream = "Private" if stream["invite_only"] else "Public"
         availability_of_history = (
@@ -1376,6 +1385,7 @@ class StreamInfoView(PopUpView):
                         f"Press {email_keys} to copy Stream email address",
                     ),
                     ("History of Stream", f"{availability_of_history}"),
+                    ("Posting Policy", f"{stream_policy}"),
                 ],
             ),
             ("Stream settings", []),


Test patch:
diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py
index a89d3c8..02c7687 100644
--- a/tests/ui_tools/test_popups.py
+++ b/tests/ui_tools/test_popups.py
@@ -1185,45 +1185,68 @@ class TestStreamInfoView:
         ],
         [
             case(
-                {"date_created": None},
+                {"date_created": None, "is_announcement_only": True},
                 "74 [Organization default]",
                 None,
-                15,
-                id="ZFL=None_no_date_created__no_retention_days",
+                17,
+                id="ZFL=None_no_date_created__no_retention_days__admins_only",
             ),
             case(
-                {"date_created": None},
+                {"date_created": None, "is_announcement_only": False},
                 "74 [Organization default]",
+                None,
+                16,
+                id="ZFL=None_no_date_created__no_retention_days__anyone_can_type",
+            ),
+            case(
+                {"date_created": None, "stream_post_policy": 1},
+                "74 [Organization default]",
+                16,
                 16,
-                15,
                 id="ZFL<30_no_date_created__ZFL<17_no_retention_days",
             ),
             case(
-                {"date_created": None, "message_retention_days": 200},
+                {
+                    "date_created": None,
+                    "message_retention_days": 200,
+                    "stream_post_policy": 2,
+                },
                 "200",
                 17,
-                15,
+                17,
                 id="ZFL<30_no_date_created__ZFL=17_custom_finite_retention_days",
             ),
             case(
-                {"date_created": None, "message_retention_days": None},
+                {
+                    "date_created": None,
+                    "message_retention_days": None,
+                    "stream_post_policy": 3,
+                },
                 "Indefinite [Organization default]",
                 29,
-                15,
+                18,
                 id="ZFL<30_no_date_created__ZFL>17_default_indefinite_retention_days",
             ),
             case(
-                {"date_created": 1472091253, "message_retention_days": 31},
+                {
+                    "date_created": 1472091253,
+                    "message_retention_days": 31,
+                    "stream_post_policy": 4,
+                },
                 "31",
                 30,
-                16,
+                18,
                 id="ZFL=30_with_date_created__ZFL>17_custom_finite_retention_days",
             ),
             case(
-                {"date_created": 1472047124, "message_retention_days": None},
+                {
+                    "date_created": 1472047124,
+                    "message_retention_days": None,
+                    "stream_post_policy": 2,
+                },
                 "72 [Organization default]",
                 40,
-                16,
+                18,
                 id="ZFL>30_with_date_created__ZFL>17_default_finite_retention_days",
             ),
             case(
@@ -1231,10 +1254,11 @@ class TestStreamInfoView:
                     "date_created": 1472046489,
                     "stream_weekly_traffic": None,
                     "message_retention_days": 60,
+                    "stream_post_policy": 1,
                 },
                 "60",
                 50,
-                16,
+                17,
                 id="ZFL>30_new_stream_with_date_created__ZFL>17_finite_retention_days",
             ),
         ],