Merge branch 'master' of git.etztech.xyz:24CarrotCraft/MinecraftManagerDjango into reminder

reminder
Etzelia 2019-11-21 20:03:05 -06:00
commit 32000792fb
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
11 changed files with 122 additions and 71 deletions

View File

@ -46,7 +46,7 @@ def clean(model, data):
attr = d
if '__' in d:
attr = d.split('__')[0]
if hasattr(model, attr):
if hasattr(model, attr) and attr != "api":
cleaned[d] = data[d]
return cleaned
@ -279,11 +279,13 @@ class PluginAPI(View):
json['message'] = "Updated {0}".format(post['username'])
elif "register" == keyword:
player = Player.objects.get(uuid=post['uuid'])
password = mcm_api.generate_password()
if player.auth_user:
json['status'] = False
json['message'] = "You are already registered. To change your password, contact an Admin."
player.auth_user.password = password
player.auth_user.is_active = True
player.auth_user.save()
json['message'] = password
else:
password = mcm_api.generate_password()
user = User.objects.create_user(username=player.username.lower(), password=password)
user.save()
player.auth_user = user

View File

@ -4,7 +4,8 @@ from django.contrib.auth.models import User
from django.db import close_old_connections
from minecraft_manager.api import api
from minecraft_manager.bot.utils import get_application, build_info
from minecraft_manager.bot.utils import get_application
from minecraft_manager.utils import build_application
from minecraft_manager.models import Application, Player
@ -79,6 +80,7 @@ class Commands(commands.Cog):
except:
is_id = False
application = None
if is_id:
application = get_application(key)
if not application:
@ -99,7 +101,7 @@ class Commands(commands.Cog):
if not found:
await self.bot.discord_message(ctx.message.channel, "An exact Application could not be found. Try search instead.")
return
await self.bot.discord_message(ctx.message.channel, build_info(application))
await self.bot.discord_message(ctx.message.channel, build_application(application))
@commands.command()
async def accept(self, ctx, app_id: int):
@ -164,7 +166,7 @@ class Commands(commands.Cog):
count = Application.objects.filter(username__icontains=search).count()
if count > 0:
if count == 1:
info = build_info(applications[0])
info = build_application(applications[0])
else:
info = "**Found the following applications**"
for app in applications:
@ -177,7 +179,7 @@ class Commands(commands.Cog):
if count > 0:
if count == 1:
await self.bot.discord_message(ctx.message.channel, "**No applications matched, however there is a player match**")
info = build_info(players[0].application)
info = build_application(players[0].application)
else:
info = "**No applications matched, however there are player matches**"
for player in players:

View File

@ -1,23 +1,4 @@
import discord
from minecraft_manager.models import Application, Player
def build_info(application):
embed = discord.Embed(colour=discord.Colour(0x417505))
embed.set_thumbnail(
url="https://minotar.net/helm/{0}/100.png".format(application.username))
embed.add_field(name="Application ID", value=application.id)
embed.add_field(name="Username", value=application.username.replace("_", "\\_"))
embed.add_field(name="Age", value=application.age)
embed.add_field(name="Type of Player", value=application.player_type)
embed.add_field(name="Ever been banned", value=application.ever_banned)
if application.ever_banned:
embed.add_field(name="Reason for being banned", value=application.ever_banned_explanation)
embed.add_field(name="Reference", value=application.reference)
embed.add_field(name="Read the Rules", value=application.read_rules)
embed.add_field(name="Date", value=application.date_display)
embed.add_field(name="Status", value=application.status)
return embed
from minecraft_manager.models import Application
def get_application(app_id):

File diff suppressed because one or more lines are too long

View File

@ -13,9 +13,6 @@ class MinecraftManagerUser(User):
class Meta:
proxy = True
permissions = (
('coreprotect_partial', 'Can use CoreProtect GUI except Command/Chat searches'),
('coreprotect_full', 'Can use full CoreProtect GUI'),
('coreprotect_activity', 'Can use CoreProtect Activity Monitor'),
('bots', 'Can use the bot control page'),
('chat', 'Can use chat page'),
)

View File

@ -1,12 +1,13 @@
{% extends "minecraft_manager/dashboard.html" %}
{% load template_settings %}
{% block title %}CoreProtect GUI{% endblock %}
{% block section %}
<a href="{% template_settings 'COREPROTECT_WEB_URL' %}?username={{ user.username }}" target="_blank">Fullscreen</a>
<iframe id="cpgui" width="100%" height="750px" src="{% template_settings 'COREPROTECT_WEB_URL' %}?username={{ user.username }}">Loading...</iframe>
<script>
var height = $(window).height();
//$("#cpgui").height(height * .8);
</script>
{% endblock section %}
{% if show_gui and show_activity %}
<li class="dropdown">
<a class="dropdown-toggle " href="#" role="button" data-toggle="dropdown" id="cpDropdown">CoreProtect</a>
<ul class="dropdown-menu" aria-labelledby="cpDropdown">
<li><a target="_blank" href="{{ url_gui }}">Web GUI</a></li>
<li><a target="_blank" href="{{ url_activity }}">Activity Monitor</a></li>
</ul>
</li>
{% elif show_gui %}
<li><a target="_blank" class="dropdown-item btn" href="{{ url_gui }}">CoreProtect GUI</a></li>
{% elif show_activity %}
<li><a target="_blank" class="dropdown-item btn" href="{{ url_activity }}">Activity Monitor</a></li>
{% endif %}

View File

@ -3,6 +3,7 @@
{% load csrf_html %}
{% load sidebar %}
{% load template_settings %}
{% load coreprotect %}
{% block bootstrap %}
{% if user.usersettings.default_theme == 'DA' %}
<link rel="stylesheet" href="{% static "minecraft_manager/css/bootswatch-darkly.css" %}">
@ -23,21 +24,7 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
{% template_settings 'COREPROTECT_WEB_URL' as CPW %}
{% template_settings 'COREPROTECT_ACTIVITY_URL' as CPA %}
{% if CPW %}
{% if perms.auth.coreprotect_activity and CPA %}
<li class="dropdown">
<a class="dropdown-toggle " href="#" role="button" data-toggle="dropdown" id="cpDropdown">CoreProtect</a>
<ul class="dropdown-menu" aria-labelledby="cpDropdown">
<li><a target="_blank" href="{{ CPW }}">Web GUI</a></li>
<li><a target="_blank" href="{{ CPA }}">Activity Monitor</a></li>
</ul>
</li>
{% elif perms.auth.coreprotect_partial or perms.auth.coreprotect_full %}
<li><a target="_blank" class="dropdown-item btn" href="{{ CPW }}">CoreProtect</a></li>
{% endif %}
{% endif %}
{% coreprotect %}
<li class="dropdown">
<a class="dropdown-toggle " href="#" role="button" data-toggle="dropdown" id="accountDropdown">{{ user.username }}</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="accountDropdown">

View File

@ -3,22 +3,37 @@
{% block title %}Overview{% endblock %}
{% block head %}
<script src="{% static 'minecraft_manager/js/chart.min.js' %}"></script>
<script>
$(document).ready(function() {
$(".staff-inactive").hide();
$("#active-only").change(function() {
if ($(this)[0].checked) {
$(".staff-inactive").hide();
} else {
$(".staff-inactive").show();
}
});
});
</script>
{% endblock %}
{% block section %}
<div id="content">
{% if request.user.is_staff %}
<div class="panel panel-danger">
<div class="panel-body">
<h4><span class="label label-danger">Admin Area</span></h4>
<h3>Resolved Tickets</h3>
<div class="row">
{% for staff in data.resolved %}
<div class="col-xs-6 col-md-4">
<p><span class="label label-{% if staff.active %}success{% else %}danger{% endif %}">{% if staff.active %}Active{% else %}Inactive{% endif %}</span> {{ staff.username }}: {{ staff.tickets }}</p>
<div class="panel-body">
<h4><span class="label label-danger">Admin Area</span></h4>
<h3>Resolved Tickets</h3>
<label>Active Only
<input id="active-only" type="checkbox" checked/>
</label>
<div class="row">
{% for staff in data.resolved %}
<div class="col-xs-6 col-md-4{% if not staff.active %} staff-inactive{% endif %}">
<p><span class="label label-{% if staff.active %}success{% else %}danger{% endif %}">{% if staff.active %}Active{% else %}Inactive{% endif %}</span> {{ staff.username }}: {{ staff.tickets }}</p>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<hr/>
{% endif %}

View File

@ -0,0 +1,20 @@
from django.template import Library
from django.shortcuts import reverse
register = Library()
@register.inclusion_tag('minecraft_manager/coreprotect.html', takes_context=True)
def coreprotect(context):
user = context.get("user", None)
data = {"show_gui": False, "show_activity": False, "url_gui": "", "url_activity": ""}
if user:
try:
data["show_gui"] = user.has_perm("django_coreprotect.gui")
data["url_gui"] = reverse("coreprotect_gui")
data["show_activity"] = user.has_perm("django_coreprotect.activity")
data["url_activity"] = reverse("coreprotect_activity")
except:
pass
return data

View File

@ -8,9 +8,6 @@ urlpatterns = [
#Dashboard
url(r'^dashboard/overview/$', login_required(mcm.Overview.as_view()), name="overview"),
url(r'^dashboard/ban/$', login_required(mcm.Ban.as_view()), name="ban"),
#CoreProtect
url(r'^dashboard/coreprotect/$', login_required(mcm.CoreProtect.as_view()), name="coreprotect"),
url(r'^dashboard/activity/$', login_required(mcm.Activity.as_view()), name="activity"),
#Alerts
url(r'^dashboard/alert/$', login_required(mcm.Alert.as_view()), name="alert"),
url(r'^dashboard/alert/(?P<alert_id>[0-9]{1,5})/$', login_required(mcm.AlertInfo.as_view())),

View File

@ -38,6 +38,7 @@ def build_application(application):
embed.add_field(name="Read the Rules", value=application.read_rules)
embed.add_field(name="Date", value=application.date_display)
embed.add_field(name="Status", value=application.status)
embed.add_field(name="Link", value="{}".format(url_path(settings.MCM_BASE_LINK, 'dashboard/application', application.id)))
return embed