feat: Option to invite teaching team when creating MM channels (#17)

Also add config for mattermost_teaching_team
This commit is contained in:
Frederick 2022-09-21 00:17:27 +08:00 committed by GitHub
parent 95b2edd804
commit 6c0df81ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -140,7 +140,11 @@ def upload_assignment_grades(assignments_dir: Path, assignment_name: str) -> Non
help="create channels for student groups according to group information on"
" gitea",
)
def create_channels_on_mm(prefix: str = Option(""), suffix: str = Option("")) -> None:
def create_channels_on_mm(
prefix: str = Option(""),
suffix: str = Option(""),
invite_teaching_team: bool = Option(False)
) -> None:
groups = {
group_name: members
for group_name, members in tea.pot.gitea.get_all_teams().items()
@ -149,9 +153,10 @@ def create_channels_on_mm(prefix: str = Option(""), suffix: str = Option("")) ->
logger.info(
f"{len(groups)} channel(s) to be created"
+ (f" with suffix {suffix}" if suffix else "")
+ (f", inviting teaching team" if invite_teaching_team else "")
+ f": {','.join(groups.keys())}"
)
tea.pot.mattermost.create_channels_for_groups(groups, suffix)
tea.pot.mattermost.create_channels_for_groups(groups, suffix, invite_teaching_team)
@app.command(

View File

@ -29,6 +29,9 @@ class Settings(BaseSettings):
mattermost_suffix: str = "/mm"
mattermost_access_token: str = ""
mattermost_team: str = ""
mattermost_teaching_team = [
"manuel",
]
# sid
joj_sid: str = ""

View File

@ -40,7 +40,7 @@ class Mattermost:
return
def create_channels_for_groups(
self, groups: Dict[str, List[str]], suffix: str = ""
self, groups: Dict[str, List[str]], suffix: str = "", invite_teaching_team: bool = False
) -> None:
for group_name, members in groups.items():
channel_name = group_name + suffix
@ -59,6 +59,8 @@ class Mattermost:
f"Error when creating channel {channel_name}: {e} Perhaps channel already exists?"
)
continue
if invite_teaching_team:
members.extend(settings.mattermost_teaching_team)
for member in members:
try:
mmuser = self.endpoint.users.get_user_by_username(member)