Skip to content

Commit e12f16d

Browse files
authored
feat: Add support for private posts to instructors (#77)
1 parent 4a8177a commit e12f16d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

piazza_api/network.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def iter_all_posts(self, limit=None, sleep=0):
111111
time.sleep(sleep)
112112
yield self.get_post(cid)
113113

114-
def create_post(self, post_type, post_folders, post_subject, post_content, is_announcement=0, bypass_email=0, anonymous=False):
114+
def create_post(self, post_type, post_folders, post_subject, post_content, is_announcement=0, bypass_email=0, anonymous=False, is_private=False):
115115
"""Create a post
116116
117117
It seems like if the post has `<p>` tags, then it's treated as HTML,
@@ -132,6 +132,8 @@ def create_post(self, post_type, post_folders, post_subject, post_content, is_an
132132
:param bypass_email:
133133
:type anonymous: bool
134134
:param anonymous:
135+
:type is_private: bool
136+
:param is_private: If True, post will be private to instructors only.
135137
:rtype: dict
136138
:returns: Dictionary with information about the created post.
137139
"""
@@ -147,6 +149,12 @@ def create_post(self, post_type, post_folders, post_subject, post_content, is_an
147149
}
148150
}
149151

152+
if is_private:
153+
user_profile = self._rpc.get_user_profile() or {}
154+
user_id = user_profile.get('user_id')
155+
if user_id:
156+
params["config"]["feed_groups"] = f"instr_{self._nid},{user_id}"
157+
150158
if bypass_email:
151159
params["prof_override"] = True
152160

0 commit comments

Comments
 (0)