feat: Option to invite teaching team when creating MM channels (#17)
Also add config for mattermost_teaching_team
This commit is contained in:
		
							parent
							
								
									95b2edd804
								
							
						
					
					
						commit
						6c0df81ec6
					
				|  | @ -140,18 +140,23 @@ def upload_assignment_grades(assignments_dir: Path, assignment_name: str) -> Non | ||||||
|     help="create channels for student groups according to group information on" |     help="create channels for student groups according to group information on" | ||||||
|     " gitea", |     " 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 = { |     groups = { | ||||||
|         group_name: members |         group_name: members | ||||||
|         for group_name, members in tea.pot.gitea.get_all_teams().items() |         for group_name, members in tea.pot.gitea.get_all_teams().items() | ||||||
|         if group_name.startswith(prefix) |         if group_name.startswith(prefix) | ||||||
|     } |     } | ||||||
|     logger.info( |     logger.info( | ||||||
|         f"{len(groups)} channel(s) to be created " |         f"{len(groups)} channel(s) to be created" | ||||||
|         + (f"with suffix {suffix}" if suffix else "") |         + (f" with suffix {suffix}" if suffix else "") | ||||||
|  |         + (f", inviting teaching team" if invite_teaching_team else "") | ||||||
|         + f": {','.join(groups.keys())}" |         + 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( | @app.command( | ||||||
|  |  | ||||||
|  | @ -29,6 +29,9 @@ class Settings(BaseSettings): | ||||||
|     mattermost_suffix: str = "/mm" |     mattermost_suffix: str = "/mm" | ||||||
|     mattermost_access_token: str = "" |     mattermost_access_token: str = "" | ||||||
|     mattermost_team: str = "" |     mattermost_team: str = "" | ||||||
|  |     mattermost_teaching_team = [ | ||||||
|  |         "manuel", | ||||||
|  |     ] | ||||||
| 
 | 
 | ||||||
|     # sid |     # sid | ||||||
|     joj_sid: str = "" |     joj_sid: str = "" | ||||||
|  |  | ||||||
|  | @ -40,7 +40,7 @@ class Mattermost: | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|     def create_channels_for_groups( |     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: |     ) -> None: | ||||||
|         for group_name, members in groups.items(): |         for group_name, members in groups.items(): | ||||||
|             channel_name = group_name + suffix |             channel_name = group_name + suffix | ||||||
|  | @ -59,6 +59,8 @@ class Mattermost: | ||||||
|                     f"Error when creating channel {channel_name}: {e} Perhaps channel already exists?" |                     f"Error when creating channel {channel_name}: {e} Perhaps channel already exists?" | ||||||
|                 ) |                 ) | ||||||
|                 continue |                 continue | ||||||
|  |             if invite_teaching_team: | ||||||
|  |                 members.extend(settings.mattermost_teaching_team) | ||||||
|             for member in members: |             for member in members: | ||||||
|                 try: |                 try: | ||||||
|                     mmuser = self.endpoint.users.get_user_by_username(member) |                     mmuser = self.endpoint.users.get_user_by_username(member) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Frederick
						Frederick