Skip to content

Commit

Permalink
Merge pull request #1476 from getredash/v1fixes
Browse files Browse the repository at this point in the history
Multiple fixes from latest refactors
  • Loading branch information
arikfr authored Dec 20, 2016
2 parents 6f3ca1e + ee57a5b commit 94519d1
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 66 deletions.
6 changes: 2 additions & 4 deletions client/app/components/app-header/app-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="dropdown"
ng-show="$ctrl.showDashboardsMenu"
uib-dropdown>
<a href="#" class="dropdown-toggle" eib-dropdown-toggle title="Dashboards">
<li class="dropdown" ng-show="$ctrl.showDashboardsMenu" uib-dropdown>
<a href="#" class="dropdown-toggle" uib-dropdown-toggle title="Dashboards">
<span class="visible-md visible-lg">Dashboards <b class="caret"></b></span>
<span class="visible-xs visible-sm"><i class="zmdi zmdi-view-dashboard"></i> <b class="caret"></b></span>
</a>
Expand Down
4 changes: 4 additions & 0 deletions client/app/components/dynamic-table/dynamic-table.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
dynamic-table > div {
overflow: auto;
}

th.sortable-column {
cursor: pointer;
}
33 changes: 17 additions & 16 deletions client/app/components/dynamic-table/dynamic-table.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<table class="table table-condensed table-hover">
<thead>
<div>
<table class="table table-condensed table-hover">
<thead>
<tr>
<th ng-repeat="column in $ctrl.columns" ng-click="$ctrl.orderBy(column)" class="sortable-column">
{{column}} <span ng-if="$ctrl.sortIcon(column)"><i class="fa fa-sort-{{$ctrl.sortIcon(column)}}"></i></span>
</th>
</tr>

</thead>
<tbody>
</thead>
<tbody>
<tr ng-repeat="row in $ctrl.rows">
<td ng-repeat="column in $ctrl.columns">
{{row[column]}}
</td>
</tr>
</tbody>
</table>

</tbody>
</table>
</div>
<div class="text-center">
<ul uib-pagination total-items="$ctrl.rowsCount"
items-per-page="$ctrl.itemsPerPage"
ng-model="$ctrl.page"
max-size="6"
class="pagination"
boundary-link-numbers="true"
rotate="false"
next-text='>'
previous-text='<'
ng-change="$ctrl.pageChanged()"></ul>
items-per-page="$ctrl.itemsPerPage"
ng-model="$ctrl.page"
max-size="6"
class="pagination"
boundary-link-numbers="true"
rotate="false"
next-text='>'
previous-text='<'
ng-change="$ctrl.pageChanged()"></ul>
</div>
2 changes: 2 additions & 0 deletions client/app/pages/alert/alert-subscriptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { contains, without, compact } from 'underscore';
import template from './alert-subscriptions.html';

function controller($scope, $q, $sce, currentUser, AlertSubscription, Destination, toastr) {
'ngInject';

$scope.newSubscription = {};
$scope.subscribers = [];
$scope.destinations = [];
Expand Down
2 changes: 2 additions & 0 deletions client/app/pages/dashboards/add-widget-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const AddWidgetDialog = {
dismiss: '&',
},
controller($sce, toastr, Query, Widget) {
'ngInject';

this.dashboard = this.resolve.dashboard;
this.saveInProgress = false;
this.widgetSize = 1;
Expand Down
3 changes: 1 addition & 2 deletions client/app/pages/groups/data-sources.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { contains } from 'underscore';
import template from './data-sources.html';

function GroupDataSourcesCtrl($scope, $routeParams, $http, $location, toastr,
currentUser, Events, Group, DataSource) {
function GroupDataSourcesCtrl($scope, $routeParams, $http, Events, Group, DataSource) {
Events.record('view', 'group_data_sources', $scope.groupId);
$scope.group = Group.get({ id: $routeParams.groupId });
$scope.dataSources = Group.dataSources({ id: $routeParams.groupId });
Expand Down
2 changes: 2 additions & 0 deletions client/app/pages/groups/edit-group-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const EditGroupDialogComponent = {
dismiss: '&',
},
controller($location) {
'ngInject';

this.group = this.resolve.group;
const newGroup = this.group.id === undefined;

Expand Down
56 changes: 28 additions & 28 deletions client/app/pages/groups/group-name.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
const groupName = {
bindings: {
group: '<',
},
transclude: true,
template: `
<h2 class="p-l-5">
<edit-in-place editable="$ctrl.canEdit()" done="$ctrl.saveName" ignore-blanks='true' value="$ctrl.group.name"></edit-in-place>&nbsp;
<button class="btn btn-xs btn-danger" ng-if="$ctrl.canEdit()" ng-click="$ctrl.deleteGroup()">Delete this group</button>
</h2>
`,
replace: true,
controller($window, $location, toastr, currentUser) {
this.canEdit = () => currentUser.isAdmin && this.group.type !== 'builtin';
function controller($window, $location, toastr, currentUser) {
this.canEdit = () => currentUser.isAdmin && this.group.type !== 'builtin';

this.saveName = () => {
this.group.$save();
};
this.saveName = () => {
this.group.$save();
};

this.deleteGroup = () => {
if ($window.confirm('Are you sure you want to delete this group?')) {
this.group.$delete(() => {
$location.path('/groups').replace();
toastr.success('Group deleted successfully.');
});
}
};
},
};
this.deleteGroup = () => {
if ($window.confirm('Are you sure you want to delete this group?')) {
this.group.$delete(() => {
$location.path('/groups').replace();
toastr.success('Group deleted successfully.');
});
}
};
}

export default function (ngModule) {
ngModule.component('groupName', groupName);
ngModule.component('groupName', {
bindings: {
group: '<',
},
transclude: true,
template: `
<h2 class="p-l-5">
<edit-in-place editable="$ctrl.canEdit()" done="$ctrl.saveName" ignore-blanks='true' value="$ctrl.group.name"></edit-in-place>&nbsp;
<button class="btn btn-xs btn-danger" ng-if="$ctrl.canEdit()" ng-click="$ctrl.deleteGroup()">Delete this group</button>
</h2>
`,
replace: true,
controller,
});
}
2 changes: 1 addition & 1 deletion client/app/pages/groups/list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Paginator } from '../../utils';
import template from './list.html';

function GroupsCtrl($scope, $location, $uibModal, toastr, currentUser, Events, Group) {
function GroupsCtrl($scope, $uibModal, currentUser, Events, Group) {
Events.record('view', 'page', 'groups');
$scope.currentUser = currentUser;
$scope.groups = new Paginator([], { itemsPerPage: 20 });
Expand Down
3 changes: 1 addition & 2 deletions client/app/pages/groups/show.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { contains } from 'underscore';
import template from './show.html';

function GroupCtrl($scope, $routeParams, $http, $location, toastr,
currentUser, Events, Group, User) {
function GroupCtrl($scope, $routeParams, $http, currentUser, Events, Group, User) {
Events.record('view', 'group', $scope.groupId);

$scope.currentUser = currentUser;
Expand Down
2 changes: 2 additions & 0 deletions client/app/pages/queries/embed-code-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import template from './embed-code-dialog.html';

const EmbedCodeDialog = {
controller(clientConfig) {
'ngInject';

this.query = this.resolve.query;
this.visualization = this.resolve.visualization;

Expand Down
2 changes: 2 additions & 0 deletions client/app/visualizations/edit-visualization-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const EditVisualizationDialog = {
dismiss: '&',
},
controller($window, currentUser, Events, Visualization, toastr) {
'ngInject';

this.query = this.resolve.query;
this.queryResult = this.resolve.queryResult;
this.originalVisualization = this.resolve.visualization;
Expand Down
9 changes: 6 additions & 3 deletions redash/authentication/org_resolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@


def _get_current_org():
if 'org' in g:
return g.org

slug = request.view_args.get('org_slug', g.get('org_slug', 'default'))
org = Organization.get_by_slug(slug)
logging.debug("Current organization: %s (slug: %s)", org, slug)
return org
g.org = Organization.get_by_slug(slug)
logging.debug("Current organization: %s (slug: %s)", g.org, slug)
return g.org

# TODO: move to authentication
current_org = LocalProxy(_get_current_org)
2 changes: 1 addition & 1 deletion redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get(self):
class DashboardListResource(BaseResource):
@require_permission('list_dashboards')
def get(self):
results = models.Dashboard.all(self.current_org, self.current_user.group_ids, self.current_user)
results = models.Dashboard.all(self.current_org, self.current_user.group_ids, self.current_user.id)
return [q.to_dict() for q in results]

@require_permission('create_dashboard')
Expand Down
24 changes: 20 additions & 4 deletions redash/handlers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def post(self):
name = request.json['name']
group = models.Group(name=name, org=self.current_org)
models.db.session.add(group)
models.db.session.commit()

self.record_event({
'action': 'create',
Expand Down Expand Up @@ -77,6 +78,8 @@ def post(self, group_id):
group = models.Group.get_by_id_and_org(group_id, self.current_org)
user.group_ids.append(group.id)

models.db.session.commit()

self.record_event({
'action': 'add_member',
'timestamp': int(time.time()),
Expand All @@ -102,6 +105,8 @@ def delete(self, group_id, user_id):
user = models.User.get_by_id_and_org(user_id, self.current_org)
user.group_ids.remove(int(group_id))

models.db.session.commit()

self.record_event({
'action': 'remove_member',
'timestamp': int(time.time()),
Expand All @@ -111,14 +116,22 @@ def delete(self, group_id, user_id):
})


def serialize_data_source_with_group(data_source, data_source_group):
d = data_source.to_dict()
d['view_only'] = data_source_group.view_only
return d


class GroupDataSourceListResource(BaseResource):
@require_admin
def post(self, group_id):
data_source_id = request.json['data_source_id']
data_source = models.DataSource.get_by_id_and_org(data_source_id, self.current_org)
group = models.Group.get_by_id_and_org(group_id, self.current_org)

data_source.add_group(group)
data_source_group = data_source.add_group(group)

models.db.session.commit()

self.record_event({
'action': 'add_data_source',
Expand All @@ -128,12 +141,13 @@ def post(self, group_id):
'member_id': data_source.id
})

return data_source.to_dict(with_permissions_for=group)
return serialize_data_source_with_group(data_source, data_source_group)

@require_admin
def get(self, group_id):
group = get_object_or_404(models.Group.get_by_id_and_org, group_id,
self.current_org)

# TOOD: move to models
data_sources = (models.DataSource.query
.join(models.DataSourceGroup)
Expand All @@ -149,7 +163,9 @@ def post(self, group_id, data_source_id):
group = models.Group.get_by_id_and_org(group_id, self.current_org)
view_only = request.json['view_only']

data_source.update_group_permission(group, view_only)
data_source_group = data_source.update_group_permission(group, view_only)

models.db.session.commit()

self.record_event({
'action': 'change_data_source_permission',
Expand All @@ -160,7 +176,7 @@ def post(self, group_id, data_source_id):
'view_only': view_only
})

return data_source.to_dict(with_permissions_for=group)
return serialize_data_source_with_group(data_source, data_source_group)

@require_admin
def delete(self, group_id, data_source_id):
Expand Down
1 change: 1 addition & 0 deletions redash/handlers/query_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def delete(self, snippet_id):
snippet_id, self.current_org)
require_admin_or_owner(snippet.user.id)
models.db.session.delete(snippet)
models.db.session.commit()

self.record_event({
'action': 'delete',
Expand Down
1 change: 1 addition & 0 deletions redash/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def post(self, user_id):

try:
self.update_model(user, params)
# TODO: this won't be triggered at this point. Need to call db.session.commit?
except IntegrityError as e:
if "email" in e.message:
message = "Email already taken."
Expand Down
Loading

0 comments on commit 94519d1

Please sign in to comment.