Skip to content

Commit

Permalink
Added demo mode and fixed some frontend bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
arnulfojr committed Mar 14, 2016
1 parent 3eac390 commit 95aee63
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 49 deletions.
6 changes: 5 additions & 1 deletion CONFIG_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ it needs some security preparations.
- Install QCharts using composer ```composer install arnulfosolis/qcharts```
+ If you choose to add QCharts as a part of the project,
then go ahead and add the QCharts directory in the target project.
- Then, make sure to add the three QCharts Bundles in the target's AppKernel.
- Then, make sure to add the three QCharts Bundles in the target's ```AppKernel```.
+ ```QCharts\ApiBundle\ApiBundle```
+ ```QCharts\FrontendBundle\FrontendBundle```
+ ```QCharts\CoreBundle\CoreBundle```
Expand Down Expand Up @@ -81,11 +81,15 @@ core:
- super_admin: role that manages users and has access the snapshot console.
+ Tip: QCharts works better when the roles are organized in a hierarchical way.
+ Map the wished roles to use to give your users availability to use QCharts.
- QCharts comes with a demo option called ```allow_demo_users```, this option
allows ALL users to access the application in a ```user``` mode, without the possibility to add
Favorites.

```yml
#Full example of QChart's configurations
#QCharts
core:
allow_demo_users: False
urls:
redirects: #custom user information urls
login: /myLogin
Expand Down
8 changes: 5 additions & 3 deletions QCharts/ApiBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ static public function getNotValidCredentials()
* @param $authService
* @param array $roles
* @param $role
* @param bool $allow_demo_users
* @return bool
* @throws InvalidCredentialsException
*/
public static function checkCredentials($authService, array $roles, $role)
public static function checkCredentials($authService, array $roles, $role, $allow_demo_users = false)
{
/** @var AuthorizationChecker $authService */
if ($authService->isGranted($roles[$role]))
if ($authService->isGranted($roles[$role]) || $allow_demo_users)
{
return true;
}
Expand Down Expand Up @@ -510,8 +511,9 @@ public function getAction(Request $request)
$authChecker = $this->get('security.authorization_checker');
$queryService = $this->get('qcharts.query');
$roles = $this->getParameter('qcharts.user_roles');
$allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

if (!$authChecker->isGranted($roles["user"]))
if (!$authChecker->isGranted($roles["user"]) && !$allow_demo_users)
{
return $this->getCredentialsNotValid($roles["user"]);
}
Expand Down
10 changes: 8 additions & 2 deletions QCharts/ApiBundle/Controller/ApiDirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function registerAction(Request $request)
$formFactory = $this->get("form.factory");
$doctrine = $this->get("doctrine");
$directory = new Directory();
/** @var FormInterface $form */
$form = $formFactory->create(new DirectoryType($doctrine), $directory);
$form->submit($request->request->get($form->getName()));

Expand Down Expand Up @@ -295,7 +296,9 @@ public function getAction(Request $request)
{
$authChecker = $this->get("security.authorization_checker");
$roles = $this->getParameter('qcharts.user_roles');
if (!$authChecker->isGranted($roles["user"]))
$allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

if (!$authChecker->isGranted($roles["user"]) && !$allow_demo_users)
{
return new JsonResponse(ApiController::getNotValidCredentials());
}
Expand All @@ -307,11 +310,13 @@ public function getAction(Request $request)
$directoryService = $this->get("qcharts.directory.directory_service");
$tree = $directoryService->getDirectories($rootDirectory);
$serializer = $this->get("qcharts.serializer");

$responseData = [
"status" => 200,
"textStatus" => "Directories returned",
"directories" => $tree
];

$responseData = $serializer->serialize($responseData, 'json');
}
catch (NotFoundException $e)
Expand Down Expand Up @@ -363,8 +368,9 @@ public function queriesInDirectoryAction(Request $request)
$authChecker = $this->get("security.authorization_checker");
$roles = $this->getParameter("qcharts.user_roles");
$serializer = $this->get("qcharts.serializer");
$allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

if (!$authChecker->isGranted($roles["user"]))
if (!$authChecker->isGranted($roles["user"]) && !$allow_demo_users)
{
return new JsonResponse(ApiController::getNotValidCredentials());
}
Expand Down
9 changes: 6 additions & 3 deletions QCharts/ApiBundle/Controller/DatabaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use QCharts\CoreBundle\Exception\ParameterNotPassedException;
use QCharts\CoreBundle\Exception\SQLException;
use QCharts\CoreBundle\Exception\ValidationFailedException;
use QCharts\CoreBundle\Service\QueryService;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use QCharts\CoreBundle\Exception\NoTableNamesException;
use QCharts\CoreBundle\Exception\NotFoundException;
Expand Down Expand Up @@ -74,8 +75,9 @@ public function chartDataAction(Request $request)
$snapshotService = $this->get("qcharts.core.snapshot_service");

$roles = $this->getParameter('qcharts.user_roles');
$allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

if ($authChecker->isGranted($roles["user"]))
if ($authChecker->isGranted($roles["user"]) || $allow_demo_users)
{
$opts = [];
try
Expand Down Expand Up @@ -493,8 +495,9 @@ public function runAction(Request $request)

$roles = $this->getParameter('qcharts.user_roles');

if (!$authChecker->isGranted($roles["admin"])) {
return $this->getCredentialsNotValid();
if (!$authChecker->isGranted($roles["admin"]))
{
return new JsonResponse(ApiController::getNotValidCredentials());
}

$query = $request->request->get('query');
Expand Down
4 changes: 2 additions & 2 deletions QCharts/ApiBundle/Controller/FavoriteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function registerFavoriteAction(Request $request)

try
{
ApiController::checkCredentials($authService, $roles, "user");
ApiController::checkCredentials($authService, $roles, ApiController::USER);

$user = $this->getUser();
$queryId = $request->request->get("q", null);
Expand All @@ -117,7 +117,7 @@ public function registerFavoriteAction(Request $request)
{
$options = [
"status" => $e->getCode(),
"textStatus" => $e->getMessage()
"textStatus" => "To add to favorites valid credentials are required. {$e->getMessage()}"
];
}
catch (InstanceNotFoundException $e)
Expand Down
4 changes: 3 additions & 1 deletion QCharts/ApiBundle/Controller/UrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public function urlsAction()
//return the URLs for using the user admin
$roles = $this->getParameter('qcharts.user_roles');
$authChecker = $this->get("security.authorization_checker");
$allow_demo_users = $this->getParameter('qcharts.allow_demo_users');

try
{
ApiController::checkCredentials($authChecker, $roles, "user");
ApiController::checkCredentials($authChecker, $roles, ApiController::USER, $allow_demo_users);

$tableInfo = $this->generateUrl('qcharts.api.table_info');
$tablesUrl = $this->generateUrl('qcharts.api.tables');
Expand Down
2 changes: 1 addition & 1 deletion QCharts/ApiBundle/Exception/ExceptionMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class ExceptionMessage
{
static public function CREDENTIALS_NOT_VALID($role)
{
return "The given credentials were not valid, {$role} needed";
return "The given credentials were not valid, the role '{$role}' is needed";
}
}
4 changes: 4 additions & 0 deletions QCharts/CoreBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->booleanNode('allow_demo_users')
->defaultFalse()
->info('Allow access to anonymous visitors to access the application')
->end()
->end()
;

Expand Down
1 change: 1 addition & 0 deletions QCharts/CoreBundle/DependencyInjection/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('qcharts.user_roles', $config["roles"]);
$container->setParameter('qcharts.urls', $config["urls"]);
$container->setParameter('qcharts.variables', $config);
$container->setParameter('qcharts.allow_demo_users', $config["allow_demo_users"]);
}
}
3 changes: 2 additions & 1 deletion QCharts/FrontendBundle/Controller/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public function mainAction()
$authChecker = $this->get("security.authorization_checker");
$roles = $this->getParameter("qcharts.user_roles");
$urls = $this->getParameter("qcharts.urls");
$allow_demo_users = $this->getParameter("qcharts.allow_demo_users");

if ($authChecker->isGranted($roles["user"]))
if ($authChecker->isGranted($roles["user"]) || $allow_demo_users)
{
try
{
Expand Down
3 changes: 2 additions & 1 deletion QCharts/FrontendBundle/Controller/QueryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function showAction($queryId = null)
$authChecker = $this->get("security.authorization_checker");
$roles = $this->getParameter("qcharts.user_roles");
$urls = $this->getParameter("qcharts.urls");
$allow_demo_users = $this->getParameter("qcharts.allow_demo_users");

if (!$authChecker->isGranted($roles["user"]))
if (!$authChecker->isGranted($roles["user"]) && !$allow_demo_users)
{
return new RedirectResponse($urls["redirects"]["login"]);
}
Expand Down
30 changes: 24 additions & 6 deletions QCharts/FrontendBundle/Resources/public/js/favorite/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ FavoriteCommunicator.prototype.removeFavorite = function(q, callback) {
}
return;
}
store.modalController.popConnectionError();

var dataInfo = {
title: "While removing it from favorites...",
body: response["textStatus"],
footer: ""
};
store.modalController.init();
store.modalController.setModal(dataInfo);
store.modalController.setSmallModal();
store.modalController.pop();
}, function() {
//error
store.modalController.popConnectionError();
Expand Down Expand Up @@ -94,9 +103,18 @@ FavoriteCommunicator.prototype.addFavorite = function(q, callback) {
return;
}

store.modalController.popConnectionError();

}, function() {
var dataInfo = {
title: "While adding to favorites...",
body: response["textStatus"],
footer: ""
};
store.modalController.init();
store.modalController.setModal(dataInfo);
store.modalController.setSmallModal();
store.modalController.pop();

}, function(response) {
console.log(response);
store.modalController.popConnectionError();
});

Expand All @@ -121,9 +139,9 @@ FavoriteController.prototype.constructor = FavoriteController;

FavoriteController.prototype.initialize = function() {
var store = this;
console.log(this);
//console.log(this);
if (this.urls == undefined) {
console.log("not cahced urls");
//console.log("not cahced urls");
this.init(function() {
store.fetchFavorites(function(favorites) {
store.favorites = store.optimizeFavorites(favorites);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DirectoryFetcher.prototype.fetchContentFromDirectory = function(directoryId, cal
};

var data = this.getObject('get', this.urls["directory"]["base"], content);
console.log(data);
//console.log(data);
var store = this;

this.loadingIcon.setLoading(true);
Expand Down Expand Up @@ -80,7 +80,7 @@ DirectoryFetcher.prototype.fetchQueriesInDirectory = function(directoryId, callb

var data = this.getObject('get', this.urls["directory"]["query"], content);

console.log(data);
//console.log(data);
var store = this;

this.service(data).then(function(r) {
Expand Down Expand Up @@ -333,7 +333,7 @@ DirectoryController.prototype.filterObjects = function (content) {
* @param cellCallback
*/
DirectoryController.prototype.addObjects = function(content, cellCallback) {
console.log(content);
//console.log(content);
var store = this;

if (this.onlyTimeMachineFiles) {
Expand Down Expand Up @@ -362,10 +362,11 @@ DirectoryController.prototype.addObjects = function(content, cellCallback) {
var left = store.createColumn("col-xs-10");

left.addEventListener("click", function() {
if (cellCallback == undefined) {
if (cellCallback === undefined) {
window.location = redirectUrl;
} else {
cellCallback(elem);
}
cellCallback(elem);
});

var buttons = [{
Expand Down Expand Up @@ -400,7 +401,7 @@ DirectoryController.prototype.addObjects = function(content, cellCallback) {
//change the content from the right section!
var heart = store.createBeatingHeart(elem["id"], function() {
//clicked on the heart!
console.log("clicked");
//console.log("clicked");
var queryId = this.getAttribute("query-id");
store.favoriteController.removeFavorite(queryId, function() {
//update view
Expand Down Expand Up @@ -446,9 +447,9 @@ DirectoryController.prototype.setUp = function(response, animate) {
var content = response["directories"];

//set up the breadcrumbs
console.log("current folder on setup:" + this.currentDir);
//console.log("current folder on setup:" + this.currentDir);

console.log(response);
//console.log(response);
var store = this;

this.configuration["cache"] = content;
Expand All @@ -467,7 +468,7 @@ DirectoryController.prototype.setUp = function(response, animate) {
}
path.unshift({id:undefined, name:"."});
this.configuration["history"] = path;
console.log(this.configuration);
//console.log(this.configuration);
this.isInit = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SnapshotTableController.prototype.init = function() {

this.fetchUrls(function(urls) {
store.urls = urls;
console.log(urls);
//console.log(urls);
store.resultFetcher.url = urls["chart"];
store.fetchResults();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% endblock %}

{% block stylesheets %}
{% stylesheets '@FrontendBundle/Resources/public/css/table/*' %}
{% stylesheets '@FrontendBundle/Resources/public/css/vendor/dataTables/datatables.min.css' %}
<link rel="stylesheet" href="{{asset_url}}"/>
{% endstylesheets %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@
{% endblock %}

{% block stylesheets %}
{% stylesheets '@FrontendBundle/Resources/public/css/general/*' %}
<link rel="stylesheet" href="{{asset_url}}"/>
{% endstylesheets %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@
{% endblock %}

{% block stylesheets %}
{% stylesheets '@FrontendBundle/Resources/public/css/general/*' %}
<link rel="stylesheet" href="{{asset_url}}"/>
{% endstylesheets %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@
{% endblock %}

{% block stylesheets %}
{% stylesheets '@FrontendBundle/Resources/public/css/general/*' %}
<link rel="stylesheet" href="{{asset_url}}"/>
{% endstylesheets %}
{% endblock %}
Loading

0 comments on commit 95aee63

Please sign in to comment.