Added Account section
This commit is contained in:
56
user/grants/grants.css
Normal file
56
user/grants/grants.css
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@import url('/global.css');
|
||||
|
||||
#grants {
|
||||
padding: 15px 15px 15px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-bottom: 1px solid #4C4C4C;
|
||||
border-collapse: separate;
|
||||
border-left: 1px solid #B2B2B2;
|
||||
border-right: 1px solid #4C4C4C;
|
||||
border-spacing: 2px;
|
||||
border-top: 1px solid #B2B2B2;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
table label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
table tbody td {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table tbody td:first-of-type {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table td {
|
||||
border-bottom: 1px solid #B2B2B2;
|
||||
border-left: 1px solid #4C4C4C;
|
||||
border-right: 1px solid #B2B2B2;
|
||||
border-top: 1px solid #4C4C4C;
|
||||
padding: 2px;
|
||||
}
|
271
user/grants/grants.js
Normal file
271
user/grants/grants.js
Normal file
@ -0,0 +1,271 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { settings, elements, apiGet, apiPut, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.billingNone = "billing-none";
|
||||
elements.billingRO = "billing-ro";
|
||||
elements.billingRW = "billing-rw";
|
||||
elements.createDomain = "create-domain";
|
||||
elements.createImage = "create-image";
|
||||
elements.createLinode = "create-linode";
|
||||
elements.createLV = "create-lv";
|
||||
elements.createNB = "create-nb";
|
||||
elements.createSS = "create-ss";
|
||||
elements.createVolume = "create-volume";
|
||||
elements.grantBox = "grant-box";
|
||||
elements.grantTables = {};
|
||||
elements.grantTables.domain = "dns-grants";
|
||||
elements.grantTables.image = "image-grants";
|
||||
elements.grantTables.linode = "linode-grants";
|
||||
elements.grantTables.longview = "lv-grants";
|
||||
elements.grantTables.nodebalancer = "nb-grants";
|
||||
elements.grantTables.stackscript = "ss-grants";
|
||||
elements.grantTables.volume = "volume-grants";
|
||||
elements.modifyLV = "modify-lv";
|
||||
elements.updateButton = "update-button";
|
||||
|
||||
// Data received from API calls
|
||||
var data = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.billingNone = {};
|
||||
ui.billingRO = {};
|
||||
ui.billingRW = {};
|
||||
ui.createDomain = {};
|
||||
ui.createImage = {};
|
||||
ui.createLinode = {};
|
||||
ui.createLV = {};
|
||||
ui.createNB = {};
|
||||
ui.createSS = {};
|
||||
ui.createVolume = {};
|
||||
ui.grantTables = {};
|
||||
ui.grantTables.domain = {};
|
||||
ui.grantTables.image = {};
|
||||
ui.grantTables.linode = {};
|
||||
ui.grantTables.longview = {};
|
||||
ui.grantTables.nodebalancer = {};
|
||||
ui.grantTables.stackscript = {};
|
||||
ui.grantTables.volume = {};
|
||||
ui.modifyLV = {};
|
||||
ui.updateButton = {};
|
||||
|
||||
// Creates a row for a grant table
|
||||
var createGrantRow = function(type, perm)
|
||||
{
|
||||
var row = document.createElement("tr");
|
||||
|
||||
var label = document.createElement("td");
|
||||
label.innerHTML = perm.label;
|
||||
row.appendChild(label);
|
||||
|
||||
var none = document.createElement("td");
|
||||
var noneLabel = document.createElement("label");
|
||||
noneLabel.for = type + "-none-" + perm.id;
|
||||
var noneBox = document.createElement("input");
|
||||
noneBox.id = type + "-none-" + perm.id;
|
||||
noneBox.className = elements.grantBox;
|
||||
noneBox.type = "radio";
|
||||
noneBox.name = type + "-" + perm.id;
|
||||
noneLabel.appendChild(noneBox);
|
||||
none.appendChild(noneLabel);
|
||||
row.appendChild(none);
|
||||
|
||||
var ro = document.createElement("td");
|
||||
var roLabel = document.createElement("label");
|
||||
roLabel.for = type + "-ro-" + perm.id;
|
||||
var roBox = document.createElement("input");
|
||||
roBox.id = type + "-ro-" + perm.id;
|
||||
roBox.className = elements.grantBox;
|
||||
roBox.type = "radio";
|
||||
roBox.name = type + "-" + perm.id;
|
||||
roLabel.appendChild(roBox);
|
||||
ro.appendChild(roLabel);
|
||||
row.appendChild(ro);
|
||||
|
||||
var rw = document.createElement("td");
|
||||
var rwLabel = document.createElement("label");
|
||||
rwLabel.for = type + "-rw-" + perm.id;
|
||||
var rwBox = document.createElement("input");
|
||||
rwBox.id = type + "-rw-" + perm.id;
|
||||
rwBox.className = elements.grantBox;
|
||||
rwBox.type = "radio";
|
||||
rwBox.name = type + "-" + perm.id;
|
||||
rwLabel.appendChild(rwBox);
|
||||
rw.appendChild(rwLabel);
|
||||
row.appendChild(rw);
|
||||
|
||||
switch (perm.permissions) {
|
||||
case "read_only":
|
||||
roBox.checked = true;
|
||||
break;
|
||||
case "read_write":
|
||||
rwBox.checked = true;
|
||||
break;
|
||||
default:
|
||||
noneBox.checked = true;
|
||||
}
|
||||
|
||||
return row;
|
||||
};
|
||||
|
||||
// Callback for user grants API call
|
||||
var displayGrants = function(response)
|
||||
{
|
||||
// Set global grants
|
||||
ui.createLinode.checked = response.global.add_linodes;
|
||||
ui.createNB.checked = response.global.add_nodebalancers;
|
||||
ui.createLV.checked = response.global.add_longview;
|
||||
ui.modifyLV.checked = response.global.longview_subscription;
|
||||
ui.createDomain.checked = response.global.add_domains;
|
||||
ui.createSS.checked = response.global.add_stackscripts;
|
||||
ui.createImage.checked = response.global.add_images;
|
||||
ui.createVolume.checked = response.global.add_volumes;
|
||||
|
||||
// Billing grants
|
||||
switch (response.global.account_access) {
|
||||
case "read_only":
|
||||
ui.billingRO.checked = true;
|
||||
break;
|
||||
case "read_write":
|
||||
ui.billingRW.checked = true;
|
||||
break;
|
||||
default:
|
||||
ui.billingNone.checked = true;
|
||||
}
|
||||
|
||||
// Specific grants
|
||||
for (var i in ui.grantTables) {
|
||||
for (var j = 0; j < response[i].length; j++)
|
||||
ui.grantTables[i].appendChild(createGrantRow(i, response[i][j]));
|
||||
}
|
||||
|
||||
ui.updateButton.disabled = false;
|
||||
};
|
||||
|
||||
// Click handler for update button
|
||||
var handleUpdate = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
var req = {};
|
||||
|
||||
// Add in global permissions
|
||||
req.global = {
|
||||
"add_linodes": ui.createLinode.checked,
|
||||
"add_nodebalancers": ui.createNB.checked,
|
||||
"add_longview": ui.createLV.checked,
|
||||
"longview_subscription": ui.modifyLV.checked,
|
||||
"add_domains": ui.createDomain.checked,
|
||||
"add_stackscripts": ui.createSS.checked,
|
||||
"add_images": ui.createImage.checked,
|
||||
"add_volumes": ui.createVolume.checked
|
||||
};
|
||||
|
||||
// Add in billing permissions
|
||||
if (ui.billingRO.checked)
|
||||
req.global.account_access = "read_only";
|
||||
else if (ui.billingRW.checked)
|
||||
req.global.account_access = "read_write";
|
||||
else
|
||||
req.global.account_access = null;
|
||||
|
||||
// Add in specific persmissions
|
||||
for (var i in ui.grantTables)
|
||||
req[i] = [];
|
||||
|
||||
var grantBoxes = document.getElementsByClassName(elements.grantBox);
|
||||
for (var i = 0; i < grantBoxes.length; i++) {
|
||||
if (!grantBoxes[i].checked)
|
||||
continue;
|
||||
|
||||
// This will give us an array tuple of [type, permission, id]
|
||||
var id = grantBoxes[i].id.split("-");
|
||||
|
||||
var perm = {};
|
||||
perm.id = parseInt(id[2]);
|
||||
if (id[1] == "ro")
|
||||
perm.permissions = "read_only";
|
||||
else if (id[1] == "rw")
|
||||
perm.permissions = "read_write";
|
||||
else
|
||||
perm.permissions = null;
|
||||
|
||||
req[id[0]].push(perm);
|
||||
}
|
||||
|
||||
apiPut("/account/users/" + data.params.user + "/grants", req, function(response)
|
||||
{
|
||||
location.href = "/user";
|
||||
});
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a username, so die if we don't have it
|
||||
if (!data.params.user) {
|
||||
alert("No username supplied!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Highlight the account nav link
|
||||
var navlinks = document.getElementsByClassName(elements.navlink);
|
||||
for (var i = 0; i < navlinks.length; i++) {
|
||||
if (navlinks[i].pathname == "/account/")
|
||||
navlinks[i].className = " " + elements.navlinkActive;
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.billingNone = document.getElementById(elements.billingNone);
|
||||
ui.billingRO = document.getElementById(elements.billingRO);
|
||||
ui.billingRW = document.getElementById(elements.billingRW);
|
||||
ui.createDomain = document.getElementById(elements.createDomain);
|
||||
ui.createImage = document.getElementById(elements.createImage);
|
||||
ui.createLinode = document.getElementById(elements.createLinode);
|
||||
ui.createLV = document.getElementById(elements.createLV);
|
||||
ui.createNB = document.getElementById(elements.createNB);
|
||||
ui.createSS = document.getElementById(elements.createSS);
|
||||
ui.createVolume = document.getElementById(elements.createVolume);
|
||||
for (var i in ui.grantTables)
|
||||
ui.grantTables[i] = document.getElementById(elements.grantTables[i]);
|
||||
ui.modifyLV = document.getElementById(elements.modifyLV);
|
||||
ui.updateButton = document.getElementById(elements.updateButton);
|
||||
|
||||
// Populate username where we need it
|
||||
document.title += " - " + data.params.user;
|
||||
|
||||
// Attach event handlers
|
||||
ui.updateButton.addEventListener("click", handleUpdate);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/account/users/" + data.params.user + "/grants", displayGrants, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
132
user/grants/index.shtml
Normal file
132
user/grants/index.shtml
Normal file
@ -0,0 +1,132 @@
|
||||
<!--
|
||||
This file is part of Linode Manager Classic.
|
||||
|
||||
Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>LMC - Account // User Grants</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="grants.css" />
|
||||
<script src="grants.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<!--#include virtual="/include/account_subnav.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="grants">
|
||||
<h2>Global Grants</h2>
|
||||
<input id="create-linode" type="checkbox" /> <label for="create-linode">Can add Linodes to this account ($)</label><br />
|
||||
<input id="create-nb" type="checkbox" /> <label for="create-nb">Can add NodeBalancers to this account ($)</label><br />
|
||||
<input id="create-lv" type="checkbox" /> <label for="create-lv">Can add Longview clients to this account</label><br />
|
||||
<input id="modify-lv" type="checkbox" /> <label for="modify-lv">Can modify this account's Longview subscription ($)</label><br />
|
||||
<input id="create-domain" type="checkbox" /> <label for="create-domain">Can add Domains using the DNS Manager</label><br />
|
||||
<input id="create-ss" type="checkbox" /> <label for="create-ss">Can create StackScripts under this account</label><br />
|
||||
<input id="create-image" type="checkbox" /> <label for="create-image">Can create frozen Images under this account</label><br />
|
||||
<input id="create-volume" type="checkbox" /> <label for="create-volume">Can add Block Storage Volumes to this account ($)</label>
|
||||
<h2>Billing Access</h2>
|
||||
<input id="billing-none" type="radio" name="billing" /> <label for="billing-none"><strong>None</strong> - Cannot view any billing information</label><br />
|
||||
<input id="billing-ro" type="radio" name="billing" /> <label for="billing-ro"><strong>Read Only</strong> - Can view invoices, billing info, and will receive copies of all invoices and payment emails</label><br />
|
||||
<input id="billing-rw" type="radio" name="billing" /> <label for="billing-rw"><strong>Read-Write</strong> - Can make payments, update contact and billing info, and will receive copies of all invoices and payment emails</label>
|
||||
<h2>Linode Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Linode</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="linode-grants"></tbody>
|
||||
</table>
|
||||
<h2>NodeBalancer Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>NodeBalancer</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="nb-grants"></tbody>
|
||||
</table>
|
||||
<h2>Longview Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Server</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="lv-grants"></tbody>
|
||||
</table>
|
||||
<h2>DNS Zone Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Zone</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="dns-grants"></tbody>
|
||||
</table>
|
||||
<h2>StackScript Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>StackScript</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ss-grants"></tbody>
|
||||
</table>
|
||||
<h2>Image Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Image</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="image-grants"></tbody>
|
||||
</table>
|
||||
<h2>Volume Grants</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Volume</td>
|
||||
<td>None</td>
|
||||
<td>Read Only</td>
|
||||
<td>Read-Write</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="volume-grants"></tbody>
|
||||
</table>
|
||||
<button disabled id="update-button" type="button">Update Grants</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user