mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add ability to reorder servers based on user
This commit is contained in:
parent
1ab4ffd8f7
commit
09335fc3d9
@ -30,6 +30,14 @@ class Users_Controller:
|
||||
def get_user_by_id(user_id):
|
||||
return users_helper.get_user(user_id)
|
||||
|
||||
@staticmethod
|
||||
def update_server_order(user_id, user_server_order):
|
||||
users_helper.update_server_order(user_id, user_server_order)
|
||||
|
||||
@staticmethod
|
||||
def get_server_order(user_id):
|
||||
return users_helper.get_server_order(user_id)
|
||||
|
||||
@staticmethod
|
||||
def user_query(user_id):
|
||||
return users_helper.user_query(user_id)
|
||||
|
@ -173,7 +173,10 @@ class Permissions_Servers:
|
||||
else:
|
||||
roles_list = users_helper.get_user_roles_id(user.user_id)
|
||||
role_server = Role_Servers.select().where(Role_Servers.role_id.in_(roles_list)).where(Role_Servers.server_id == server_id).execute()
|
||||
permissions_mask = role_server[0].permissions
|
||||
try:
|
||||
permissions_mask = role_server[0].permissions
|
||||
except IndexError:
|
||||
permissions_mask = '0' * len(server_permissions.get_permissions_list())
|
||||
return permissions_mask
|
||||
|
||||
@staticmethod
|
||||
|
@ -1,3 +1,5 @@
|
||||
from email.policy import default
|
||||
from http import server
|
||||
import sys
|
||||
import logging
|
||||
import datetime
|
||||
@ -42,6 +44,7 @@ class Users(Model):
|
||||
lang = CharField(default="en_EN")
|
||||
support_logs = CharField(default = '')
|
||||
valid_tokens_from = DateTimeField(default=datetime.datetime.now)
|
||||
server_order = CharField(default="")
|
||||
|
||||
class Meta:
|
||||
table_name = "users"
|
||||
@ -173,6 +176,14 @@ class helper_users:
|
||||
if up_data:
|
||||
Users.update(up_data).where(Users.user_id == user_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def update_server_order(user_id, user_server_order):
|
||||
Users.update(server_order = user_server_order).where(Users.user_id == user_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def get_server_order(user_id):
|
||||
return Users.select().where(Users.user_id == user_id)
|
||||
|
||||
@staticmethod
|
||||
def get_super_user_list():
|
||||
final_users = []
|
||||
|
@ -258,6 +258,10 @@ class AjaxHandler(BaseHandler):
|
||||
# Create the directory
|
||||
os.mkdir(dir_path)
|
||||
|
||||
elif page == "send_order":
|
||||
self.controller.users.update_server_order(exec_user['user_id'], bleach.clean(self.get_argument('order')))
|
||||
return
|
||||
|
||||
elif page == "unzip_file":
|
||||
if not permissions['Files'] in user_perms:
|
||||
if not superuser:
|
||||
|
@ -307,6 +307,29 @@ class PanelHandler(BaseHandler):
|
||||
list(filter(lambda x: x['stats']['running'], page_data['servers'])))
|
||||
page_data['server_stats']['stopped'] = len(page_data['servers']) - page_data['server_stats']['running']
|
||||
|
||||
#set user server order
|
||||
user_order = self.controller.users.get_user_by_id(exec_user['user_id'])
|
||||
user_order = user_order['server_order'].split(',')
|
||||
page_servers = []
|
||||
server_ids = []
|
||||
|
||||
for server_id in user_order:
|
||||
for server in page_data['servers']:
|
||||
if str(server['server_data']['server_id']) == str(server_id):
|
||||
page_servers.append(server)
|
||||
|
||||
|
||||
for server in page_data['servers']:
|
||||
server_ids.append(str(server['server_data']['server_id']))
|
||||
if server not in page_servers:
|
||||
page_servers.append(server)
|
||||
for server_id in user_order:
|
||||
#remove IDs in list that user no longer has access to
|
||||
if str(server_id) not in server_ids:
|
||||
user_order.remove(server_id)
|
||||
page_data['servers'] = page_servers
|
||||
|
||||
|
||||
for data in page_data['servers']:
|
||||
data['stats']['crashed'] = self.controller.servers.is_crashed(
|
||||
str(data['stats']['server_id']['server_id']))
|
||||
|
@ -123,7 +123,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for server in data['servers'] %}
|
||||
<tr>
|
||||
<tr id="{{server['server_data']['server_id']}}" draggable="true" ondragstart="start()" ondragover="dragover()" ondragend="dragend()">
|
||||
<td>
|
||||
<i class="fas fa-server"></i>
|
||||
<a href="/panel/server_detail?id={{server['server_data']['server_id']}}">
|
||||
@ -554,5 +554,55 @@
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
var row;
|
||||
|
||||
function start(){
|
||||
row = event.target;
|
||||
}
|
||||
function dragover(){
|
||||
var e = event;
|
||||
e.preventDefault();
|
||||
|
||||
let children= Array.from(e.target.parentNode.parentNode.children);
|
||||
|
||||
if(children.indexOf(e.target.parentNode)>children.indexOf(row))
|
||||
e.target.parentNode.after(row);
|
||||
else
|
||||
e.target.parentNode.before(row);
|
||||
}
|
||||
|
||||
function dragend(){
|
||||
var id_string = '';
|
||||
const table = document.querySelector("table");
|
||||
for (const row of table.rows) {
|
||||
if (row.getAttribute('id') != null){
|
||||
if (id_string != ''){
|
||||
id_string += ',' + String(row.getAttribute('id'));
|
||||
}else{
|
||||
id_string +=String(row.getAttribute('id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(id_string)
|
||||
sendOrder(id_string)
|
||||
}
|
||||
function sendOrder(id_string) {
|
||||
var token = getCookie("_xsrf")
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
headers: {'X-XSRFToken': token},
|
||||
url: '/ajax/send_order?order='+id_string,
|
||||
data: {
|
||||
order: id_string,
|
||||
},
|
||||
success: function(data){
|
||||
console.log("got response:");
|
||||
console.log(data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{% end %}
|
@ -134,18 +134,21 @@
|
||||
server_version = document.getElementById('version');
|
||||
server_input_motd = document.getElementById('input_motd');
|
||||
|
||||
if (server['stats']['updating']){
|
||||
server_status.setAttribute("class", "text-success");
|
||||
server_status.innerHTML = `{{ translate('serverTerm', 'updating', data['lang']) }}`;
|
||||
}
|
||||
|
||||
/* TODO Update each element */
|
||||
if (server.running)
|
||||
{
|
||||
if (server.int_ping_results)
|
||||
{
|
||||
server_status.setAttribute("class", "text-success");
|
||||
server_status.innerHTML = `{{ translate('serverStats', 'online', data['lang']) }}`;
|
||||
if (server.running){
|
||||
if (server['stats']['waiting_start']){
|
||||
server_status.setAttribute("class", "text-warning");
|
||||
server_status.innerHTML = `{{ translate('serverStats', 'starting', data['lang']) }}`;
|
||||
}
|
||||
else
|
||||
{
|
||||
server_status.setAttribute("class", "text-warning");
|
||||
server_status.innerHTML = `{{ translate('serverStats', 'starting', data['lang']) }}`;
|
||||
server_status.setAttribute("class", "text-success");
|
||||
server_status.innerHTML = `{{ translate('serverStats', 'online', data['lang']) }}`;
|
||||
}
|
||||
|
||||
startedUTC = server.started;
|
||||
|
16
app/migrations/20220226_server_order.py
Normal file
16
app/migrations/20220226_server_order.py
Normal file
@ -0,0 +1,16 @@
|
||||
# Generated by database migrator
|
||||
import peewee
|
||||
|
||||
def migrate(migrator, database, **kwargs):
|
||||
migrator.add_columns('users', server_order=peewee.CharField(default=''))
|
||||
"""
|
||||
Write your migrations here.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, **kwargs):
|
||||
migrator.drop_columns('users', ['server_order'])
|
||||
"""
|
||||
Write your rollback migrations here.
|
||||
"""
|
Loading…
Reference in New Issue
Block a user