/
main.py
788 lines (621 loc) · 23.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
from os import path
import atexit
import csv
from datetime import datetime
from flask import Flask, render_template, request, session, redirect, url_for, send_from_directory
from database import Database
from entity_manager import EntityManager
from util import Util
from time_unit import TimeUtil, TimeUnit
from stage import Stage
from role import Role
from incident_value_change_request import IncidentValueChangeRequest
from datetime import timedelta
HTTP_OKAY = 200
HTTP_CREATED = 201
HTTP_BAD_REQUEST = 400
HTTP_FORBIDDEN = 403
HTTP_NOT_FOUND = 404
HTTP_UNPROCESSABLE = 422
HTTP_SERVER_ERROR = 500
app = Flask(__name__, static_url_path='/static', instance_relative_config=True)
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
database = Database('irms.db')
entity_manager = EntityManager(database, False)
entity_manager.initialize()
def handle_shutdown():
database.close()
atexit.register(handle_shutdown)
def get_user():
if 'user_id' in session:
return entity_manager.get_user(int(session['user_id']))
return None
def add_dates(data, incidents):
if len(incidents) > 0:
startDate = incidents[0].date_created
endDate = incidents[0].date_created
for incident in incidents:
if incident.date_created < startDate:
startDate = incident.date_created
if incident.date_created > endDate:
endDate = incident.date_created
if startDate == endDate:
endDate = endDate + timedelta(minutes=1)
data['startDate'] = TimeUtil.datetime_to_string(startDate)
data['endDate'] = TimeUtil.datetime_to_string(endDate)
@app.route('/')
def index():
user = get_user()
if user is None:
return render_template('irms.html', data = {})
else:
if user.role.name == Role.MAJOR_INCIDENT_MANAGER:
incidents = entity_manager.get_all_incidents()
pageTitle = 'All Incidents'
else:
incidents = entity_manager.get_incidents(user)
pageTitle = 'Your Incidents'
notifications = entity_manager.get_user_notifications(user)
data = {
'pageTitle': pageTitle,
'user': user,
'incidents': incidents,
'incidentsLength': len(incidents),
'notifications': notifications,
'notificationsLength': len(notifications)
}
add_dates(data, incidents)
print(data)
return render_template('irms.html', data = data)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
username = content['username']
password = content['password']
user = entity_manager.get_user_by_username(username)
if user is None:
return Util.json_response({'status': 'invalid credential'}, HTTP_OKAY)
if user.password != password:
return Util.json_response({'status': 'invalid credential'}, HTTP_OKAY)
entity_manager.login(user)
session['user_id'] = str(user.id)
if user.role.name == Role.MAJOR_INCIDENT_MANAGER:
incidents = entity_manager.get_all_incidents()
pageTitle = 'All Incidents'
else:
incidents = entity_manager.get_incidents(user)
pageTitle = 'Your Incidents'
notifications = entity_manager.get_notifications(user)
data = {
'pageTitle': pageTitle,
'user': user,
'incidents': incidents,
'incidentsLength': len(incidents),
}
add_dates(data, incidents)
success_response = {
'status': 'success',
'body': render_template('irms_body.html', data = data)
}
response = Util.json_response(success_response, HTTP_OKAY)
return response
@app.route('/logout')
def logout():
user = get_user()
if user is not None:
entity_manager.logout(user)
session.pop('user_id', None)
data = {}
success_response = {
'status': 'logout',
'body': render_template('irms_body.html', data = data)
}
return Util.json_response(success_response, HTTP_OKAY)
@app.route('/decideIncidentTeam/<incident_id>/<team_id>/<decision>')
def decide_incident_team(incident_id, team_id, decision):
incident_id = int(incident_id)
team_id = int(team_id)
incident = entity_manager.get_incident(incident_id)
team = entity_manager.get_team(team_id)
team_assignment_request = entity_manager.get_team_assignment_request(incident, team)
if decision == 'approve':
new_status = IncidentValueChangeRequest.STATUS_APPROVED
elif decision == 'deny':
new_status = IncidentValueChangeRequest.STATUS_DENIED
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
entity_manager.decide_team_assignment_request(user, team_assignment_request, new_status)
return app.response_class(status = HTTP_OKAY)
@app.route('/decideTaskTeam/<task_id>/<team_id>/<decision>')
def decide_task_team(task_id, team_id, decision):
task_id = int(task_id)
team_id = int(team_id)
task = entity_manager.get_task(task_id)
team = entity_manager.get_team(team_id)
team_assignment_request = entity_manager.get_team_assignment_request(task, team)
if decision == 'approve':
new_status = IncidentValueChangeRequest.STATUS_APPROVED
elif decision == 'deny':
new_status = IncidentValueChangeRequest.STATUS_DENIED
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
entity_manager.decide_team_assignment_request(user, team_assignment_request, new_status)
return app.response_class(status = HTTP_OKAY)
@app.route('/requestIncidentTeam/<incident_id>/<team_id>')
def request_incident_team(incident_id, team_id):
incident_id = int(incident_id)
team_id = int(team_id)
user = get_user()
incident = entity_manager.get_incident(incident_id)
team = entity_manager.get_team(team_id)
team_assignment = entity_manager.request_team_assignment(user, incident, team)
team_assignment_obj = {
'name': team_assignment.team.name,
'date_issued': team_assignment.date_issued,
'assigner': (team_assignment.assigner.forename + ' ' + team_assignment.assigner.surname),
'status': IncidentValueChangeRequest.status_to_string(team_assignment.status)
}
return Util.json_response(team_assignment_obj, HTTP_OKAY)
@app.route('/requestTaskTeam/<task_id>/<team_id>')
def request_task_team(task_id, team_id):
task_id = int(task_id)
team_id = int(team_id)
user = get_user()
task = entity_manager.get_task(task_id)
team = entity_manager.get_team(team_id)
team_assignment = entity_manager.request_team_assignment(user, task, team)
team_assignment_obj = {
'name': team_assignment.team.name,
'date_issued': team_assignment.date_issued,
'assigner': (team_assignment.assigner.forename + ' ' + team_assignment.assigner.surname),
'status': IncidentValueChangeRequest.status_to_string(team_assignment.status)
}
return Util.json_response(team_assignment_obj, HTTP_OKAY)
@app.route('/decideChangeRequest/<change_request_id>/<decision>')
def decide_change_request(change_request_id, decision):
change_request_id = int(change_request_id)
change_request = entity_manager.get_change_request(change_request_id)
if decision == 'approve':
new_status = IncidentValueChangeRequest.STATUS_APPROVED
elif decision == 'deny':
new_status = IncidentValueChangeRequest.STATUS_DENIED
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
entity_manager.decide_change_request(user, change_request, new_status)
return app.response_class(status = HTTP_OKAY)
@app.route('/changeIncidentValue/<incident_id>/<value_type>', methods=['POST'])
def request_incident_value_change(incident_id, value_type):
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
if incident is None:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
old_value = content['oldValue']
new_value = content['newValue']
justification = content['justification']
value_type = IncidentValueChangeRequest.string_to_value_type(value_type)
change_request = entity_manager.get_existing_change_request(user, incident, value_type)
if change_request is not None:
entity_manager.update_change_request(user, change_request, new_value, justification)
else:
entity_manager.request_value_change(user, incident, old_value, new_value, value_type, justification)
return app.response_class(status = HTTP_OKAY)
@app.route('/allTeamAssignmentRequests')
def all_team_assignment_requests():
user = get_user()
team_assignment_requests = entity_manager.get_all_team_assignment_requests()
data = {
'pageTitle': 'All Requests',
'user': user,
'requests': team_assignment_requests,
'requestsLength': len(team_assignment_requests),
'requestType': 'team'
}
return render_template('list_requests.html', data = data)
@app.route('/listTeamAssignmentRequests')
def list_team_assignment_requests():
user = get_user()
#team_assignment_requests = entity_manager.get_team_assignment_requests()
data = {
'pageTitle': 'Your Requests',
'user': user,
#'requests': team_assignment_requests,
#'requestsLength': len(team_assignment_requests),
'requestType': 'team',
'tab': 'team'
}
return render_template('list_requests.html', data = data)
@app.route('/allChangeRequests')
def all_change_requests():
user = get_user()
change_requests = entity_manager.get_all_change_requests()
data = {
'pageTitle': 'All Requests',
'user': user,
'requests': change_requests,
'requestsLength': len(change_requests),
'requestType': 'value'
}
return render_template('list_requests.html', data = data)
@app.route('/listChangeRequests')
def list_change_requests():
user = get_user()
change_requests = entity_manager.get_change_requests(user)
data = {
'pageTitle': 'Your Requests',
'user': user,
'requests': change_requests,
'requestsLength': len(change_requests),
'requestType': 'value'
}
return render_template('list_requests.html', data = data)
@app.route('/allIncidents')
def all_incidents():
user = get_user()
incidents = entity_manager.get_all_incidents()
data = {
'pageTitle': 'All Incidents',
'user': user,
'incidents': incidents,
'incidentsLength': len(incidents)
}
add_dates(data, incidents)
return render_template('list_incidents.html', data = data)
@app.route('/listUsers')
def list_users():
roles = entity_manager.get_all_roles()
users = entity_manager.get_users()
data = {
'usersLength': len(users),
'users': users,
'rolesLength': len(roles),
'roles': roles
}
return render_template('list_Users.html', data = data)
@app.route('/updateRole/<user_id>', methods=['POST'])
def update_user_role(user_id):
user_id = int(user_id)
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = entity_manager.get_user(user_id)
role_name = content['role']
new_role = entity_manager.get_role_by_name(role_name)
entity_manager.update_user_role(user, new_role)
return app.response_class(status = HTTP_OKAY)
@app.route('/viewIncident/<incident_id>')
def view_incident(incident_id):
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
impacts = entity_manager.get_all_impacts()
priorities = entity_manager.get_all_priorities()
severities = entity_manager.get_all_severities()
assigned_teams = entity_manager.get_assigned_teams(incident)
team_assignment_requests = entity_manager.get_team_assignment_requests(incident)
for team_assignment_request in team_assignment_requests:
if team_assignment_request.status == IncidentValueChangeRequest.STATUS_PENDING:
assigned_teams.append(team_assignment_request)
departments = entity_manager.get_all_departments()
department = departments[0]
teams = entity_manager.get_teams(department)
user = get_user()
for task in incident.tasks:
print(task.teams)
data = {
'user': user,
'incident': incident,
'priorities': priorities,
'prioritiesLength': len(priorities),
'impacts': impacts,
'impactsLength': len(impacts),
'severities': severities,
'severitiesLength': len(severities),
'assigned_teams': assigned_teams,
'assignedTeamsLength': len(assigned_teams),
'departmentsLength': len(departments),
'departments': departments,
'teamsLength': len(teams),
'teams': teams,
'notesLength': len(incident.notes),
'notes': incident.notes,
'questionsLength': len(incident.questions),
'questions': incident.questions,
'tasksLength': len(incident.tasks),
'tasks': incident.tasks
}
return render_template('view_incident.html', data = data)
@app.route('/listIncidents')
def list_incidents():
user = get_user()
incidents = entity_manager.get_incidents(user)
data = {
'pageTitle': 'Your Incidents',
'user': user,
'incidents': incidents,
'incidentsLength': len(incidents)
}
add_dates(data, incidents)
return render_template('list_incidents.html', data = data)
@app.route('/serviceDeskIncidents')
def service_desk_incidents():
user = get_user()
incidents = entity_manager.get_service_desk_incidents()
data = {
'pageTitle': 'Service Desk Incidents',
'user': user,
'incidents': incidents,
'incidentsLength': len(incidents)
}
add_dates(data, incidents)
return render_template('list_incidents.html', data = data)
@app.route('/raiseIncident', methods = ['GET', 'POST'])
def raise_incident():
if request.method == 'POST':
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
author = get_user()
if author is None:
return app.response_class(status = HTTP_FORBIDDEN)
title = content['title']
description = content['description']
sanitizedIdentificationDeadline = TimeUtil.sanitize_time_input(content['identificationDeadline'])
sanitizedImplementationDeadline = TimeUtil.sanitize_time_input(content['implementationDeadline'])
identificationDeadline = TimeUtil.sqlite_to_datetime(sanitizedIdentificationDeadline)
implementationDeadline = TimeUtil.sqlite_to_datetime(sanitizedImplementationDeadline)
impact = entity_manager.get_impact_by_level(content['impact'])
severity = entity_manager.get_severity_by_code(content['severity'])
system = entity_manager.get_system_class_by_name(content['system'])
priority = entity_manager.get_priority_by_code(content['priority'])
team = entity_manager.get_team(int(content['team']))
status = entity_manager.get_stage_by_level(Stage.IDENTIFYING)
incident = entity_manager.create_incident(title, description, author, \
identificationDeadline, implementationDeadline, status, system, \
impact, priority, severity)
if 'onBehalf' in content:
on_behalf_user = entity_manager.get_user(int(content['onBehalf']))
entity_manager.create_on_behalf(incident, on_behalf_user)
print(author)
print(incident)
print(team)
entity_manager.request_team_assignment(author, incident, team)
return app.response_class(status = HTTP_CREATED)
severities = entity_manager.get_all_severities()
impacts = entity_manager.get_all_impacts()
system_classes = entity_manager.get_all_system_classes()
priorities = entity_manager.get_all_priorities()
departments = entity_manager.get_all_departments()
department = departments[0]
teams = entity_manager.get_teams(department)
user = get_user()
data = {
'user': user,
'impactsLength': len(impacts),
'impacts': impacts,
'prioritiesLength': len(priorities),
'priorities': priorities,
'severitiesLength': len(severities),
'severities': severities,
'systemClassesLength': len(system_classes),
'system_classes': system_classes,
'departmentsLength': len(departments),
'departments': departments,
'teamsLength': len(teams),
'teams': teams
}
return render_template('raise_incident.html', data = data)
@app.route('/addNote/<incident_id>', methods=['POST'])
def add_note(incident_id):
incident_id = int(incident_id)
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
incident = entity_manager.get_incident(incident_id)
title = content['title']
noteContent = content['content']
entity_manager.create_note(user, incident, title, noteContent)
return app.response_class(status = HTTP_OKAY)
@app.route('/viewNote/<note_id>')
def view_note(note_id):
note_id = int(note_id)
note = entity_manager.get_note(note_id)
data = {
'note': note
}
return render_template('view_note.html', data = data)
@app.route('/askQuestion/<incident_id>', methods=['POST'])
def ask_question(incident_id):
incident_id = int(incident_id)
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
incident = entity_manager.get_incident(incident_id)
title = content['title']
questionContent = content['content']
entity_manager.create_question(user, incident, title, questionContent)
return app.response_class(status = HTTP_OKAY)
@app.route('/answerQuestion/<question_id>', methods=['POST'])
def answer_question(question_id):
question_id = int(question_id)
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
question = entity_manager.get_question(question_id)
answer = content['answer']
entity_manager.answer_question(user, question, answer)
return app.response_class(status = HTTP_OKAY)
@app.route('/viewQuestion/<question_id>')
def view_question(question_id):
question_id = int(question_id)
question = entity_manager.get_question(question_id)
data = {
'question': question
}
return render_template('view_question.html', data = data)
@app.route('/addTask/<incident_id>', methods=['POST'])
def add_task(incident_id):
incident_id = int(incident_id)
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
incident = entity_manager.get_incident(incident_id)
title = content['title']
taskContent = content['content']
entity_manager.create_task(user, incident, title, taskContent)
return app.response_class(status = HTTP_OKAY)
@app.route('/departmentTeams/<department_name>')
def get_teams(department_name):
department = entity_manager.get_department_by_name(department_name)
teams = entity_manager.get_teams(department)
team_objects = []
for team in teams:
team_objects.append({ 'team_id': team.id, 'team_name': team.name})
return Util.json_response({ 'teams': team_objects }, HTTP_OKAY)
@app.route('/followIncident/<incident_id>')
def follow_incident(incident_id):
incident_id = int(incident_id)
user = get_user()
incident = entity_manager.get_incident(incident_id)
entity_manager.follow(user, incident)
return app.response_class(status = HTTP_OKAY)
@app.route('/notifications')
def notifications():
user = get_user()
if user is None:
return app.response_class(status = HTTP_OKAY)
notifications = entity_manager.get_user_notifications(user)
unseen = 0
for notification in notifications:
if not notification.seen:
unseen += 1
entity_manager.seen_user_notification(notification)
data = {
'notifications': notifications,
'notificationsLength': len(notifications)
}
json_response = {
'unseen': unseen,
'body': render_template('notification-body.html', data = data)
}
return Util.json_response(json_response, HTTP_OKAY)
@app.route('/allUsers')
def usernames():
users = entity_manager.get_users()
users_response = []
for user in users:
name = user.forename + ' ' + user.surname
users_response.append({ 'id': user.id, 'name': name})
return Util.json_response({ 'users': users_response }, HTTP_OKAY)
@app.route('/exportCSV/<incident_id>')
def export_csv(incident_id):
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
reportsDir = path.join(app.root_path, 'reports')
filename = 'incident' + str(incident_id) + '.csv'
with open(reportsDir + '/' + filename, mode='w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file, delimiter=",")
incident.to_csv(writer)
return send_from_directory(directory = reportsDir, filename = filename)
@app.route('/listExportCSV', methods=['POST'])
def list_export_csv():
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
user = get_user()
start = content['startDate']
end = content['endDate']
incidentIds = content['incidents']
incidents = []
for incidentId in incidentIds:
incidents.append(entity_manager.get_incident(int(incidentId)))
print(incidents)
startDate = TimeUtil.sqlite_to_datetime(TimeUtil.sanitize_time_input(start))
endDate = TimeUtil.sqlite_to_datetime(TimeUtil.sanitize_time_input(end)) + timedelta(days=1)
selectedIncidents = []
for incident in incidents:
if incident.date_created >= startDate and incident.date_created <= endDate:
selectedIncidents.append(incident)
current_date = TimeUtil.now()
reportsDir = path.join(app.root_path, 'reports')
filename = 'incident' + current_date.strftime('%Y_%m_%d_%H_%M_%S') + '.csv'
with open(reportsDir + '/' + filename, mode='w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file, delimiter=",")
writer.writerow(["ID", "Title", "Description", "Author", "SLA Identification Deadline", "Date Identified", \
"SLA Implementation Deadline", "Date Implemented", "Time To Resolve", "Status", "System", "Impact", "Priority", "Severity", "Note Count", \
"Question Count", "Task Count"])
for incident in selectedIncidents:
author_name = incident.author.forename + ' ' + incident.author.surname
date_identified = incident.date_identified if incident.date_identified is not None else 'N/A'
date_implemented = incident.date_implemented if incident.date_implemented is not None else 'N/A'
ttr = (datetime.strptime(incident.date_implemented, '%Y-%m-%d %H:%M:%S') - incident.get_date_created()) if incident.date_implemented is not None else 'N/A'
writer.writerow([incident.id, incident.title, incident.description, author_name, incident.sla_identification_deadline, date_identified, incident.sla_implementation_deadline, date_implemented, \
ttr, incident.status.level, incident.system.name, incident.impact.level, incident.priority.code, incident.severity.code, len(incident.notes), len(incident.questions), len(incident.tasks)])
return send_from_directory(directory = reportsDir, filename = filename)
@app.route('/updateValue/<incident_id>', methods=['POST'])
def update_value(incident_id):
if request.is_json:
content = request.json
else:
return app.response_class(status = HTTP_BAD_REQUEST)
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
user = get_user()
value_type = content['valueType']
new_value = content['newValue']
entity_manager.update_incident_value(user, incident, IncidentValueChangeRequest.string_to_value_type(value_type), new_value)
return app.response_class(status = HTTP_OKAY)
@app.route('/resolutionIdentified/<incident_id>')
def identified(incident_id):
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
user = get_user()
entity_manager.update_incident_identified_date(user, incident)
status = incident.status
date = incident.date_identified
return Util.json_response({ 'status': status.level, 'status_class': status.get_class(), 'date': date }, HTTP_OKAY)
@app.route('/resolutionImplemented/<incident_id>')
def implemented(incident_id):
incident_id = int(incident_id)
incident = entity_manager.get_incident(incident_id)
user = get_user()
entity_manager.update_incident_implemented_date(user, incident)
status = incident.status
date = incident.date_implemented
return Util.json_response({ 'status': status.level, 'status_class': status.get_class(), 'date': date }, HTTP_OKAY)
@app.route('/userNavBar')
def user_mode():
user = get_user()
data = {
'user': user
}
return render_template('user_navbar.html', data = data)
@app.route('/managerNavBar')
def manager_mode():
user = get_user()
data = {
'user': user
}
return render_template('manager_navbar.html', data = data)
app.run()