Added models_api perm

+ This will be used for the model API and for Townffrey
doc_update
Joey Hines 2019-09-17 11:23:47 -05:00
parent 57f3d2fa83
commit 5c3010d233
5 changed files with 44 additions and 20 deletions

View File

@ -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

View File

@ -6,24 +6,9 @@ import sys
from GeoffreyApp.api.commands import RequestTypes from GeoffreyApp.api.commands import RequestTypes
import GeoffreyApp.api.commands as commands import GeoffreyApp.api.commands as commands
from GeoffreyApp.api.key import check_request_for_key, check_key
from GeoffreyApp.errors import * from GeoffreyApp.errors import *
from GeoffreyApp.models import APIToken, PermissionLevel from GeoffreyApp.models import 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
def run_command(request, command_name, req_type, key): def run_command(request, command_name, req_type, key):

View File

@ -1,9 +1,8 @@
from django.apps import AppConfig from django.apps import AppConfig
import os
path = os.path.dirname(os.path.abspath(__file__)) + "/assets/bots/geoffrey.py"
class GeoffreyAppConfig(AppConfig): class GeoffreyAppConfig(AppConfig):
name = 'GeoffreyApp' name = 'GeoffreyApp'
verbose_name = "Geoffrey: Minecraft Web Database" verbose_name = "Geoffrey: Minecraft Web Database"

View File

@ -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),
),
]

View File

@ -41,6 +41,11 @@ class APIToken(models.Model):
Permission to use admin commands 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): def has_command_permission(self, permission_level):
if permission_level == PermissionLevel.ADMIN: if permission_level == PermissionLevel.ADMIN:
return self.admin_commands_perm return self.admin_commands_perm