Skip to content

Commit

Permalink
Don't change backend
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko committed Feb 21, 2019
1 parent 92c57e9 commit 18c2d2b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions client/app/components/items-list/classes/ItemsFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class PlainListFetcher extends ItemsFetcher {
return {
results: paginator.getItemsForPage(this._allItems),
count: this._allItems.length,
allResults: this._allItems,
};
}

Expand All @@ -59,6 +60,7 @@ export class PlainListFetcher extends ItemsFetcher {
return Promise.resolve({
results: paginator.getItemsForPage(this._allItems),
count: this._allItems.length,
allResults: this._allItems,
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion client/app/components/items-list/classes/ItemsSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export class ItemsSource {
const context = this.getCallbackContext();
return this._beforeUpdate().then(() => (
this._fetcher.fetch(changes, state, context)
.then(({ results, count }) => {
.then(({ results, count, allResults }) => {
this._pageItems = results;
this._allItems = allResults || null;
this._paginator.setTotalCount(count);
return this._afterUpdate();
})
Expand Down Expand Up @@ -76,6 +77,7 @@ export class ItemsSource {
selectedTags: this._selectedTags,
totalCount: this._paginator.totalCount,
pageItems: this._pageItems,
allItems: this._allItems,
};
}

Expand Down
5 changes: 3 additions & 2 deletions client/app/pages/groups/GroupDataSources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class GroupDataSources extends React.Component {
});

addDataSources = () => {
const allDataSources = DataSource.query({ include_groups: true }).$promise;
const allDataSources = DataSource.query().$promise;
const alreadyAddedDataSources = map(this.props.controller.allItems, ds => ds.id);
SelectItemsDialog.showModal({
dialogTitle: 'Add Data Sources',
inputPlaceholder: 'Search data sources...',
Expand All @@ -134,7 +135,7 @@ class GroupDataSources extends React.Component {
return allDataSources.then(items => filter(items, ds => ds.name.toLowerCase().includes(searchTerm)));
},
renderItem: (item, { isSelected }) => {
const alreadyInGroup = includes(item.groups, this.groupId);
const alreadyInGroup = includes(alreadyAddedDataSources, item.id);
return {
content: (
<DataSourcePreviewCard dataSource={item}>
Expand Down
5 changes: 3 additions & 2 deletions client/app/pages/groups/GroupMembers.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { some, map } from 'lodash';
import { includes, map } from 'lodash';
import React from 'react';
import { react2angular } from 'react2angular';
import Button from 'antd/lib/button';
Expand Down Expand Up @@ -93,13 +93,14 @@ class GroupMembers extends React.Component {
onTableRowClick = (event, item) => navigateTo('users/' + item.id);

addMembers = () => {
const alreadyAddedUsers = map(this.props.controller.allItems, u => u.id);
SelectItemsDialog.showModal({
dialogTitle: 'Add Members',
inputPlaceholder: 'Search users...',
selectedItemsTitle: 'New Members',
searchItems: searchTerm => User.query({ q: searchTerm }).$promise.then(({ results }) => results),
renderItem: (item, { isSelected }) => {
const alreadyInGroup = some(item.groups, g => g.id === this.groupId);
const alreadyInGroup = includes(alreadyAddedUsers, item.id);
return {
content: (
<UserPreviewCard user={item}>
Expand Down
4 changes: 1 addition & 3 deletions redash/handlers/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ def get(self):
else:
data_sources = models.DataSource.all(self.current_org, group_ids=self.current_user.group_ids)

include_groups = request.args.get('include_groups', None) is not None

response = {}
for ds in data_sources:
if ds.id in response:
continue

try:
d = ds.to_dict(include_groups=include_groups)
d = ds.to_dict()
d['view_only'] = all(project(ds.groups, self.current_user.group_ids).values())
response[ds.id] = d
except AttributeError:
Expand Down
5 changes: 1 addition & 4 deletions redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DataSource(BelongsToOrgMixin, db.Model):
def __eq__(self, other):
return self.id == other.id

def to_dict(self, all=False, with_permissions_for=None, include_groups=False):
def to_dict(self, all=False, with_permissions_for=None):
d = {
'id': self.id,
'name': self.name,
Expand All @@ -109,9 +109,6 @@ def to_dict(self, all=False, with_permissions_for=None, include_groups=False):
DataSourceGroup.group == with_permissions_for,
DataSourceGroup.data_source == self).one()[0]

if include_groups:
d['groups'] = [g.group_id for g in self.data_source_groups]

return d

def __str__(self):
Expand Down

0 comments on commit 18c2d2b

Please sign in to comment.