mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add role detection to creation
This commit is contained in:
parent
2847cab1d8
commit
a90dd546a1
@ -518,6 +518,31 @@ class Controller:
|
||||
new_server_id,
|
||||
)
|
||||
|
||||
exec_user = self.users.get_user_by_id(int(user_id))
|
||||
captured_roles = data.get("roles", [])
|
||||
# These lines create a new Role for the Server with full permissions
|
||||
# and add the user to it if he's not a superuser
|
||||
if len(captured_roles) == 0:
|
||||
if not exec_user["superuser"]:
|
||||
new_server_uuid = self.servers.get_server_data_by_id(
|
||||
new_server_id
|
||||
).get("server_uuid")
|
||||
role_id = self.roles.add_role(
|
||||
f"Creator of Server with uuid={new_server_uuid}",
|
||||
exec_user["user_id"],
|
||||
)
|
||||
self.server_perms.add_role_server(
|
||||
new_server_id, role_id, "11111111"
|
||||
)
|
||||
self.users.add_role_to_user(exec_user["user_id"], role_id)
|
||||
|
||||
else:
|
||||
for role in captured_roles:
|
||||
role_id = role
|
||||
self.server_perms.add_role_server(
|
||||
new_server_id, role_id, "11111111"
|
||||
)
|
||||
|
||||
return new_server_id, server_fs_uuid
|
||||
|
||||
@staticmethod
|
||||
|
@ -24,6 +24,7 @@ new_server_schema = {
|
||||
"examples": ["My Server"],
|
||||
"minLength": 2,
|
||||
},
|
||||
"roles": {"title": "Roles to add", "type": "array", "examples": [1, 2, 3]},
|
||||
"stop_command": {
|
||||
"title": "Stop command",
|
||||
"description": '"" means the default for the server creation type.',
|
||||
|
@ -156,7 +156,7 @@
|
||||
<div class="card-body scroll">
|
||||
<div class="form-group">
|
||||
{% for r in data['roles'] %}
|
||||
<span class="d-block menu-option"><label><input name="{{ r['role_id'] }}" type="checkbox"> {{ r['role_name'].capitalize() }}</label></span>
|
||||
<span class="d-block menu-option"><label><input class="roles" name="{{ r['role_id'] }}" type="checkbox" value="{{ r['role_id'] }}"> {{ r['role_name'].capitalize() }}</label></span>
|
||||
{% end %}
|
||||
</div>
|
||||
</div>
|
||||
@ -271,7 +271,7 @@
|
||||
<div class="card-body scroll">
|
||||
<div class="form-group">
|
||||
{% for r in data['roles'] %}
|
||||
<span class="d-block menu-option"><label><input name="{{ r['role_id'] }}" type="checkbox">
|
||||
<span class="d-block menu-option"><label><input class="roles" name="{{ r['role_id'] }}" type="checkbox" value="{{ r['role_id'] }}">
|
||||
{{ r['role_name'].capitalize() }}</label></span>
|
||||
{% end %}
|
||||
</div>
|
||||
@ -389,7 +389,7 @@
|
||||
<div class="card-body scroll">
|
||||
<div class="form-group">
|
||||
{% for r in data['roles'] %}
|
||||
<span class="d-block menu-option"><label><input name="{{ r['role_id'] }}" type="checkbox">
|
||||
<span class="d-block menu-option"><label><input class="roles" name="{{ r['role_id'] }}" type="checkbox" value="{{ r['role_id'] }}">
|
||||
{{ r['role_name'].capitalize() }}</label></span>
|
||||
{% end %}
|
||||
</div>
|
||||
@ -528,7 +528,7 @@
|
||||
<div class="card-body scroll">
|
||||
<div class="form-group">
|
||||
{% for r in data['roles'] %}
|
||||
<span class="d-block menu-option"><label><input name="{{ r['role_id'] }}" type="checkbox">
|
||||
<span class="d-block menu-option"><label><input class="roles" name="{{ r['role_id'] }}" type="checkbox" value="{{ r['role_id'] }}">
|
||||
{{ r['role_name'].capitalize() }}</label></span>
|
||||
{% end %}
|
||||
</div>
|
||||
@ -895,6 +895,9 @@
|
||||
|
||||
<script>
|
||||
function replacer(key, value) {
|
||||
if (key === "roles"){
|
||||
return value
|
||||
}
|
||||
if (key != "ignored_exits") {
|
||||
if (typeof value == "boolean" || key === "host" || key === "version") {
|
||||
return value
|
||||
@ -905,6 +908,15 @@
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function calcRoles() {
|
||||
let role_ids = $('.roles').map(function() {
|
||||
if ($(this).is(':checked')){
|
||||
return $(this).val();
|
||||
}
|
||||
}).get();
|
||||
console.log(role_ids)
|
||||
return role_ids
|
||||
}
|
||||
async function send_server(data){
|
||||
let token = getCookie("_xsrf")
|
||||
let res = await fetch(`/api/v2/servers/`, {
|
||||
@ -937,7 +949,8 @@
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
@ -976,7 +989,8 @@
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
@ -1011,7 +1025,8 @@
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
@ -1046,7 +1061,8 @@
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_java",
|
||||
"minecraft_java_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
|
Loading…
Reference in New Issue
Block a user