Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.
Prev Previous commit
Next Next commit
Basic CREATE POLICY builder modal accessible on security policies page.
  • Loading branch information
robsoto committed May 26, 2017
commit 2dbaf59b0551cdedffcf50d2ea01009478ff2a3d
28 changes: 26 additions & 2 deletions src/apps/dataq/client_src/js/dataq.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Defines the DataQ.DQ object, which is what the user of the library will interact with.
*
* Simply call DataQ.DQ(repo_name, callback) and DataQ will launch. After the user builds a query,
* the callback is executed as callback(query), where query is a String representing the SQL query
* the callback is executed as callback(query), where query is a String representing the SQL query
* or null if the query was not built successfully.
*/
(function() {
Expand Down Expand Up @@ -40,6 +40,30 @@
})
};

/**
* @param repo_name - The name of the repo that DataQ should work on.
* @param cb - The callback to trigger when the query is built.
*/
DataQ.DQ_rls_policy = function(repo_name, cb) {
// Set the callback.
callback = cb;

// Add the container to the page.
var container = $(DataQ.templates["dataq-container-rls-policy"]());
$('body').append(container);

// Create the policy object and set the repo name.
policy = DataQ.Policy();
policy.repo(repo_name);

// Handle DataQ close when clicking backdrop.
$(".dq-black-background").click(function() {
$(".dq-black-background").remove();
$(".dataq").remove();
callback(null);
});
};

/**
* Update the UI to reflect the latest query.
*/
Expand Down Expand Up @@ -107,7 +131,7 @@
query.sorts().forEach(function(sort) {
sort_strings.push(sort.string);
});

// Display the sorts.
if (sort_strings.length > 0) {
$(".dq-sorting-text").html(sort_strings.join(", "));
Expand Down
56 changes: 56 additions & 0 deletions src/apps/dataq/client_src/templates/dataq-container-rls-policy.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!-- HTML file containing an extension of the overall DataQ interface.
This interface is for building DataQ.Policy objects. -->

<!-- Create a translucent black background -->
<div class="dq-black-background"></div>

<!-- The DataQ container -->
<div class="dataq container-fluid">

<h4>
DataQ-Policy-Builder allows you to write PostgreSQL CREATE POLICY commands using a simple checklist-like user interface.
</h4>

<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading dq-panel" data-toggle="collapse" href="#collapseOne">
<h4 class="panel-title">
Policy Name
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">

<input id="policyName" type="text" class="form-control" placeholder="Policy Name" />

</div>
</div>

<div class="panel panel-default">
<div class="panel-heading dq-panel" data-toggle="collapse" href="#collapseTwo">
<h4 class="panel-title">
Allowed commands
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse in">
<div class="panel-body">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Choose command
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">SELECT</a></li>
<li><a href="#">INSERT</a></li>
<li><a href="#">UPDATE</a></li>
<li><a href="#">DELETE</a></li>
<li><a href="#">ALL</a></li>
</ul>
</div>
</div>
</div>

<!-- Button to run query -->
<div class="row">
<button class="btn btn-primary col-xs-3 dq-btn-run-query col-xs-offset-3">Query</button>
<button class="btn btn-default col-xs-3 dq-btn-cancel-query">Cancel</button>
</div>
</div>
11 changes: 6 additions & 5 deletions src/browser/templates/security-policies.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h4 class="inline-block">

<div class="col-sm-2">
<button class="btn btn-primary btn-xsm" id="btn-run" type="submit">Execute</button>
<button class="btn btn-primary btn-xsm modal-upload-dialog" type="button" target-modal="#security-policy-modal" title="New Policy"> New </button>
<button class="btn btn-primary btn-xsm" id="btn-dataq" type="button">Query Builder</button>
<button class="btn btn-primary btn-xsm modal-upload-dialog" type="button" target-modal="#security-policy-modal" title="New Policy"> New Table-Level Policy </button>
<button class="btn btn-primary btn-xsm" id="btn-dataq-rls-policy" type="button">Row-Level Policy Builder</button>
</div>

</div>
Expand Down Expand Up @@ -238,12 +238,13 @@ <h4 class="modal-title" id="confirm-modal-title">Update Security Policy</h4>
<!-- /dataq -->

<script>
$(document).on("click", "#btn-dataq", function(e) {
$(document).on("click", "#btn-dataq-rls-policy", function(e) {
e.preventDefault();
DataQ.DQ("{{repo}}", function(query) {
console.log(DataQ);
// DataQ.DQ("{{repo}}", function(query) {
DataQ.DQ_rls_policy("{{repo}}", function(query) {
$("#txt-sql").val(query);
});
console.log('click');
});
</script>
{% endblock js %}
Expand Down