mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Adds user based languages
changes server creation so that it adds it to roles instead of creating one Changes server creation so you cannot create a server without a role.
This commit is contained in:
parent
d0f6e6b8a9
commit
72a85d7e64
@ -42,6 +42,7 @@ class Servers_Controller:
|
||||
for role in roles_list:
|
||||
role_id = role.role_id
|
||||
role_data = Roles_Controller.get_role_with_servers(role_id)
|
||||
role_data['servers'] = {server_id}
|
||||
server_permissions.delete_roles_permissions(role_id, role_data['servers'])
|
||||
server_permissions.remove_roles_of_server(server_id)
|
||||
servers_helper.remove_server(server_id)
|
||||
|
@ -40,8 +40,8 @@ class Users(Model):
|
||||
password = CharField(default="")
|
||||
enabled = BooleanField(default=True)
|
||||
superuser = BooleanField(default=False)
|
||||
api_token = CharField(default="", unique=True, index=True), # we may need to revisit this
|
||||
lang = CharField(default='en_EN')
|
||||
api_token = CharField(default="", unique=True, index=True) # we may need to revisit this
|
||||
lang = CharField(default="en_EN")
|
||||
|
||||
class Meta:
|
||||
table_name = "users"
|
||||
@ -73,6 +73,10 @@ class helper_users:
|
||||
query = Users.select()
|
||||
return query
|
||||
|
||||
@staticmethod
|
||||
def get_user_lang_by_id(user_id):
|
||||
return Users.get(Users.user_id == user_id).lang
|
||||
|
||||
@staticmethod
|
||||
def get_user_id_by_name(username):
|
||||
if username == "SYSTEM":
|
||||
@ -82,10 +86,6 @@ class helper_users:
|
||||
except DoesNotExist:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_user_lang_by_id(user_id):
|
||||
return Users.get(Users.user_id == user_id).lang
|
||||
|
||||
@staticmethod
|
||||
def get_user_by_api_token(token: str):
|
||||
query = Users.select().where(Users.api_token == token)
|
||||
@ -119,7 +119,6 @@ class helper_users:
|
||||
'api_token': None,
|
||||
'roles': [],
|
||||
'servers': [],
|
||||
'lang': 'en_EN'
|
||||
}
|
||||
user = model_to_dict(Users.get(Users.user_id == user_id))
|
||||
|
||||
|
@ -284,11 +284,12 @@ class Helpers:
|
||||
break
|
||||
path_list = test.split('/')
|
||||
root_path = path_list[0]
|
||||
'''
|
||||
if len(path_list) > 1:
|
||||
for i in range(len(path_list) - 2):
|
||||
root_path = os.path.join(root_path, path_list[i + 1])
|
||||
|
||||
full_root_path = os.path.join(tempDir, root_path)
|
||||
'''
|
||||
full_root_path = tempDir
|
||||
|
||||
for item in os.listdir(full_root_path):
|
||||
try:
|
||||
|
@ -48,7 +48,7 @@ class db_builder:
|
||||
# Users.enabled: True,
|
||||
# Users.superuser: True
|
||||
#}).execute()
|
||||
user_id = users_helper.add_user(username, password=password, superuser=True)
|
||||
user_id = users_helper.add_user(username=username, password=password, superuser=True)
|
||||
#users_helper.update_user(user_id, user_crafty_data={"permissions_mask":"111", "server_quantity":[-1,-1,-1]} )
|
||||
|
||||
#console.info("API token is {}".format(api_token))
|
||||
|
@ -366,10 +366,11 @@ class PanelHandler(BaseHandler):
|
||||
page_data['permissions_list'] = set()
|
||||
page_data['quantity_server'] = self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits()
|
||||
page_data['languages'] = []
|
||||
page_data['languages'].append(self.controller.users.get_user_lang_by_id(exec_user_id))
|
||||
for file in os.listdir(os.path.join(helper.root_dir, 'app', 'translations')):
|
||||
if file.endswith('.json'):
|
||||
page_data['languages'].append(file.split('.')[0])
|
||||
print(page_data['languages'])
|
||||
if file != str(page_data['languages'][0] + '.json'):
|
||||
page_data['languages'].append(file.split('.')[0])
|
||||
|
||||
template = "panel/panel_edit_user.html"
|
||||
|
||||
@ -390,9 +391,11 @@ class PanelHandler(BaseHandler):
|
||||
page_data['permissions_list'] = self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
||||
page_data['quantity_server'] = self.controller.crafty_perms.list_crafty_permissions_quantity_limits(user_id)
|
||||
page_data['languages'] = []
|
||||
page_data['languages'].append(self.controller.users.get_user_lang_by_id(exec_user_id))
|
||||
for file in os.listdir(os.path.join(helper.root_dir, 'app', 'translations')):
|
||||
if file.endswith('.json'):
|
||||
page_data['languages'].append(file.split('.')[0])
|
||||
if file != str(page_data['languages'][0] + '.json'):
|
||||
page_data['languages'].append(file.split('.')[0])
|
||||
|
||||
if user_id is None:
|
||||
self.redirect("/panel/error?error=Invalid User ID")
|
||||
@ -701,7 +704,7 @@ class PanelHandler(BaseHandler):
|
||||
password1 = bleach.clean(self.get_argument('password1', None))
|
||||
enabled = int(float(self.get_argument('enabled', '0')))
|
||||
regen_api = int(float(self.get_argument('regen_api', '0')))
|
||||
lang = bleach.clean(self.get_argument('lang'), 'en_EN')
|
||||
lang = bleach.clean(self.get_argument('language'), 'en_EN')
|
||||
|
||||
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
||||
if user_id != exec_user_id:
|
||||
|
@ -66,10 +66,15 @@ class ServerHandler(BaseHandler):
|
||||
'menu_servers': defined_servers,
|
||||
'show_contribute': helper.get_setting("show_contribute_link", True)
|
||||
}
|
||||
page_data['lang'] = self.controller.users.get_user_lang_by_id(exec_user_id)
|
||||
|
||||
if page == "step1":
|
||||
|
||||
if not exec_user['superuser'] and not self.controller.crafty_perms.can_create_server(exec_user_id):
|
||||
if len(self.controller.users.get_user_roles_id(exec_user_id)) <= 0:
|
||||
self.redirect("/panel/error?error=Unauthorized access: you must have a role to create a server.")
|
||||
return
|
||||
|
||||
elif not exec_user['superuser'] and not self.controller.crafty_perms.can_create_server(exec_user_id):
|
||||
self.redirect("/panel/error?error=Unauthorized access: not a server creator or server limit reached")
|
||||
return
|
||||
|
||||
@ -200,11 +205,10 @@ class ServerHandler(BaseHandler):
|
||||
new_server_id,
|
||||
self.get_remote_ip())
|
||||
|
||||
#These lines create a new Role for the Server with full permissions and add the user to it
|
||||
#These lines add the server to all the user's existing roles with full permissions
|
||||
new_server_uuid = self.controller.servers.get_server_data_by_id(new_server_id).get("server_uuid")
|
||||
role_id = self.controller.roles.add_role("Creator of Server with uuid={}".format(new_server_uuid))
|
||||
self.controller.server_perms.add_role_server(new_server_id, role_id, "11111111")
|
||||
self.controller.users.add_role_to_user(exec_user_id, role_id)
|
||||
for role_id in self.controller.users.get_user_roles_id(exec_user_id):
|
||||
self.controller.server_perms.add_role_server(new_server_id, role_id, "11111111")
|
||||
if not exec_user['superuser']:
|
||||
self.controller.server_perms.add_server_creation(exec_user_id)
|
||||
|
||||
|
@ -92,7 +92,7 @@
|
||||
<div style="text-align: center; color: grey;">
|
||||
<h1>{{ translate('dashboard', 'welcome', data['lang']) }}</h1>
|
||||
<br>
|
||||
<h7>{{ translate('dashboard', 'no-servers') }} {{ translate('dashboard', 'newServer', data['lang']) }}.</h7>
|
||||
<h7>{{ translate('dashboard', 'no-servers', data['lang']) }} {{ translate('dashboard', 'newServer', data['lang']) }}.</h7>
|
||||
</div>
|
||||
|
||||
{% end %}
|
||||
|
Loading…
Reference in New Issue
Block a user