Skip to content

Commit 08b94bd

Browse files
authored
MYSQL SCHEMA CHANGE - add api managed teams that disable UI info changes (#396)
* MYSQL SCHEMQA CHANGE - add api_managed_roster * whitespace formatting * test * test * update changelog * update test * update schema-update file name
1 parent f5f2040 commit 08b94bd

File tree

8 files changed

+47
-9
lines changed

8 files changed

+47
-9
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
5+
## [2.0.0] - 2023-06-06
6+
WARNING: this version adds a change to the MYSQL schema! Make changes to the schema before deploying new 2.0.0 version.
7+
8+
### Added
9+
- MINOR added the ability to designate teams as "api managed" which will prevent changes to team info from being done via the UI
10+
### Changed
11+
- MAJOR added the `api_managed_roster` column to the `team` table in the MYSQL schema. Before running 2.0.0 the MYSQL schema must be updated with the new column to avoid errors, to do so run `mysql -u root -p oncall < ./db/schema-update.v2.0.0_2023-06-06.sql`
12+
13+
### Fixed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- -----------------------------------------------------
2+
-- Update to Table `team`
3+
-- -----------------------------------------------------
4+
5+
ALTER TABLE `team`
6+
ADD `api_managed_roster` BOOLEAN NOT NULL DEFAULT FALSE;

db/schema.v0.sql

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `team` (
1515
`iris_plan` VARCHAR(255),
1616
`iris_enabled` BOOLEAN NOT NULL DEFAULT FALSE,
1717
`override_phone_number` VARCHAR(255),
18+
`api_managed_roster` BOOLEAN NOT NULL DEFAULT FALSE,
1819
PRIMARY KEY (`id`),
1920
UNIQUE INDEX `name_unique` (`name` ASC));
2021

e2e/test_teams.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_api_v0_get_team(team, role, roster, schedule):
7070
team = re.json()
7171
assert isinstance(team, dict)
7272
expected_set = {'users', 'admins', 'services', 'rosters', 'name', 'id', 'slack_channel', 'slack_channel_notifications', 'email',
73-
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number'}
73+
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'}
7474
assert expected_set == set(team.keys())
7575

7676
# it should also support filter by fields
@@ -79,7 +79,7 @@ def test_api_v0_get_team(team, role, roster, schedule):
7979
team = re.json()
8080
assert isinstance(team, dict)
8181
expected_set = {'users', 'admins', 'services', 'name', 'id', 'slack_channel', 'slack_channel_notifications', 'email',
82-
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number'}
82+
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'}
8383
assert expected_set == set(team.keys())
8484

8585

@@ -113,6 +113,7 @@ def test_api_v0_update_team(team):
113113
# edit team name/email/slack
114114
re = requests.put(api_v0('teams/'+team_name), json={'name': new_team_name,
115115
'email': email,
116+
'api_managed_roster': True,
116117
'slack_channel': slack,
117118
'slack_channel_notifications': slack_notifications,
118119
'override_phone_number': override_num})
@@ -128,6 +129,7 @@ def test_api_v0_update_team(team):
128129
assert data['slack_channel'] == slack
129130
assert data['slack_channel_notifications'] == slack_notifications
130131
assert data['override_phone_number'] == override_num
132+
assert data['api_managed_roster'] == 1
131133

132134

133135
@prefix('test_v0_team_admin')

src/oncall/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.5.5'
1+
__version__ = '2.0.0'

src/oncall/api/v0/team.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from .rosters import get_roster_by_team_id
1212
from ...auth import login_required, check_team_auth
1313
from ...utils import load_json_body, invalid_char_reg, create_audit
14-
from ...constants import TEAM_DELETED, TEAM_EDITED
14+
from ...constants import TEAM_DELETED, TEAM_EDITED, SUPPORTED_TIMEZONES
1515

1616
# Columns which may be modified
1717
cols = set(['name', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
18-
'iris_plan', 'iris_enabled', 'override_phone_number'])
18+
'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'])
1919

2020

2121
def populate_team_users(cursor, team_dict):
@@ -148,7 +148,7 @@ def on_get(req, resp, team):
148148
connection = db.connect()
149149
cursor = connection.cursor(db.DictCursor)
150150
cursor.execute('''SELECT `id`, `name`, `email`, `slack_channel`, `slack_channel_notifications`,
151-
`scheduling_timezone`, `iris_plan`, `iris_enabled`, `override_phone_number`
151+
`scheduling_timezone`, `iris_plan`, `iris_enabled`, `override_phone_number`, `api_managed_roster`
152152
FROM `team` WHERE `name`=%s AND `active` = %s''', (team, active))
153153
results = cursor.fetchall()
154154
if not results:
@@ -172,7 +172,8 @@ def on_get(req, resp, team):
172172
@login_required
173173
def on_put(req, resp, team):
174174
'''
175-
Edit a team's information. Allows edit of: name, slack_channel, email, scheduling_timezone, iris_plan.
175+
Edit a team's information. Allows edit of: 'name', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
176+
'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'
176177
177178
**Example request:**
178179
@@ -213,9 +214,18 @@ def on_put(req, resp, team):
213214
plan_resp = iris.client.get(iris.client.url + 'plans?name=%s&active=1' % iris_plan)
214215
if plan_resp.status_code != 200 or plan_resp.json() == []:
215216
raise HTTPBadRequest('invalid iris escalation plan', 'no iris plan named %s exists' % iris_plan)
217+
if 'iris_enabled' in data:
218+
if not type(data['iris_enabled']) == bool:
219+
raise HTTPBadRequest('invalid payload', 'iris_enabled must be boolean')
220+
if 'api_managed_roster' in data:
221+
if not type(data['api_managed_roster']) == bool:
222+
raise HTTPBadRequest('invalid payload', 'api_managed_roster must be boolean')
223+
if 'scheduling_timezone' in data:
224+
if data['scheduling_timezone'] not in SUPPORTED_TIMEZONES:
225+
raise HTTPBadRequest('invalid payload', 'requested scheduling_timezone is not supported. Supported timezones: %s' % str(SUPPORTED_TIMEZONES))
216226

217227
set_clause = ', '.join(['`{0}`=%s'.format(d) for d in data_cols if d in cols])
218-
query_params = tuple(data[d] for d in data_cols) + (team,)
228+
query_params = tuple(data[d] for d in data_cols if d in cols) + (team,)
219229
try:
220230
update_query = 'UPDATE `team` SET {0} WHERE name=%s'.format(set_clause)
221231
cursor.execute(update_query, query_params)

src/oncall/ui/static/js/oncall.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,8 @@ var oncall = {
13641364
data.isAdmin = true;
13651365
} else {
13661366
for (var i in data.admins) {
1367-
if (data.admins[i].name === oncall.data.user) {
1367+
// if team api managed and user is not superadmin then disable editing of team info
1368+
if (data.admins[i].name === oncall.data.user && !data.api_managed_roster) {
13681369
data.isAdmin = true;
13691370
}
13701371
}

src/oncall/ui/templates/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ <h4>
333333
<a href="https://{% endraw %}{{slack_instance}}{% raw %}.slack.com/messages/{{stripHash slack_channel_notifications}}/" target="_blank">{{slack_channel_notifications}}</a>
334334
{{/if}}
335335
</h4>
336+
<h4>
337+
{{#if api_managed_roster}}
338+
Managed team - this team is managed via API
339+
{{/if}}
340+
</h4>
336341
{% endraw %} {% endif %} {% raw %}
337342
</div>
338343
<div class="pull-right">

0 commit comments

Comments
 (0)