Skip to content

Commit

Permalink
fix(3093) Return timezone field of the user via public API (grafana#3311
Browse files Browse the repository at this point in the history
)

# What this PR does
Return the `timezone` field for the users GET API call
## Which issue(s) this PR fixes

Closes grafana#3093 

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Joey Orlando <[email protected]>
  • Loading branch information
ravishankar15 and joeyorlando authored Nov 10, 2023
1 parent f5d75f3 commit 152b1b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added user timezone field to the users public API response ([#3311](https://github.com/grafana/oncall/pull/3311))

## v1.3.57 (2023-11-10)

### Fixed
Expand Down
7 changes: 5 additions & 2 deletions docs/sources/oncall-api-reference/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ The above command returns JSON structured in the following way:
}
],
"username": "alex",
"role": "admin"
"role": "admin",
"timezone": "UTC"
}
```

Expand All @@ -45,6 +46,7 @@ Use `{{API_URL}}/api/v1/users/current` to retrieve the current user.
| `slack` | Yes/org | List of user IDs from connected Slack. User linking key is e-mail. |
| `username` | Yes/org | User username |
| `role` | No | One of: `user`, `observer`, `admin`. |
| `timezone` | No | timezone of the user one of [time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). |

# List Users

Expand Down Expand Up @@ -73,7 +75,8 @@ The above command returns JSON structured in the following way:
}
],
"username": "alex",
"role": "admin"
"role": "admin",
"timezone": "UTC"
}
],
"current_page_number": 1,
Expand Down
3 changes: 2 additions & 1 deletion engine/apps/public_api/serializers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class UserSerializer(serializers.ModelSerializer, EagerLoadingMixin):

class Meta:
model = User
fields = ["id", "email", "slack", "username", "role", "is_phone_number_verified"]
fields = ["id", "email", "slack", "username", "role", "is_phone_number_verified", "timezone"]
read_only_fields = ["timezone"]

@staticmethod
def get_role(obj):
Expand Down
3 changes: 3 additions & 0 deletions engine/apps/public_api/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_get_user(
"username": user.username,
"role": "admin",
"is_phone_number_verified": False,
"timezone": user.timezone,
}

assert response.status_code == status.HTTP_200_OK
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_get_users_list(
"username": user_1.username,
"role": "admin",
"is_phone_number_verified": False,
"timezone": user_1.timezone,
},
{
"id": user_2.public_primary_key,
Expand All @@ -80,6 +82,7 @@ def test_get_users_list(
"username": user_2.username,
"role": "admin",
"is_phone_number_verified": False,
"timezone": user_2.timezone,
},
],
"current_page_number": 1,
Expand Down

0 comments on commit 152b1b1

Please sign in to comment.