1
0
mirror of https://github.com/linkedin/oncall.git synced 2025-11-29 23:38:17 +02:00

add note to event

This commit is contained in:
Qingping Hou
2017-06-29 11:31:23 -07:00
committed by Daniel Wang
parent 747edb583e
commit a47ed21c4d
8 changed files with 84 additions and 19 deletions

View File

@@ -2,7 +2,11 @@
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (1,'root',1,'God User',NULL,NULL,1),(2,'manager',1,'Team Admin',NULL,NULL,0),(3,'jdoe',1,'John Doe',NULL,NULL,0),(4,'asmith',1,'Alice Smith',NULL,NULL,0);
INSERT INTO `user` VALUES
(1,'root',1,'God User',NULL,NULL,1),
(2,'manager',1,'Team Admin',NULL,NULL,0),
(3,'jdoe',1,'John Doe',NULL,NULL,0),
(4,'asmith',1,'Alice Smith',NULL,NULL,0);
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
@@ -119,7 +123,13 @@ UNLOCK TABLES;
LOCK TABLES `event` WRITE;
/*!40000 ALTER TABLE `event` DISABLE KEYS */;
INSERT INTO `event` VALUES (1,1,1,1,NULL,3,1495555200,1496160000),(2,1,1,1,NULL,4,1496160000,1496764800),(3,1,1,1,NULL,3,1496764800,1497369600),(7,1,4,2,NULL,2,1495555200,1496160000),(8,1,4,2,NULL,2,1496160000,1496764800),(9,1,4,2,NULL,2,1496764800,1497369600);
INSERT INTO `event` (`id`, `team_id`, `role_id`, `schedule_id`, `user_id`, `start`, `end`) VALUES
(1,1,1,1,3,1495555200,1496160000),
(2,1,1,1,4,1496160000,1496764800),
(3,1,1,1,3,1496764800,1497369600),
(7,1,4,2,2,1495555200,1496160000),
(8,1,4,2,2,1496160000,1496764800),
(9,1,4,2,2,1496764800,1497369600);
/*!40000 ALTER TABLE `event` ENABLE KEYS */;
UNLOCK TABLES;

View File

@@ -189,7 +189,7 @@ CREATE TABLE IF NOT EXISTS `event` (
-- seconds since epoch (unix timestamp)
`start` BIGINT(20) NOT NULL,
`end` BIGINT(20) NOT NULL,
`note` TEXT,
PRIMARY KEY (`id`),
INDEX `event_role_id_fk_idx` (`role_id` ASC),
INDEX `event_user_id_fk_idx` (`user_id` ASC),

View File

@@ -73,7 +73,8 @@ def test_events(team, user, role):
'role': role_name,
'schedule_id': None,
'link_id': None,
'full_name': None
'full_name': None,
'note': None,
}
# test get events by team

View File

@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.1.0'

View File

@@ -7,7 +7,9 @@ from falcon import HTTPNotFound, HTTPBadRequest, HTTPForbidden
from ...auth import login_required, check_calendar_auth
from ... import db
from ...utils import load_json_body, user_in_team_by_name, create_notification, create_audit
from ...utils import (
load_json_body, user_in_team_by_name, create_notification, create_audit
)
from ...constants import EVENT_DELETED, EVENT_EDITED
from events import columns, all_columns
@@ -16,7 +18,8 @@ update_columns = {
'start': '`start`=%(start)s',
'end': '`end`=%(end)s',
'role': '`role_id`=(SELECT `id` FROM `role` WHERE `name`=%(role)s)',
'user': '`user_id`=(SELECT `id` FROM `user` WHERE `name`=%(user)s)'
'user': '`user_id`=(SELECT `id` FROM `user` WHERE `name`=%(user)s)',
'note': '`note`=%(note)s'
}
@@ -114,6 +117,7 @@ def on_put(req, resp, event_id):
`event`.`user_id`,
`event`.`role_id`,
`event`.`id`,
`event`.`note`,
`team`.`name` AS `team`,
`role`.`name` AS `role`,
`user`.`name` AS `user`,

View File

@@ -6,7 +6,9 @@ from falcon import HTTP_201, HTTPError, HTTPBadRequest
from ujson import dumps as json_dumps
from ...auth import login_required, check_calendar_auth
from ... import db
from ...utils import load_json_body, user_in_team_by_name, create_notification, create_audit
from ...utils import (
load_json_body, user_in_team_by_name, create_notification, create_audit
)
from ...constants import EVENT_CREATED
columns = {
@@ -18,7 +20,8 @@ columns = {
'user': '`user`.`name` as `user`',
'full_name': '`user`.`full_name` as `full_name`',
'schedule_id': '`event`.`schedule_id`',
'link_id': '`event`.`link_id`'
'link_id': '`event`.`link_id`',
'note': '`event`.`note`',
}
all_columns = ', '.join(columns.values())
@@ -66,7 +69,8 @@ constraints = {
def on_get(req, resp):
"""
Search for events. Allows filtering based on a number of parameters, detailed below.
Search for events. Allows filtering based on a number of parameters,
detailed below.
**Example request**:
@@ -219,7 +223,8 @@ def on_post(req, resp):
check_calendar_auth(data['team'], req)
columns = ['`start`', '`end`', '`user_id`', '`team_id`', '`role_id`']
values = ['%(start)s', '%(end)s', '(SELECT `id` FROM `user` WHERE `name`=%(user)s)',
values = ['%(start)s', '%(end)s',
'(SELECT `id` FROM `user` WHERE `name`=%(user)s)',
'(SELECT `id` FROM `team` WHERE `name`=%(team)s)',
'(SELECT `id` FROM `role` WHERE `name`=%(role)s)']
@@ -227,6 +232,10 @@ def on_post(req, resp):
columns.append('`schedule_id`')
values.append('%(schedule_id)s')
if 'note' in data:
columns.append('`note`')
values.append('%(note)s')
connection = db.connect()
cursor = connection.cursor(db.DictCursor)
@@ -241,10 +250,22 @@ def on_post(req, resp):
cursor.execute('SELECT team_id, role_id, user_id, start, full_name '
'FROM event JOIN user ON user.`id` = user_id WHERE event.id=%s', event_id)
ev_info = cursor.fetchone()
context = {'team': data['team'], 'role': data['role'], 'full_name': ev_info['full_name']}
create_notification(context, ev_info['team_id'], [ev_info['role_id']], EVENT_CREATED,
[ev_info['user_id']], cursor, start_time=ev_info['start'])
create_audit({'new_event_id': event_id, 'request_body': data}, data['team'], EVENT_CREATED, req, cursor)
context = {
'team': data['team'],
'role': data['role'],
'full_name': ev_info['full_name']
}
create_notification(context, ev_info['team_id'],
[ev_info['role_id']],
EVENT_CREATED,
[ev_info['user_id']],
cursor,
start_time=ev_info['start'])
create_audit({'new_event_id': event_id, 'request_body': data},
data['team'],
EVENT_CREATED,
req,
cursor)
connection.commit()
except db.IntegrityError as e:
err_msg = str(e.args[1])

View File

@@ -1245,6 +1245,14 @@
})
)
)
.append(
$('<li />')
.append('<label class="label-col">Note: </label>')
.append(
$('<div class="input-col" />')
.append('<input type="text" id="inc-event-note" name="inc-event-note" value="" style="width:100%" /> ')
)
)
.append('<h5 class="divider-text"> Substitute </h5>')
.append(
$('<li class="toggle-input" />')
@@ -1292,8 +1300,14 @@
start: self._createMoment($modal.find('#inc-event-start-date').val() + ' ' + $modal.find('#inc-event-start-time').val()).valueOf(),
end: self._createMoment($modal.find('#inc-event-end-date').val() + ' ' + $modal.find('#inc-event-end-time').val()).valueOf(),
team: self.options.team,
user: $modal.find('#inc-event-user').val()
user: $modal.find('#inc-event-user').val(),
}
var note = $modal.find('#inc-event-note').val();
if (!!note) {
evt.note = note;
}
if ($modal.attr('data-override') === "true") {
// override logic goes here
$('#inc-override-event-list').find('input[type="checkbox"]:checked').each(function(){
@@ -1389,6 +1403,11 @@
.append('<label class="label-col">User: </label>')
.append('<span class="data-col">' + evt.user + '</span>')
)
.append(
$('<li />')
.append('<label class="label-col">Note: </label>')
.append('<span class="data-col">' + (evt.note || "") + '</span>')
)
)
.append(
$('<div class="inc-event-details inc-event-details-edit" />')
@@ -1443,6 +1462,14 @@
})
)
)
.append(
$('<li />')
.append('<label class="label-col">Note: </label>')
.append(
$('<div class="input-col" />')
.append('<input type="text" id="inc-event-note" name="inc-event-note" value="' + (evt.note || '') + '" style="width:100%" /> ')
)
)
.append(
$('<li class="toggle-input" />')
.append(
@@ -1494,6 +1521,7 @@
updatedEvt.start = self._createMoment($modal.find('#inc-event-start-date').val() + ' ' + $modal.find('#inc-event-start-time').val()).valueOf();
updatedEvt.end = self._createMoment($modal.find('#inc-event-end-date').val() + ' ' + $('#inc-event-end-time').val()).valueOf();
updatedEvt.user = $('#inc-event-user').val();
updatedEvt.note = $('#inc-event-note').val();
self.updateEvent($modal, updatedEvt);
})
)
@@ -1634,7 +1662,8 @@
role: evt.role,
start: evt.start / 1000,
end: evt.end / 1000,
user: evt.user
user: evt.user,
note: evt.note,
}
// #TODO: convert times to second for API. find a better solution for interacting with api.
@@ -1652,6 +1681,7 @@
item.end = evt.end;
item.role = evt.role;
item.user = evt.user;
item.note = evt.note;
item.formatted = false;
item.link_id = null; // break link on individual event swap
delete item.full_name;

View File

@@ -1051,8 +1051,7 @@ var oncall = {
if (evt.schedule_id) {
$ul.append(
$('<li />')
.append('<label class="label-col">Note</label>')
.append('<span class="data-col">This event is auto generated by the scheduler</span>')
.append('<small>This event is auto generated by the scheduler</small>')
);
}
},