Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk committed May 2, 2024
1 parent 41e6cb6 commit 80dab5a
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 236 deletions.
26 changes: 13 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ botocore = "1.31.8"
cassandra-driver = "3.21.0"
certifi = ">=2019.9.11"
cmem-cmempy = "21.2.3"
databend-driver = "0.12.5"
databend-sqlalchemy = "0.4.4"
databend-driver = "0.17.1"
databend-sqlalchemy = "0.4.6"
google-api-python-client = "1.7.11"
gspread = "5.11.2"
impyla = "0.16.0"
Expand Down
1 change: 0 additions & 1 deletion redash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def create_app():
from redash.metrics import request as request_metrics
from redash.models import db, users
from redash.utils import sentry
from redash.version_check import reset_new_version_status

from . import (
limiter,
Expand Down
8 changes: 2 additions & 6 deletions redash/cli/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,9 @@ def delete(email, organization=None):
if organization:
org = models.Organization.get_by_slug(organization)
deleted_users_query = deleted_users_query.where(models.User.org == org)

Check warning on line 208 in redash/cli/users.py

View check run for this annotation

Codecov / codecov/patch

redash/cli/users.py#L208

Added line #L208 was not covered by tests
deleted_count = len(
models.db.session.scalars(
deleted_users_query.returning(models.User.id).execution_options(synchronize_session=False)
).all()
)
result = models.db.session.execute(deleted_users_query.execution_options(synchronize_session=False))
models.db.session.commit()
print("Deleted %d users." % deleted_count)
print("Deleted %d users." % result.rowcount)


@manager.command()
Expand Down
2 changes: 1 addition & 1 deletion redash/destinations/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def notify(self, alert, query, user, new_state, app, host, metadata, options):
]
if alert.custom_body:
fields.append({"name": "Description", "value": alert.custom_body})
if new_state == Alert.TRIGGERED_STATE:
if new_state == Alerts.TRIGGERED_STATE:
if alert.options.get("custom_subject"):
text = alert.options["custom_subject"]
else:
Expand Down
33 changes: 16 additions & 17 deletions redash/handlers/organization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from flask_login import current_user, login_required
from sqlalchemy import distinct, func
from sqlalchemy.sql.expression import select

from redash import models
from redash.authentication import current_org
Expand All @@ -12,34 +11,34 @@
@login_required
def organization_status(org_slug=None):
counters = {
"users": models.db.session.execute(
models.User.all(current_org, columns=[func.count(models.User.id)])
).first()[0],
"alerts": models.db.session.execute(
models.Alert.all(
group_ids=current_user.group_ids, columns=[func.count(models.Alert.id)], distinct=[]
)
).first()[0],
"data_sources": models.db.session.execute(
"users": models.db.session.scalar(models.User.all(current_org, columns=[func.count(models.User.id)])),
"alerts": models.db.session.scalar(
models.Alert.all(group_ids=current_user.group_ids, columns=[func.count(models.Alert.id)], distinct=[])
),
"data_sources": models.db.session.scalar(
models.DataSource.all(
current_org,
group_ids=current_user.group_ids,
columns=[func.count(models.DataSource.id)],
)
).first()[0],
"queries": models.db.session.execute(
),
"queries": models.db.session.scalar(
models.Query.all(
current_user.group_ids,
user_id=current_user.id,
include_drafts=True,
columns=[func.count(distinct(models.Query.id))],
)
).first()[0],
"dashboards": models.db.session.execute(
select(func.count(models.Dashboard.id)).where(
models.Dashboard.org == current_org, models.Dashboard.is_archived.is_(False)
),
"dashboards": models.db.session.scalar(
models.Dashboard.all(
current_org,
[],
None,
columns=[func.count(distinct(models.Dashboard.id))],
distinct=[],
)
).first()[0],
),
}

return json_response(dict(object_counters=counters))
27 changes: 24 additions & 3 deletions redash/handlers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ def get(self):
page = request.args.get("page", 1, type=int)
per_page = request.args.get("per_page", 25, type=int)

results = paginate(ordered_results, page=page, per_page=per_page, serializer=QuerySerializer)
results = paginate(
ordered_results,
page=page,
per_page=per_page,
serializer=QuerySerializer,
with_stats=True,
with_last_modified_by=False,
)

if search_term:
self.record_event({"action": "search", "object_type": "query", "term": search_term})
Expand Down Expand Up @@ -290,7 +297,14 @@ def get(self):

page = request.args.get("page", 1, type=int)
per_page = request.args.get("per_page", 25, type=int)

Check warning on line 299 in redash/handlers/queries.py

View check run for this annotation

Codecov / codecov/patch

redash/handlers/queries.py#L299

Added line #L299 was not covered by tests
return paginate(ordered_results, page=page, per_page=per_page, serializer=QuerySerializer)
return paginate(
ordered_results,
page=page,
per_page=per_page,
serializer=QuerySerializer,
with_stats=True,
with_last_modified_by=False,
)


class QueryResource(BaseResource):
Expand Down Expand Up @@ -483,7 +497,14 @@ def get(self):

page = request.args.get("page", 1, type=int)
per_page = request.args.get("per_page", 25, type=int)
results = paginate(ordered_favorites, page=page, per_page=per_page, serializer=QuerySerializer)
results = paginate(
ordered_favorites,
page=page,
per_page=per_page,
serializer=QuerySerializer,
with_stats=True,
with_last_modified_by=False,
)

self.record_event(
{
Expand Down
10 changes: 5 additions & 5 deletions redash/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask_login import current_user, login_user
from flask_restful import abort
from funcy import partial, project
from sqlalchemy import asc, desc
from sqlalchemy import desc
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

Expand Down Expand Up @@ -32,13 +32,13 @@

# Ordering map for relationships
order_map = {
"name": [asc(models.User.name)],
"name": [models.User.name],
"-name": [desc(models.User.name)],
"active_at": [asc(models.User.active_at)],
"active_at": [models.User.active_at],
"-active_at": [desc(models.User.active_at)],
"created_at": [asc(models.User.created_at)],
"created_at": [models.User.created_at],
"-created_at": [desc(models.User.created_at)],
"groups": [asc(models.User.group_ids)],
"groups": [models.User.group_ids],
"-groups": [desc(models.User.group_ids)],
}

Expand Down

0 comments on commit 80dab5a

Please sign in to comment.