Commit graph

175 commits

Author SHA1 Message Date
Vadim Stepanov
b8d78fd6bb
Allow messaging backends to be enabled/disabled per organization (#1151)
# What this PR does
Allows messaging backends to be enabled/disabled per organization when
getting a list of available personal notification channels.

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [x] `CHANGELOG.md` updated
2023-01-18 15:52:25 +00:00
Matias Bordese
d3062b56fd
Draft initial logic for user/schedule paging (#1098)
Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2023-01-17 12:19:08 -03:00
Yulya Artyukhina
9129a720ef
Integration with grafana incident (#1081)
Check if Grafana Incident is enabled. If it is, add a button with a link
to declare Grafana Incident from Alert group in Slack and on Web.

Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
2023-01-17 13:04:50 +01:00
Tommy
5bd8fbdef8
Add alert groups state filter (#1133)
# What this PR does
This PR added a new parameter (state) into the alert_group public API to
filter the state of the alert groups

## Which issue(s) this PR fixes
https://github.com/grafana/oncall/issues/684

## Checklist

- [x] Tests updated
- [x] Documentation added
- [x] `CHANGELOG.md` updated

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2023-01-17 10:28:29 +00:00
Matias Bordese
0d38fe2a7f
Web schedules overrides are the higher priority level (#1115)
Related to https://github.com/grafana/oncall-private/issues/1550
2023-01-13 08:58:35 -03:00
Matias Bordese
abbb5a8381
Update schedules query not to defer ical fields used for on-call check (#1114)
Do not defer cached ical fields which are later needed for calculating
on-call users listed in the schedules list page.
2023-01-09 14:10:23 -03:00
Matias Bordese
87fad5eec1
Add select_related to fetch schedules user group information (#1109) 2023-01-09 13:15:27 -03:00
Vadim Stepanov
7a1f176cb5
Schedule score backend (#338)
This PR adds an endpoint returning a schedule quality score, overloaded
users and comments on the existing issues (e.g. balance issues or gaps).

## Limitations
- Since working hours editor is not implemented yet, there are only two
scores taken into account: balance score and a score representing the
ratio of time when someone is on-call to the whole time period.
- Time period is now set to be constant (90 days from today), so **in
some cases the results will be inaccurate** (when rotations don't align
with the time period)
- It only takes primary rotations into account (overrides are ignored)

## Usage
`GET /api/internal/v1/schedules/<pk>/quality?date=<TOMORROW_DATE>`

Note that `date` should be tomorrow date, because we can only be sure
about changing tomorrow's shifts (some of the shifts for current day
could be "deleted" but still show up in the UI).

## Example response
```json
{
  "total_score": 90,
  "comments": ["Schedule has no gaps", "Schedule is well-balanced, but still can be improved"],
  "overloaded_users": ["USSZ5WRH2CUA9", "U74XJZSSQGBIH"]
}
```

Issue: #118
2023-01-04 16:49:58 +00:00
Matias Bordese
374f32f489 Handle no start date when calculating by day ical shift events 2023-01-02 11:53:49 -03:00
Joey Orlando
5967d5af63
remove apns + fix django-push-notifications migrations (#984)
- removes APNS support
- changes the `django-push-notification` library from the `iskhakov`
fork to the [`grafana`
fork](https://github.com/grafana/django-push-notifications). This new
fork basically just patches an issue which affected the database
migrations of this django app (previously the library would not respect
the `USER_MODEL` setting when creating its tables and would instead
reference the `auth_user` table.. which we don't want)
- add `--no-cache` flag to the `make build` command

**NOTE**
A migration should be applied as follows:
```bash
# remove the four push_notifications tables, which have improper foreign key references
python manage.py migrate push_notifications zero

# recreate the tables with the proper foreign key references
python manage.py migrate
```
2022-12-13 13:00:59 +01:00
Matias Bordese
67ac47ff32 Update SCHEDULES_WRITE fallback role to EDITOR 2022-12-09 12:56:35 -03:00
Innokentii Konstantinov
7341641b3f
Introduce org uuid (#947)
* Introduce org uuid

* Rename uuid_with_org_id to uuid_with_org_uuid

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2022-12-06 22:42:58 +08:00
Joey Orlando
f8c8ceb2f6
only grant admins read/write access to public api keys (#952) 2022-12-06 13:02:53 +01:00
Joey Orlando
9a7b8acd5a
centralize timezone validation + add serializer validation for on call shifts and schedules (#924)
* Centralize timezone validation into one spot + add serializer validation
for schedules and oncall shifts (both public and internal API)

* add engine-manage make command
2022-12-01 14:13:39 +01:00
Joey Orlando
9e598385f4
Add RBAC Support (#777)
* Modify plugin.json to support RBAC role registration

* defines 26 new custom roles in plugin.json. The main roles are:

- Admin: read/write access to everything in OnCall
- Reader: read access to everything in OnCall
- OnCaller : read access to everything in OnCall + edit access to Alert Groups and Schedules
- <object-type> Editor: read/write access to everything related to <object-type>
- <object-type> Reader: read access for <object-type>
- User Settings Admin: read/write access to all user's settings, not just own settings. This is in comparison to User Settings Editor which can only read/write own settings

* update changelog and documentation (#686)

* implement RBAC for OnCall backend

This commit refactors backend authorization. It trys to use RBAC authorization if the org's grafana instance supports it, otherwise it falls back to basic role authorization.

* update RBAC backend tests

* add tests for RBAC changes
- run backend tests as matrix where RBAC is enabled/disabled. When RBAC is enabled, the permissions granted are read from the role grants in the frontend's plugin.json file (instead of relying what we specify in RBACPermission.Permissions)
- remove --reuse-db --nomigrations flags from engine/tox.ini
- minor autoformatting changes to docker-compose-developer.yml

* remove --ds=settings.ci-test from pytest CI command

DJANGO_SETTINGS_MODULE is already specified as an env var so this is just unecessary duplication

* update gitignore

* update github action job name for "test"

* RBAC frontend changes

* refactors the use of basic roles (ex. Viewer, Editor, Admin) use RBAC permissions (when supported), or falling back to basic roles when RBAC is not supported.

- updates the UserAction enum in grafana-plugin/src/state/userAction.ts. Previously this was hardcoded to a list of strings that were being returned by the OnCall API. Now the values here correspond to the permissions in plugin.json (plus a fallback role)

* changes per Gabriel's comments:
- get rid of group attribute in rbac roles
- remove displayName role attribute
- remove hidden role attribute
- add back role to includes section

* don't try to update user timezone if they don't have permission
2022-11-29 09:41:56 +01:00
Michael Derynck
3582f9b08f
Improve Jinja Template feedback and error handling (#884)
* Improve feedback so template errors are given to user

* Add security error logging

* Add limits for templates, payloads, results

* Show popup error notification for webhook errors and template errors that don't have a result

* Update tests

* Split exceptions into warnings/errors to give more control when previewing, rendering, saving templates

* Limit title lengths

* Make TypeError a warning

* Adjust title length limit

* Remove length limiting on urlize since it is being done on template render

* Fix tests

* Add KeyError and ValueError to warnings

* No longer enforcing json result when saving webhook in case it is dependent on payload

* Add tests for expected exceptions coming from apply_jinja_template

* Update changelog

* Send raw post if template result is not JSON
2022-11-28 09:46:51 -07:00
Vadim Stepanov
dc6fcf5c05
Add internal API fields for the mobile app (#910)
* add permalinks list to internal API alertgroup view

* add user's name and full avatar URL to the user view

* make avatar_full_url a property

* fix tests

* fix user connection criteria
2022-11-28 15:52:31 +00:00
Vadim Stepanov
54d14d1025
Move MobileAppAuthToken view to mobile_app (#902) 2022-11-28 12:50:58 +00:00
Innokentii Konstantinov
3b73522f5a
Fix saving source link template (#898)
* Add test for update integration templates

* Fix saving source link template
2022-11-24 16:26:12 +08:00
Vadim Stepanov
255964ceaf
Mobile app messaging backend (#874)
* move mobile notifications to a separate backend, remove critical notification

* remove outdated mobile app code

* MOBILE_APP_PUSH_NOTIFICATIONS_ENABLED -> FEATURE_MOBILE_APP_INTEGRATION_ENABLED

* create error log if no devices are set up

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* fix typing

* add GCMDevice todos

* add user connection capabilities

* add user connect/disconnect to the messaging backend

* move APNS endpoint to mobile_app Django app

* restore critical notifications

* support hackathon app

* tweak migrations so mobile app auth tokens are preserved

* reuse notify_by IDs

* use mobile app template to render push notification

* add GCM/FCM (Android) support

* fix unlink user

* logger.error -> logger.info
2022-11-23 15:56:43 +00:00
Joey Orlando
fd4877408a
remove grafana_plugin_management django app (#812)
* remove grafana_plugin_management django app

it seems to be no longer used or referenced. In addition apps.api.serializers.organization.PluginOrganizationSerializer was only
referenced from within grafana_plugin_management and is thereby safe
to remove.
2022-11-09 13:53:59 +01:00
Michael Derynck
fc78dd98da
Merge pull request #707 from grafana/add-region-to-organization
Add region info to organizations
2022-11-08 10:30:53 -07:00
Michael Derynck
f01d754851 Merge dev 2022-11-08 10:14:35 -07:00
Matias Bordese
a349d39f31 Enforce until on override shifts 2022-11-07 12:35:57 -03:00
Michael Derynck
25826690a8 Use common environment for templates 2022-11-05 00:31:51 -06:00
Maxim Mordasov
387b334d2a
Merge pull request #720 from grafana/matiasb/daily-shifts-by-day
Enable daily/by-day shifts option for web schedules
2022-11-04 14:23:09 +00:00
Michael Derynck
81702ba52d Merge dev 2022-11-03 12:42:36 -06:00
Michael Derynck
369a23551b Merge branch 'dev' into add-region-to-organization 2022-11-03 12:41:07 -06:00
Matias Bordese
b1a664df3b
Merge pull request #742 from grafana/matiasb/web-schedules-all-day-as-datetime
Update web schedule events to return all-day start/end as datetimes
2022-11-03 14:54:28 -03:00
Vadim Stepanov
e2456315af
Allow no-auth SMTP connection for email notifications (#759)
* DEFAULT_FROM_EMAIL -> EMAIL_FROM

* add EMAIL_FROM live setting

* EMAIL_FROM -> EMAIL_FROM_ADDRESS

* merge dev

* add test for get_from_email

* allow live settings to be null on internal API

* remove redundant tests
2022-11-03 16:18:37 +00:00
Matias Bordese
3e2d52ad51 Update web schedule events to return all-day as datetimes 2022-11-02 16:12:37 -03:00
Matias Bordese
98b187acd9 Add support for daily/by-day and custom interval 2022-11-02 16:12:16 -03:00
Matias Bordese
4bc3ed17a8 Make interval check more explicit 2022-11-02 16:12:16 -03:00
Matias Bordese
241283959a Enable daily/by-day shifts option for web schedules 2022-11-02 16:12:16 -03:00
Michael Derynck
a331a3f392 Rename to validate_settings 2022-11-01 18:24:44 -06:00
Michael Derynck
e019c70f67 Handle validation on update, remove redundant get_error call 2022-11-01 18:22:50 -06:00
Michael Derynck
2905423bad Merge dev 2022-11-01 17:56:03 -06:00
Matias Bordese
64570cc9fd Update schedules endpoint to filter by numeric type 2022-10-31 11:08:33 -03:00
Michael Derynck
cbde8cd680 Merge branch 'dev' into add-region-to-organization 2022-10-28 09:20:16 -06:00
Joey Orlando
5a4c3d6d77
remove POST /api/internal/v1/custom_buttons/{id}/action (#734)
* remove POST /api/internal/v1/custom_buttons/{id}/action
2022-10-28 10:44:37 +02:00
Michael Derynck
9d7c370752 Merge branch 'dev' into add-region-to-organization 2022-10-27 15:41:35 -06:00
Matias Bordese
565cb84bb1 Add optional type filter to internal schedules endpoint 2022-10-25 12:51:06 -03:00
Innokentii Konstantinov
2c6a27154f
Support mutliregion telegram (#676)
* Support mutliregion telegram

* Fix test_personal_message

* Fix tg verification code tests

* Simplify /start cmd handler

* Comment about link with org_id in tg msg
2022-10-25 14:53:07 +08:00
Michael Derynck
a3a0b22947 Merge branch 'dev' into add-region-to-organization 2022-10-24 09:14:30 -06:00
Matias Bordese
6439752949
Rewrite fallback condition for num escalation chains
Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
2022-10-20 12:57:59 -03:00
Matias Bordese
3d171f20f7 Defer large unused queryset fields when listing schedules 2022-10-19 17:07:06 -03:00
Matias Bordese
e4a7a5a23d Rework schedule escalation chains/policies count as a subquery 2022-10-19 17:07:06 -03:00
Michael Derynck
330f103844 Merge branch 'dev' into add-region-to-organization 2022-10-19 11:00:59 -06:00
Vadim Stepanov
e67d3519fe
Restore email notifications (#621)
* remove email verification related code

* remove email verification related code

* remove sendgrid callback

* remove sendgrid related code

* remove sendgrid related code

* rename sendgrid app to email

* remove email from built-in channels

* remove email from built-in channels

* remove email from built-in channels

* add email backend: https://github.com/grafana/oncall/pull/50

* add email templater

* add email templater

* convert md to html

* add email settings to live settings

* use task to send email, handle some exceptions to create logs

* remove ERROR_NOTIFICATION_MAIL_DELIVERY_FAILED usage

* add email limit logic

* fix tests

* add docs

* remove old email templates

* remove old email templates

* add template_fields to messaging backend

* add messaging backends templates to public api

* add comment for deprecated fields

* fix test

* fix tests

* disable email by default

* don't retry on SMTPException and TimeoutError

* add tests

* bring email back to public api docs

* return ERROR_NOTIFICATION_MAIL_LIMIT_EXCEEDED

* make template_fields tuple

* build_subject_and_title -> build_subject_and_message

* add one more comment about template deprecation

* use 8 as backend id

* add comment about gaierror and BadHeaderError

* add comment on importing in notify_user_async

* edit oss docs
2022-10-19 12:32:56 +01:00
Ben Sully
e36757b293
Allow non-JSON custom webhook templates, provided they render as valid JSON (#639)
* Allow non-JSON custom webhook templates, provided they render as valid JSON

Previously, both the provided template _and_ the rendered template had
to be valid JSON in order for validation to pass. This was unnecessarily
restrictive: really, only the rendered template needs to be valid JSON.
It also disallowed using templates such as:

    {
      "labels": {{ alert_payload.labels | tojson }}
    }

even though this would be valid JSON after rendering.

This commit relaxes the validation of custom webhook templates so that
they don't need to be valid JSON, provided that the rendered template
_is_ valid JSON. This is checked using a dummy dictionary of render
params, which use a constant string for the `alert_group_id` field
and a `defaultdict(dict)` for the `alert_payload` field. This should
permit templates like the one above, but still deny templates such as

    {
      "labels": {{ alert_payload.labels }}
    }

which would otherwise fail later if `labels` is not valid JSON.

This should resolve #638.

* Use defaultdict(str) instead of defaultdict(lambda: "")

* Add missing comment to resolution note validation code

* Update validation of resolution notes in public API, too

* Add extra test cases for JSON webhook templates endpoint of public API
2022-10-19 12:32:21 +01:00