Mark VanLandingham 30fe9289b8 Allow groups to access queries (#36)
* [WIP] group ids saving on new reports

* Add groups to default queries, and added tab connector

* group_ids set to empty array for default queries

* group reports route (in & and) action

* [WIP] created group reports show route/controller

* Find correct query in show route

* Removed empty array for group_ids in query file

* Add report show view, where users can run queries

* Removed unneeded commas from queries.rb

* Allow non-admin group members to access reports

* query-result component dynamic download url based on location

* Removed accidental changes, and corrected tab size

* Group members can add params to queries

* Specs for new QueryController actions

* remove "Inlude query plan" from group reports

* Run prettier

* return and return -> return render

Co-Authored-By: Robin Ward <robin.ward@gmail.com>

* [WIP] changes from review

* Remove weird [-1] group_ids logic, for a simply check for [] in query update action

* Added integration tests for group report access

* Using guardian for securing endpoints, and much improved specs

* Update assets/javascripts/discourse/components/group-reports-nav-item.js.es6

Co-Authored-By: Robin Ward <robin.ward@gmail.com>
2019-09-11 10:09:41 -04:00

45 lines
1.3 KiB
JavaScript

import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { ajax } from "discourse/lib/ajax";
import {
default as computed,
observes
} from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend({
showResults: false,
explain: false,
loading: false,
results: Ember.computed.alias("model.results"),
hasParams: Ember.computed.gt("model.param_info.length", 0),
actions: {
run() {
this.setProperties({ loading: true, showResults: false });
ajax(`/g/${this.get("group.name")}/reports/${this.model.id}/run`, {
type: "POST",
data: {
params: JSON.stringify(this.model.params),
explain: this.explain
}
})
.then(result => {
this.set("results", result);
if (!result.success) {
return;
}
this.set("showResults", true);
})
.catch(err => {
if (err.jqXHR && err.jqXHR.status === 422 && err.jqXHR.responseJSON) {
this.set("results", err.jqXHR.responseJSON);
} else {
popupAjaxError(err);
}
})
.finally(() => this.set("loading", false));
}
}
});