Skip to content

Commit

Permalink
Revise Query.by_user method
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr committed Jan 25, 2017
1 parent 84e1ac8 commit 7e43e54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion redash/handlers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get(self):
class MyQueriesResource(BaseResource):
@require_permission('view_query')
def get(self):
results = models.Query.by_user(self.current_user, self.current_user.id)
results = models.Query.by_user(self.current_user)
page = request.args.get('page', 1, type=int)
page_size = request.args.get('page_size', 25, type=int)
return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
Expand Down
4 changes: 2 additions & 2 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ def all_queries(cls, group_ids, user_id=None, drafts=False):
return q

@classmethod
def by_user(cls, user, drafts):
return cls.all_queries(user.group_ids, drafts).filter(Query.user == user)
def by_user(cls, user):
return cls.all_queries(user.group_ids, user.id).filter(Query.user == user)

@classmethod
def outdated_queries(cls):
Expand Down
14 changes: 7 additions & 7 deletions tests/models/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ def test_returns_only_users_queries(self):
q = self.factory.create_query(user=self.factory.user)
q2 = self.factory.create_query(user=self.factory.create_user())

queries = Query.by_user(self.factory.user, False)
queries = Query.by_user(self.factory.user)

# not using self.assertIn/NotIn because otherwise this fails :O
self.assertTrue(q in queries)
self.assertFalse(q2 in queries)
self.assertTrue(q in list(queries))
self.assertFalse(q2 in list(queries))

def test_returns_drafts_if_asked_to(self):
def test_returns_drafts_by_the_user(self):
q = self.factory.create_query(is_draft=True)
q2 = self.factory.create_query(is_draft=False)
q2 = self.factory.create_query(is_draft=True, user=self.factory.create_user())

queries = Query.by_user(self.factory.user, True)
queries = Query.by_user(self.factory.user)

# not using self.assertIn/NotIn because otherwise this fails :O
self.assertTrue(q in queries)
Expand All @@ -185,7 +185,7 @@ def test_returns_only_queries_from_groups_the_user_is_member_in(self):
q = self.factory.create_query()
q2 = self.factory.create_query(data_source=self.factory.create_data_source(group=self.factory.create_group()))

queries = Query.by_user(self.factory.user, False)
queries = Query.by_user(self.factory.user)

# not using self.assertIn/NotIn because otherwise this fails :O
self.assertTrue(q in queries)
Expand Down

0 comments on commit 7e43e54

Please sign in to comment.