1
0
mirror of https://github.com/linkedin/oncall.git synced 2025-11-30 23:44:59 +02:00

team name change on deletion (#188)

* on delete change team name to uuid to avoid future conflicts

* string formating

* requested changes

* close connection
This commit is contained in:
Diego Cepeda
2018-07-30 15:28:48 -07:00
committed by Daniel Wang
parent 566801f0ad
commit 5ab4685414
2 changed files with 33 additions and 4 deletions

View File

@@ -17,6 +17,22 @@ CREATE TABLE IF NOT EXISTS `team` (
PRIMARY KEY (`id`),
UNIQUE INDEX `name_unique` (`name` ASC));
-- -----------------------------------------------------
-- Table `deleted_team`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `deleted_team` (
`team_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`new_name` VARCHAR(255) NOT NULL,
`old_name` VARCHAR(255) NOT NULL,
`deletion_date` BIGINT(20) NOT NULL,
PRIMARY KEY (`team_id`),
CONSTRAINT `deleted_team_team_fk`
FOREIGN KEY (`team_id`)
REFERENCES `team` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
UNIQUE INDEX `new_name_unique` (`new_name` ASC));
-- -----------------------------------------------------
-- Table `user`
-- -----------------------------------------------------

View File

@@ -1,6 +1,7 @@
# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
# See LICENSE in the project root for license information.
import uuid
import time
from urllib import unquote
from falcon import HTTPNotFound, HTTPBadRequest, HTTPError
from ujson import dumps as json_dumps
@@ -244,6 +245,8 @@ def on_delete(req, resp, team):
:statuscode 404: Team not found
'''
team = unquote(team)
new_team = str(uuid.uuid4())
deletion_date = time.time()
check_team_auth(team, req)
connection = db.connect()
cursor = connection.cursor()
@@ -253,9 +256,19 @@ def on_delete(req, resp, team):
'AND `start` > UNIX_TIMESTAMP()', team)
create_audit({}, team, TEAM_DELETED, req, cursor)
deleted = cursor.rowcount
if deleted == 0:
connection.commit()
cursor.close()
connection.close()
raise HTTPNotFound()
cursor.execute('SELECT `id` FROM `team` WHERE `name`=%s', team)
team_id = cursor.fetchone()
# create entry in deleted_teams and then change name in team to preserve a clean namespace
cursor.execute('UPDATE `team` SET `name` = %s WHERE `name`= %s', (new_team, team))
cursor.execute('INSERT INTO `deleted_team` (team_id, new_name, old_name, deletion_date) VALUES (%s, %s, %s, %s)', (team_id, new_team, team, deletion_date))
connection.commit()
cursor.close()
connection.close()
if deleted == 0:
raise HTTPNotFound()