Skip to content

Commit

Permalink
[MYSQL SCHEMA CHANGE] Add description text field to teams (#411)
Browse files Browse the repository at this point in the history
* allow editing info for api managed teams

* add a team description field [MYSQL SCHEMA CHANGE]

* modify tests [MYSQL SCHEMA CHANGE]
  • Loading branch information
diegocepedaw authored Dec 18, 2023
1 parent 0296952 commit c4b5990
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions db/schema.v0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ USE `oncall`;
CREATE TABLE IF NOT EXISTS `team` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`description` TEXT,
`slack_channel` VARCHAR(255),
`slack_channel_notifications` VARCHAR(255),
`email` VARCHAR(255),
Expand Down
4 changes: 2 additions & 2 deletions e2e/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_api_v0_get_team(team, role, roster, schedule):
team = re.json()
assert isinstance(team, dict)
expected_set = {'users', 'admins', 'services', 'rosters', 'name', 'id', 'slack_channel', 'slack_channel_notifications', 'email',
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'}
'scheduling_timezone', 'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster', 'description'}
assert expected_set == set(team.keys())

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


Expand Down
2 changes: 1 addition & 1 deletion src/oncall/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.5"
__version__ = "2.1.5"
9 changes: 5 additions & 4 deletions src/oncall/api/v0/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ...constants import TEAM_DELETED, TEAM_EDITED, SUPPORTED_TIMEZONES

# Columns which may be modified
cols = set(['name', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
cols = set(['name', 'description', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'])


Expand Down Expand Up @@ -58,7 +58,7 @@ def populate_team_rosters(cursor, team_dict):
def on_get(req, resp, team):
'''
Get team info by name. By default, only finds active teams. Allows selection of
fields, including: users, admins, services, and rosters. If no ``fields`` is
fields, including: users, admins, services, descriptions, and rosters. If no ``fields`` is
specified in the query string, it defaults to all fields.
**Example request**
Expand Down Expand Up @@ -86,6 +86,7 @@ def on_get(req, resp, team):
"id": 5501,
"iris_plan": null,
"name": "team-foo",
"description": "this is an important team!",
"rosters": {
"roster-foo": {
"id": 4186,
Expand Down Expand Up @@ -148,7 +149,7 @@ def on_get(req, resp, team):
connection = db.connect()
cursor = connection.cursor(db.DictCursor)
cursor.execute('''SELECT `id`, `name`, `email`, `slack_channel`, `slack_channel_notifications`,
`scheduling_timezone`, `iris_plan`, `iris_enabled`, `override_phone_number`, `api_managed_roster`
`scheduling_timezone`, `iris_plan`, `iris_enabled`, `override_phone_number`, `api_managed_roster`, `description`
FROM `team` WHERE `name`=%s AND `active` = %s''', (team, active))
results = cursor.fetchall()
if not results:
Expand All @@ -172,7 +173,7 @@ def on_get(req, resp, team):
@login_required
def on_put(req, resp, team):
'''
Edit a team's information. Allows edit of: 'name', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
Edit a team's information. Allows edit of: 'name', 'description', 'slack_channel', 'slack_channel_notifications', 'email', 'scheduling_timezone',
'iris_plan', 'iris_enabled', 'override_phone_number', 'api_managed_roster'
**Example request:**
Expand Down
7 changes: 4 additions & 3 deletions src/oncall/api/v0/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def on_post(req, resp):
raise HTTPBadRequest('invalid slack notifications channel',
'slack channel notifications name needs to start with #')
email = data.get('email')
description = data.get('description')
iris_plan = data.get('iris_plan')
iris_enabled = data.get('iris_enabled', False)
override_number = data.get('override_phone_number')
Expand All @@ -202,9 +203,9 @@ def on_post(req, resp):

try:
cursor.execute('''INSERT INTO `team` (`name`, `slack_channel`, `slack_channel_notifications`, `email`, `scheduling_timezone`,
`iris_plan`, `iris_enabled`, `override_phone_number`)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''',
(team_name, slack, slack_notifications, email, scheduling_timezone, iris_plan, iris_enabled, override_number))
`iris_plan`, `iris_enabled`, `override_phone_number`, `description`)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)''',
(team_name, slack, slack_notifications, email, scheduling_timezone, iris_plan, iris_enabled, override_number, description))

team_id = cursor.lastrowid
query = '''
Expand Down
5 changes: 5 additions & 0 deletions src/oncall/ui/static/js/oncall.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ var oncall = {
$cta = $modal.find('.modal-cta'),
name = $form.find('#team-name').val().trim(),
email = $form.find('#team-email').val(),
description = $form.find('#team-description').val(),
slack = $form.find('#team-slack').val(),
slack_notifications = $form.find('#team-slack-notifications').val(),
timezone = $form.find('#team-timezone').val(),
Expand Down Expand Up @@ -839,6 +840,7 @@ var oncall = {
$cta = $modal.find('.modal-cta'),
name = $form.find('#team-name').val(),
email = $form.find('#team-email').val(),
description = $form.find('#team-description').val(),
slack = $form.find('#team-slack').val(),
slack_notifications = $form.find('#team-slack-notifications').val(),
timezone = $form.find('#team-timezone').val(),
Expand Down Expand Up @@ -866,6 +868,7 @@ var oncall = {
blankModel = {
name: name,
email: email,
description: description,
slack_channel: slack,
slack_channel_notifications: slack_notifications,
scheduling_timezone: timezone,
Expand Down Expand Up @@ -3099,6 +3102,7 @@ var oncall = {
$teamSlack = $modalForm.find('#team-slack'),
$teamSlackNotifications = $modalForm.find('#team-slack-notifications'),
$teamTimezone = $modalForm.find('#team-timezone'),
$teamDescription = $modalForm.find('#team-description'),
$teamNumber = $modalForm.find('#team-override-phone'),
$teamIrisPlan = $modalForm.find('#team-irisplan'),
$teamIrisEnabled = $modalForm.find('#team-iris-enabled'),
Expand All @@ -3114,6 +3118,7 @@ var oncall = {
$teamEmail.val($btn.attr('data-modal-email'));
$teamSlack.val($btn.attr('data-modal-slack'));
$teamSlackNotifications.val($btn.attr('data-modal-slack-notifications'));
$teamDescription.val($btn.attr('data-modal-description'));
$teamNumber.val($btn.attr('data-modal-override-phone'));
$teamIrisPlan.val($btn.attr('data-modal-irisplan'));
$teamIrisEnabled.prop('checked', $btn.attr('data-modal-iris-enabled') === '1');
Expand Down
3 changes: 3 additions & 0 deletions src/oncall/ui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ <h4 class="modal-title"></h4>
{% endfor %}
</select>
</p>
<p>
<label for="team-description"> Team Description: </label> <input type="text" name="description" id="team-description" class="form-control" placeholder="Additional team info" />
</p>
<p class="advanced-toggle light">
Advanced
<i class="svg-icon svg-icon-chevron svg-icon-chevron-down settings-normal">
Expand Down
7 changes: 6 additions & 1 deletion src/oncall/ui/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ <h4><strong><a class="landing-teams-name" target="_blank" href="mailto:{{data.cu
<h3>
{{name}}
<span class="edit-team-name">
<i class="svg-icon svg-icon-pencil" data-toggle="modal" data-target="#team-edit-modal" data-modal-action="oncall.team.updateTeamName" data-modal-title="Update Team Info" data-modal-name="{{#if name}}{{name}}{{else}}{{@key}}{{/if}}" data-modal-email="{{email}}" data-modal-slack="{{slack_channel}}" data-modal-slack-notifications="{{slack_channel_notifications}}" data-modal-timezone="{{scheduling_timezone}}" data-modal-irisplan="{{iris_plan}}" data-modal-iris-enabled="{{iris_enabled}}" data-modal-override-phone="{{override_phone_number}}" info-admin-action="true">
<i class="svg-icon svg-icon-pencil" data-toggle="modal" data-target="#team-edit-modal" data-modal-action="oncall.team.updateTeamName" data-modal-title="Update Team Info" data-modal-name="{{#if name}}{{name}}{{else}}{{@key}}{{/if}}" data-modal-email="{{email}}" data-modal-slack="{{slack_channel}}" data-modal-slack-notifications="{{slack_channel_notifications}}" data-modal-timezone="{{scheduling_timezone}}" data-modal-description="{{description}}" data-modal-irisplan="{{iris_plan}}" data-modal-iris-enabled="{{iris_enabled}}" data-modal-override-phone="{{override_phone_number}}" info-admin-action="true">
<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 8 8" style="fill: currentColor">
<path d="M6 0l-1 1 2 2 1-1-2-2zm-2 2l-4 4v2h2l4-4-2-2z" />
</svg>
Expand Down Expand Up @@ -338,6 +338,11 @@ <h4>
{% endraw %} <div> {{team_managed_message|safe}} </div> {% raw %}
{{/if}}
</h4>

{{#if description}}
<span style="display: inline-block;"><h4 style="display: inline;">Description: </h4><p style="display: inline;" target="_blank">{{description}}</p></span>
{{else}}
{{/if}}
{% endraw %} {% endif %} {% raw %}
</div>
<div class="pull-right">
Expand Down

0 comments on commit c4b5990

Please sign in to comment.