working toward a permissions grid in domain-server settings

This commit is contained in:
Seth Alves 2016-05-31 16:56:08 -07:00
parent cb3dfa0457
commit 7810ed6313
3 changed files with 109 additions and 50 deletions

View file

@ -87,27 +87,6 @@
"help": "Password used for basic HTTP authentication. Leave this blank if you do not want to change it.",
"value-hidden": true
},
{
"name": "restricted_access",
"type": "checkbox",
"label": "Restricted Access",
"default": false,
"help": "Only users listed in \"Allowed Users\" can enter your domain."
},
{
"name": "allowed_users",
"type": "table",
"label": "Allowed Users",
"help": "You can always connect from the domain-server machine.",
"numbered": false,
"columns": [
{
"name": "username",
"label": "Username",
"can_set": true
}
]
},
{
"name": "maximum_user_capacity",
"label": "Maximum User Capacity",
@ -117,25 +96,47 @@
"advanced": false
},
{
"name": "allowed_editors",
"name": "permissions",
"type": "table",
"label": "Allowed Editors",
"help": "List the High Fidelity names for people you want to be able lock or unlock entities in this domain.<br/>An empty list means everyone.",
"numbered": false,
"label": "Domain-Wide User Permissions",
"help": "Indicate which users or groups can have which domain-wide permissions.",
"columns": [
{
"name": "username",
"label": "Username",
"can_set": true
"name": "permissions_id",
"label": "User/Group"
},
{
"name": "id_can_connect",
"label": "Connect",
"type": "checkbox",
"default": true
},
{
"name": "id_can_adjust_locks",
"label": "Lock/Unlock",
"type": "checkbox",
"default": false
},
{
"name": "id_can_rez",
"label": "Rez",
"type": "checkbox",
"default": false
},
{
"name": "id_can_rez_tmp",
"label": "Rez Temp",
"type": "checkbox",
"default": false
},
{
"name": "id_can_write_to_asset_server",
"label": "Write Assets",
"type": "checkbox",
"default": false
}
]
},
{
"name": "editors_are_rezzers",
"type": "checkbox",
"label": "Only Editors Can Create Entities",
"help": "Only users listed in \"Allowed Editors\" can create new entites.",
"default": false
}
]
},

View file

@ -875,6 +875,7 @@ function saveSettings() {
}
}
console.log("----- SAVING ------");
console.log(formJSON);
// re-enable all inputs
@ -957,7 +958,11 @@ function makeTable(setting, keypath, setting_value, isLocked) {
colValue = rowIsObject ? row[col.name] : row;
colName = keypath + "[" + rowIndexOrName + "]" + (rowIsObject ? "." + col.name : "");
} else {
colValue = row[col.name];
if (col.type === "checkbox") {
colValue = (row[col.name] ? "X" : "")
} else {
colValue = row[col.name];
}
colName = keypath + "." + rowIndexOrName + "." + col.name;
}
@ -1012,10 +1017,22 @@ function makeTableInputs(setting) {
}
_.each(setting.columns, function(col) {
html += "<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>\
<input type='text' class='form-control' placeholder='" + (col.placeholder ? col.placeholder : "") + "'\
value='" + (col.default ? col.default : "") + "' data-default='" + (col.default ? col.default : "") + "'>\
</td>"
if (col.type === "checkbox") {
html += "<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>"
// html += "<div class='toggle-checkbox-container'>"
html += "<input type='checkbox' "
html += "class='form-control toggle-checkbox' "
html += "name='" + col.name + "'"
html += (col.default ? " checked" : "")
html += "/>"
// html += "</div>"
html += "</td>"
} else {
html += "<td class='" + Settings.DATA_COL_CLASS + "'name='" + col.name + "'>\
<input type='text' class='form-control' placeholder='" + (col.placeholder ? col.placeholder : "") + "'\
value='" + (col.default ? col.default : "") + "' data-default='" + (col.default ? col.default : "") + "'>\
</td>"
}
})
if (setting.can_order) {
@ -1072,6 +1089,10 @@ function addTableRow(add_glyphicon) {
var table = row.parents('table')
var isArray = table.data('setting-type') === 'array'
console.log("------------------------");
console.log("table = " + table.name + " " + table.id);
console.log("isArray = " + isArray);
var columns = row.parent().children('.' + Settings.DATA_ROW_CLASS)
if (!isArray) {
@ -1115,11 +1136,17 @@ function addTableRow(add_glyphicon) {
var table = row.parents("table")
var setting_name = table.attr("name")
var full_name = setting_name + "." + key
console.log("table = " + table);
console.log("setting_name = " + setting_name);
console.log("full_name = " + full_name);
row.addClass(Settings.DATA_ROW_CLASS + " " + Settings.NEW_ROW_CLASS)
row.removeClass("inputs")
_.each(row.children(), function(element) {
if ($(element).hasClass("numbered")) {
console.log("A");
// Index row
var numbers = columns.children(".numbered")
if (numbers.length > 0) {
@ -1127,40 +1154,70 @@ function addTableRow(add_glyphicon) {
} else {
$(element).html(1)
}
} else if ($(element).hasClass(Settings.REORDER_BUTTONS_CLASS)) {
$(element).html("<td class='" + Settings.REORDER_BUTTONS_CLASSES + "'><a href='javascript:void(0);'"
+ " class='" + Settings.MOVE_UP_SPAN_CLASSES + "'></a><a href='javascript:void(0);' class='"
+ Settings.MOVE_DOWN_SPAN_CLASSES + "'></span></td>")
} else if ($(element).hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) {
} else if ($(element).hasClass(Settings.REORDER_BUTTONS_CLASS)) {
console.log("B");
$(element).html("<td class='" + Settings.REORDER_BUTTONS_CLASSES + "'><a href='javascript:void(0);'"
+ " class='" + Settings.MOVE_UP_SPAN_CLASSES + "'></a><a href='javascript:void(0);' class='"
+ Settings.MOVE_DOWN_SPAN_CLASSES + "'></span></td>")
} else if ($(element).hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) {
console.log("C");
// Change buttons
var anchor = $(element).children("a")
anchor.removeClass(Settings.ADD_ROW_SPAN_CLASSES)
anchor.addClass(Settings.DEL_ROW_SPAN_CLASSES)
} else if ($(element).hasClass("key")) {
console.log("D");
var input = $(element).children("input")
$(element).html(input.val())
input.remove()
} else if ($(element).hasClass(Settings.DATA_COL_CLASS)) {
console.log("E");
// Hide inputs
var input = $(element).children("input")
console.log("element = " + element);
var input = $(element).find("input")
var val = input.val();
if (input.attr("type") == "checkbox") {
val = input.is(':checked');
$(element).children().hide();
}
input.attr("type", "hidden")
if (isArray) {
var row_index = row.siblings('.' + Settings.DATA_ROW_CLASS).length
var key = $(element).attr('name')
console.log("row_index = " + row_index);
console.log("key = " + key);
// are there multiple columns or just one?
// with multiple we have an array of Objects, with one we have an array of whatever the value type is
var num_columns = row.children('.' + Settings.DATA_COL_CLASS).length
console.log("num_columns = " + num_columns);
console.log("input = " + JSON.stringify(input));
console.log("new name = " + setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : ""));
input.attr("name", setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : ""))
} else {
input.attr("name", full_name + "." + $(element).attr("name"))
}
input.attr("data-changed", "true")
$(element).append(input.val())
// if the input is a bootstrapSwitch, we need to move this input up to where it will be found
var inputElement = $(input).detach();
$(element).append(inputElement);
console.log("input.val() = " + val);
$(element).append(val)
} else {
console.log("F");
console.log("Unknown table element")
}
})

View file

@ -44,7 +44,8 @@ DomainServerSettingsManager::DomainServerSettingsManager() :
QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
descriptionFile.open(QIODevice::ReadOnly);
QJsonDocument descriptionDocument = QJsonDocument::fromJson(descriptionFile.readAll());
QJsonParseError parseError;
QJsonDocument descriptionDocument = QJsonDocument::fromJson(descriptionFile.readAll(), &parseError);
if (descriptionDocument.isObject()) {
QJsonObject descriptionObject = descriptionDocument.object();
@ -63,8 +64,8 @@ DomainServerSettingsManager::DomainServerSettingsManager() :
}
static const QString MISSING_SETTINGS_DESC_MSG =
QString("Did not find settings decription in JSON at %1 - Unable to continue. domain-server will quit.")
.arg(SETTINGS_DESCRIPTION_RELATIVE_PATH);
QString("Did not find settings decription in JSON at %1 - Unable to continue. domain-server will quit.\n%2 at %3")
.arg(SETTINGS_DESCRIPTION_RELATIVE_PATH).arg(parseError.errorString()).arg(parseError.offset);
static const int MISSING_SETTINGS_DESC_ERROR_CODE = 6;
QMetaObject::invokeMethod(QCoreApplication::instance(), "queuedQuit", Qt::QueuedConnection,