@@ -105,14 +105,36 @@ def post(self):
105105
106106 if operation == self .REMOVE :
107107 asking_page = self .url ("users" , user_id , "remove" )
108- # Open asking for remove page
109108 self .redirect (asking_page )
110109 else :
111110 self .service .add_notification (
112111 make_datetime (), "Invalid operation %s" % operation , "" )
113112 self .redirect (self .url ("contests" ))
114113
115114
115+ class TeamListHandler (SimpleHandler ("teams.html" )):
116+ """Get returns the list of all teams, post perform operations on
117+ a specific team (removing them from CMS).
118+
119+ """
120+
121+ REMOVE = "Remove"
122+
123+ @require_permission (BaseHandler .AUTHENTICATED )
124+ def post (self ):
125+ team_id : str = self .get_argument ("team_id" )
126+ operation : str = self .get_argument ("operation" )
127+
128+ if operation == self .REMOVE :
129+ asking_page = self .url ("teams" , team_id , "remove" )
130+ self .redirect (asking_page )
131+ else :
132+ self .service .add_notification (
133+ make_datetime (), "Invalid operation %s" % operation , ""
134+ )
135+ self .redirect (self .url ("contests" ))
136+
137+
116138class RemoveUserHandler (BaseHandler ):
117139 """Get returns a page asking for confirmation, delete actually removes
118140 the user from CMS.
@@ -145,6 +167,47 @@ def delete(self, user_id):
145167 self .write ("../../users" )
146168
147169
170+ class RemoveTeamHandler (BaseHandler ):
171+ """Get returns a page asking for confirmation, delete actually removes
172+ the team from CMS.
173+
174+ """
175+
176+ @require_permission (BaseHandler .PERMISSION_ALL )
177+ def get (self , team_id ):
178+ team = self .safe_get_item (Team , team_id )
179+ participation_query = self .sql_session .query (Participation ).filter (
180+ Participation .team == team
181+ )
182+
183+ self .r_params = self .render_params ()
184+ self .r_params ["team" ] = team
185+ self .r_params ["participation_count" ] = participation_query .count ()
186+ self .render ("team_remove.html" , ** self .r_params )
187+
188+ @require_permission (BaseHandler .PERMISSION_ALL )
189+ def delete (self , team_id ):
190+ team = self .safe_get_item (Team , team_id )
191+ try :
192+
193+ # Remove associations
194+ self .sql_session .query (Participation ).filter (
195+ Participation .team_id == team_id
196+ ).update ({Participation .team_id : None })
197+
198+ # delete the team
199+ self .sql_session .delete (team )
200+ if self .try_commit ():
201+ self .service .proxy_service .reinitialize ()
202+ except Exception as fallback_error :
203+ self .service .add_notification (
204+ make_datetime (), "Error removing team" , repr (fallback_error )
205+ )
206+
207+ # Maybe they'll want to do this again (for another team)
208+ self .write ("../../teams" )
209+
210+
148211class TeamHandler (BaseHandler ):
149212 """Manage a single team.
150213
0 commit comments