Commit graph

34 commits

Author SHA1 Message Date
Vadim Stepanov
b2f4ffb98a
apps.get_model -> import (#2619)
# What this PR does

Remove
[`apps.get_model`](https://docs.djangoproject.com/en/3.2/ref/applications/#django.apps.apps.get_model)
invocations and use inline `import` statements in places where models
are imported within functions/methods to avoid circular imports.

I believe `import` statements are more appropriate for most use cases as
they allow for better static code analysis & formatting, and solve the
issue of circular imports without being unnecessarily dynamic as
`apps.get_model`. With `import` statements, it's possible to:

- Jump to model definitions in most IDEs
- Automatically sort inline imports with `isort`
- Find import errors faster/easier (most IDEs highlight broken imports)
- Have more consistency across regular & inline imports when importing
models

This PR also adds a flake8 rule to ban imports of `django.apps.apps`, so
it's harder to use `apps.get_model` by mistake (it's possible to ignore
this rule by using `# noqa: I251`). The rule is not enforced on
directories with migration files, because `apps.get_model` is often used
to get a historical state of a model, which is useful when writing
migrations ([see this SO answer for more
details](https://stackoverflow.com/a/37769213)). So `apps.get_model` is
considered OK in migrations (even necessary in some cases).

## 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)
2023-07-25 09:43:23 +00:00
Joey Orlando
9cc74e5b67
remove references to AlertGroup.is_archived and AlertGroup.unarchived_objects (#2524)
# What this PR does

This is a follow up to #2502 which started to remove logic to
"archiving" alert groups. This PR:
- removes all references to `AlertGroup.is_archived` and marks the
column as deprecated. We will remove it in the next release
- removes the `AlertGroup.unarchived_objects` `Manager`
- renames the `AlertGroup.all_objects` `Manager` to `AlertGroup.objects`

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] 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)
2023-07-18 11:48:34 +00:00
Joey Orlando
01b1be85af
fix mypy return errors (#2408)
# What this PR does

Fix the following `return` `mypy` errors (related to #2392):

```bash
❯ mypy .
apps/telegram/updates/update_manager.py:36: error: Missing return statement  [return]
apps/slack/scenarios/step_mixins.py:109: error: Missing return statement  [return]
apps/mobile_app/tasks.py:368: error: Missing return statement  [return]
apps/telegram/updates/update_handlers/button_press.py:48: error: Missing return statement  [return]
apps/twilioapp/phone_provider.py:28: error: Missing return statement  [return]
apps/twilioapp/phone_provider.py:61: error: Missing return statement  [return]
Found 6 errors in 5 files (checked 595 source files)
```

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-07-05 11:36:59 +00:00
Joey Orlando
cc20c9dfdd
re-enable mypy GitHub Actions CI job (#2390)
# What this PR does

```bash
❯ mypy .
Success: no issues found in 595 source files
```

- re-enable the mypy CI check
- fixes all `django-manager-missing` mypy errors
- disable all other rules currently giving mypy errors
- changing the approach here. rather than enforcing that backend
contributors fix >= 1 `mypy` error on their PR, lets simply disable all
the rules that're currently returning errors and slowly re-enable these
one at a time #2392

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required) (N/A)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (N/A)
2023-06-29 14:01:52 +00:00
Joey Orlando
75028d0427
continue addressing mypy violations (#2170)
# What this PR does

See #2173 

Also, closes #2187 . All of the new files under `type_stubs/icalendar`
were autogenerated by running:

```bash
stubgen -p icalendar -o type_stubs
```

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-06-27 10:23:08 +00:00
Joey Orlando
9dde1805aa
add mypy static type checker to backend codebase (#2151)
# What this PR does

- Adds [`mypy` static type checking](https://mypy-lang.org/) to our CI
pipeline. Currently there is still a **ton** of errors being returned by
the tool, as we'll need to fix pre-existing errors. I think we can
slowly chip away at these errors in small PRs, doing them all in one
large PR is likely very risky.
- Also, this PR starts chipping away at one of the main type errors that
we have which is accessing the `datetime` class (from the `datetime`
library) or `timedelta` function on the `django.utils.timezone` module.
Basically we should be instead accessing these two objects from the
native `datetime` module. This makes sense because the [`__all__`
attribute](https://github.com/django/django/blob/main/django/utils/timezone.py#L14-L30)
in `django.utils.timezone` does not re-export `datetime` or `timedelta`.
- splits `engine` dependencies out into `requirements.txt` and
`requirements-dev.txt`

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required) (N/A)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (N/A)
2023-06-12 12:50:33 -04:00
Vadim Stepanov
3d7c044193
Fix Telegram ratelimit on live setting change (#2100)
# What this PR does

Fixes https://github.com/grafana/oncall/issues/1103, inspired by
https://github.com/grafana/oncall/pull/1934.

Makes sure that:
1. `LiveSettings.validate_settings` is only called once per update
request and not called for any individual LiveSetting instance save.
2. `telegram.Bot.set_webhook` is only called once per request when
changing `TELEGRAM_WEBHOOK_HOST`.


## Which issue(s) this PR fixes

https://github.com/grafana/oncall/issues/1103

## 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)
2023-06-06 15:18:12 +00:00
Vadim Stepanov
53d34164ef
Fix SQLite permission issue (#1984)
# What this PR does
Fixes https://github.com/grafana/oncall/issues/1960.

## 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)
2023-05-22 19:16:31 +00:00
Joey Orlando
4967ce8208
update web UI, Slack, and Telegram to allow silencing an acknowledged alert group (#1831)
# What this PR does

https://www.loom.com/share/1a6ef0d00c3b46ca80c120579d512dcc

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [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)
2023-04-27 14:52:35 +00:00
Innokentii Konstantinov
c68fdf5681
Fix insight_logs exceptions (#1757)
Most of the PR is just renaming ChatOpsType to ChatOpsPlug, core changes
are linked below:

- Fix insight_logs error writing unlink_backend error
https://github.com/grafana/oncall/pull/1757/files#diff-7ae187be84e55ebac962bad0984f7569186cdc83c896132b2ebcbcbb31bbf5dd
- Fix insight_logs error writing updated schedule with installed slack
integration
(https://github.com/grafana/oncall/pull/1757/files#diff-4037b7bbef9fc16d9b541beb3ed46f760916d7cd720847c3123adf7afb5ab4b4L690)
2023-04-17 07:16:18 +00:00
Innokentii Konstantinov
a50ec8fed2
Refactor get_user_verbal_for_team_for_slack. (#809)
Remove unused params from signature, rename
2023-03-07 10:09:37 +00:00
Ildar Iskhakov
1b7ada4315
Add database migrations linter (#1020)
# What this PR does

This PR adds
[django-migration-linter](https://github.com/3YOURMIND/django-migration-linter)
to keep database migrations
 backwards compatible

- we can automatically run migrations and they are zero-downtime, e.g.
old code can work with the migrated database
 - we can run and rollback migrations without worrying about data safety
- OnCall is deployed to the multiple environments core team is not able
to control

See [django-migration-linter
checklist](https://github.com/3YOURMIND/django-migration-linter/blob/main/docs/incompatibilities.md)
for the common mistakes and best practices


## Which issue(s) this PR fixes

## Checklist

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

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2023-02-06 16:01:37 +08:00
Vadim Stepanov
a1e4f72280
remove send_link_to_channel_message_or_fallback_to_full_incident 2023-01-06 11:34:11 +00:00
Joey Orlando
802e3964e9
update mobile app push notification text + make telegram alert verbage consistent ("Firing" instead of "Alerting") (#1089) 2023-01-05 16:16:43 +01:00
Vadim Stepanov
0d4701bd81
Change wording from "incident" to "alert group" in the Telegram app (#1052)
# What this PR does
Makes Telegram integration consistent with the rest of the system so it
uses the word "alert group" instead of "incident" when referring to
alert groups.

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [x] `CHANGELOG.md` updated
2023-01-04 17:44:01 +00:00
Ildar Iskhakov
282e58db7b
Don't render logs for too big telegram dm (#1051)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated
2022-12-29 13:22:15 +00:00
Innokentii Konstantinov
28dedcd109
Shorten telegram callback data (#959)
Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2022-12-07 23:54:29 +08: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
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
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
c3b054ae61 Retry on exception first 5 times 2022-09-02 15:03:08 -06:00
Michael Derynck
0ef2cbf77b Fix message typo 2022-09-01 11:41:52 -06:00
Michael Derynck
50dc7d6240 Handle a exceptions on some retrying tasks 2022-09-01 11:39:47 -06:00
Innokentii Konstantinov
434fe17617
user_id -> linked_user_id (#410) 2022-08-25 13:34:19 +05:00
Vadim Stepanov
eba799abb4
Handle Telegram BadRequest (#404) 2022-08-24 15:35:01 +01:00
Innokentii Konstantinov
4765c9b07c
Insight logs (#348)
* Entity events insight logs

* Insight logging

* Fix event for updating templates

* Format fixes

* Remove organization_log_type.py

* Simplify signature of chatops_insight_log

* insight logs formatting

* Add possibility to enable all insight logging via DynamicSetting

* Fixes

* Style fixes

* Add migration

* Fix migration
2022-08-24 12:04:44 +05:00
Matias Bordese
3c4ba80f5f
Merge pull request #397 from grafana/matiasb/user-already-linked-telegram-account
Handle user already linked to telegram account when verifying
2022-08-23 16:52:29 -03:00
Matias Bordese
5b6f4b2c54 Handle user already linked to telegram account when verifying 2022-08-23 14:59:10 -03:00
Vadim Stepanov
3cd9a81d7d
Add logging for Telegram BadRequest (#394) 2022-08-23 15:17:05 +01:00
Vadim Stepanov
8b553ce735
Validate Slack and Telegram host env variables (#307)
* Validate Slack and Telegram host env variables

* remove ImproperlyConfigured usage, improve Telegram creds handling

* update TELEGRAM_WEBHOOK_HOST description
2022-08-02 12:57:12 +03:00
Michael Derynck
ce8f4e53fa
Conform URLs (#281)
* Make any URLs build from env vars tolerant of path prefix, trailing/leading slashes

* Add comment

* Lint
2022-07-25 09:12:50 -06:00
Vadim Stepanov
c8964188e7
Allow Telegram DMs without channel connection (#142)
* allow posting DM messages to Telegram without connecting a channel

* fix get_channel_for_alert_group, add tests

* add docs on usage without channel connection
2022-06-28 09:11:19 +01:00
Michael Derynck
66e8cf2cbc
Merge dev to main (#54)
* Log (failed) attempt to notify a user with viewer role

* Remove https:// prefix from BASE_URL docker env var

* Fix cloud heartbeat name

* Polishing telegram

* Update docker-compose.yml

* Update plugin README  (#48)

* Update README and screenshot, remove plop for build info since version is now displayed prominently

* Sign build

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>

* Build actions (#38)

* Drone, github action changes

* Minor version updates

* Update frontend dependencies

* Re-enable unit test

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>

* Revert stylelint version (#52)

* Revert stylelint version

* Build plugin as well as lint

* Build in previous step

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>

* Update screenshot (#53)

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>

Co-authored-by: Matias Bordese <mbordese@gmail.com>
Co-authored-by: Matvey Kukuy <Matvey-Kuk@users.noreply.github.com>
Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: Matvey Kukuy <matvey@amixr.io>
Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
2022-06-13 16:39:58 -06:00
Michael Derynck
6b40f95033 World, meet OnCall!
Co-authored-by: Eve832 <eve.meelan@grafana.com>
    Co-authored-by: Francisco Montes de Oca <nevermind89x@gmail.com>
    Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com>
    Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
    Co-authored-by: Julia <ferril.darkdiver@gmail.com>
    Co-authored-by: maskin25 <kengurek@gmail.com>
    Co-authored-by: Matias Bordese <mbordese@gmail.com>
    Co-authored-by: Matvey Kukuy <motakuk@gmail.com>
    Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
    Co-authored-by: Richard Hartmann <richih@richih.org>
    Co-authored-by: Robby Milo <robbymilo@fastmail.com>
    Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
    Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
    Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
2022-06-03 08:09:47 -06:00