Added models_api perm
+ This will be used for the model API and for Townffreydoc_update
parent
57f3d2fa83
commit
5c3010d233
|
@ -0,0 +1,17 @@
|
|||
from GeoffreyApp.models import APIToken
|
||||
|
||||
|
||||
def check_request_for_key(request):
|
||||
if "api" in request:
|
||||
key = request["api"]
|
||||
|
||||
return APIToken.objects.get(key=key)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def check_key(key, **kwargs):
|
||||
if APIToken.objects.filter(key=key, **kwargs).exists():
|
||||
return True
|
||||
else:
|
||||
return False
|
|
@ -6,24 +6,9 @@ import sys
|
|||
|
||||
from GeoffreyApp.api.commands import RequestTypes
|
||||
import GeoffreyApp.api.commands as commands
|
||||
from GeoffreyApp.api.key import check_request_for_key, check_key
|
||||
from GeoffreyApp.errors import *
|
||||
from GeoffreyApp.models import APIToken, PermissionLevel
|
||||
|
||||
|
||||
def check_key(key, **kwargs):
|
||||
if APIToken.objects.filter(key=key, **kwargs).exists():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def check_request_for_key(request):
|
||||
if "api" in request:
|
||||
key = request["api"]
|
||||
|
||||
return APIToken.objects.get(key=key)
|
||||
|
||||
return None
|
||||
from GeoffreyApp.models import PermissionLevel
|
||||
|
||||
|
||||
def run_command(request, command_name, req_type, key):
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from django.apps import AppConfig
|
||||
import os
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__)) + "/assets/bots/geoffrey.py"
|
||||
|
||||
|
||||
class GeoffreyAppConfig(AppConfig):
|
||||
name = 'GeoffreyApp'
|
||||
verbose_name = "Geoffrey: Minecraft Web Database"
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.2 on 2019-09-17 16:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('GeoffreyApp', '0002_auto_20190818_0116'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='apitoken',
|
||||
name='model_api_perm',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -41,6 +41,11 @@ class APIToken(models.Model):
|
|||
Permission to use admin commands
|
||||
"""
|
||||
|
||||
model_api_perm = models.BooleanField(default=False)
|
||||
"""
|
||||
Permission to access the model api
|
||||
"""
|
||||
|
||||
def has_command_permission(self, permission_level):
|
||||
if permission_level == PermissionLevel.ADMIN:
|
||||
return self.admin_commands_perm
|
||||
|
|
Loading…
Reference in New Issue