Skip to content

Commit

Permalink
Release 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Apr 22, 2022
2 parents c877c9b + 9acda56 commit 2216ee4
Show file tree
Hide file tree
Showing 183 changed files with 6,456 additions and 5,116 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ services:
image: postgres:13-alpine
restart: always
environment:
POSTGRES_DB: tacticalrmm
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASS}
volumes:
Expand All @@ -120,7 +120,7 @@ services:
container_name: trmm-redis-dev
restart: always
user: 1000:1000
command: redis-server --appendonly yes
command: redis-server
image: redis:6.0-alpine
volumes:
- redis-data-dev:/data
Expand All @@ -145,6 +145,7 @@ services:
TRMM_PASS: ${TRMM_PASS}
HTTP_PROTOCOL: ${HTTP_PROTOCOL}
APP_PORT: ${APP_PORT}
POSTGRES_DB: ${POSTGRES_DB}
depends_on:
- postgres-dev
- meshcentral-dev
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ DEBUG = True
DOCKER_BUILD = True
SWAGGER_ENABLED = True
CERT_FILE = '${CERT_PUB_PATH}'
KEY_FILE = '${CERT_PRIV_PATH}'
Expand Down Expand Up @@ -94,6 +96,7 @@ EOF
echo "${localvars}" > ${WORKSPACE_DIR}/api/tacticalrmm/tacticalrmm/local_settings.py

# run migrations and init scripts
"${VIRTUAL_ENV}"/bin/python manage.py pre_update_tasks
"${VIRTUAL_ENV}"/bin/python manage.py migrate --no-input
"${VIRTUAL_ENV}"/bin/python manage.py collectstatic --no-input
"${VIRTUAL_ENV}"/bin/python manage.py initial_db_setup
Expand Down
35 changes: 20 additions & 15 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
# To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file
asgiref==3.5.0
celery==5.2.3
celery==5.2.6
channels==3.0.4
channels_redis==3.3.1
channels_redis==3.4.0
daphne==3.0.2
Django==3.2.12
Django==4.0.4
django-cors-headers==3.11.0
django-ipware==4.0.2
django-rest-knox==4.2.0
djangorestframework==3.13.1
future==0.18.2
msgpack==1.0.3
nats-py==2.0.0
nats-py==2.1.0
packaging==21.3
psycopg2-binary==2.9.3
pycryptodome==3.14.1
pyotp==2.6.0
pytz==2021.3
pytz==2022.1
qrcode==7.3.1
redis==4.1.3
redis==4.2.2
requests==2.27.1
twilio==7.6.0
urllib3==1.26.8
twilio==7.8.1
urllib3==1.26.9
validators==0.18.2
websockets==10.1
drf_spectacular==0.21.2
websockets==10.2
drf_spectacular==0.22.0
meshctrl==0.1.15
hiredis==2.0.0

# dev
black==22.1.0
Werkzeug==2.0.2
black==22.3.0
django-extensions==3.1.5
Pygments==2.11.2
isort==5.10.1
mypy==0.931
types-pytz==2021.3.4
mypy==0.942
types-pytz==2021.3.6
model-bakery==1.5.0
coverage==6.3.2
django-silk==4.3.0
django-stubs==1.10.1
djangorestframework-stubs==1.5.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ run_go_cmd.py
nats-api.conf
ignore/
coverage.lcov
daphne.sock.lock
20 changes: 19 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "error",
"reportDuplicateImport": "error",
"reportGeneralTypeIssues": "none"
},
"python.analysis.typeCheckingMode": "basic",
"mypy.runUsingActiveInterpreter": true,
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.mypyArgs": [
"--ignore-missing-imports",
"--follow-imports=silent",
"--show-column-numbers",
"--strict"
],
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"vetur.format.defaultFormatter.js": "prettier",
Expand Down Expand Up @@ -64,5 +74,13 @@
"usePlaceholders": true,
"completeUnimported": true,
"staticcheck": true,
}
},
"mypy.targets": [
"api/tacticalrmm"
],
"python.linting.ignorePatterns": [
"**/site-packages/**/*.py",
".vscode/*.py",
"**env/**"
]
}
23 changes: 0 additions & 23 deletions .vscode/tasks.json

This file was deleted.

18 changes: 18 additions & 0 deletions api/tacticalrmm/accounts/migrations/0031_user_date_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-04-02 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0030_auto_20211104_0221'),
]

operations = [
migrations.AddField(
model_name='user',
name='date_format',
field=models.CharField(blank=True, max_length=30, null=True),
),
]
29 changes: 29 additions & 0 deletions api/tacticalrmm/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.db.models.fields import CharField, DateTimeField
from django.core.cache import cache
from logs.models import BaseAuditModel

from typing import Optional

from tacticalrmm.constants import ROLE_CACHE_PREFIX

AGENT_DBLCLICK_CHOICES = [
("editagent", "Edit Agent"),
("takecontrol", "Take Control"),
Expand Down Expand Up @@ -48,6 +53,7 @@ class User(AbstractUser, BaseAuditModel):
client_tree_splitter = models.PositiveIntegerField(default=11)
loading_bar_color = models.CharField(max_length=255, default="red")
clear_search_when_switching = models.BooleanField(default=True)
date_format = models.CharField(max_length=30, blank=True, null=True)
is_installer_user = models.BooleanField(default=False)
last_login_ip = models.GenericIPAddressField(default=None, blank=True, null=True)

Expand All @@ -74,6 +80,23 @@ def serialize(user):

return UserSerializer(user).data

def get_and_set_role_cache(self) -> "Optional[Role]":
role = cache.get(f"{ROLE_CACHE_PREFIX}{self.role}")

if role and isinstance(role, Role):
return role
elif not role and not self.role:
return None
else:
models.prefetch_related_objects(
[self.role],
"can_view_clients",
"can_view_sites",
)

cache.set(f"{ROLE_CACHE_PREFIX}{self.role}", self.role, 600)
return self.role


class Role(BaseAuditModel):
name = models.CharField(max_length=255, unique=True)
Expand Down Expand Up @@ -174,6 +197,12 @@ class Role(BaseAuditModel):
def __str__(self):
return self.name

def save(self, *args, **kwargs) -> None:

# delete cache on save
cache.delete(f"{ROLE_CACHE_PREFIX}{self.name}")
super(BaseAuditModel, self).save(*args, **kwargs)

@staticmethod
def serialize(role):
# serializes the agent and returns json
Expand Down
6 changes: 3 additions & 3 deletions api/tacticalrmm/accounts/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class AccountsPerms(permissions.BasePermission):
def has_permission(self, r, view):
def has_permission(self, r, view) -> bool:
if r.method == "GET":
return _has_perm(r, "can_list_accounts")
else:
Expand All @@ -28,15 +28,15 @@ def has_permission(self, r, view):


class RolesPerms(permissions.BasePermission):
def has_permission(self, r, view):
def has_permission(self, r, view) -> bool:
if r.method == "GET":
return _has_perm(r, "can_list_roles")
else:
return _has_perm(r, "can_manage_roles")


class APIKeyPerms(permissions.BasePermission):
def has_permission(self, r, view):
def has_permission(self, r, view) -> bool:
if r.method == "GET":
return _has_perm(r, "can_list_api_keys")

Expand Down
2 changes: 2 additions & 0 deletions api/tacticalrmm/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Meta:
"loading_bar_color",
"clear_search_when_switching",
"block_dashboard_login",
"date_format",
]


Expand All @@ -39,6 +40,7 @@ class Meta:
"last_login_ip",
"role",
"block_dashboard_login",
"date_format",
]


Expand Down
16 changes: 8 additions & 8 deletions api/tacticalrmm/accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TestAccounts(TacticalTestCase):
def setUp(self):
self.client_setup()
self.setup_client()
self.bob = User(username="bob")
self.bob.set_password("hunter2")
self.bob.save()
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_get_api_keys(self):
serializer = APIKeySerializer(apikeys, many=True)
resp = self.client.get(url, format="json")
self.assertEqual(resp.status_code, 200)
self.assertEqual(serializer.data, resp.data) # type: ignore
self.assertEqual(serializer.data, resp.data)

self.check_not_authenticated("get", url)

Expand All @@ -331,13 +331,13 @@ def test_modify_api_key(self):
self.assertEqual(resp.status_code, 404)

apikey = baker.make("accounts.APIKey", name="Test")
url = f"/accounts/apikeys/{apikey.pk}/" # type: ignore
url = f"/accounts/apikeys/{apikey.pk}/"

data = {"name": "New Name"} # type: ignore
data = {"name": "New Name"}

resp = self.client.put(url, data, format="json")
self.assertEqual(resp.status_code, 200)
apikey = APIKey.objects.get(pk=apikey.pk) # type: ignore
apikey = APIKey.objects.get(pk=apikey.pk)
self.assertEquals(apikey.name, "New Name")

self.check_not_authenticated("put", url)
Expand All @@ -349,11 +349,11 @@ def test_delete_api_key(self):

# test delete api key
apikey = baker.make("accounts.APIKey")
url = f"/accounts/apikeys/{apikey.pk}/" # type: ignore
url = f"/accounts/apikeys/{apikey.pk}/"
resp = self.client.delete(url, format="json")
self.assertEqual(resp.status_code, 200)

self.assertFalse(APIKey.objects.filter(pk=apikey.pk).exists()) # type: ignore
self.assertFalse(APIKey.objects.filter(pk=apikey.pk).exists())

self.check_not_authenticated("delete", url)

Expand Down Expand Up @@ -393,7 +393,7 @@ def setUp(self):
name="Test Token", key="123456", user=self.user
)

self.client_setup()
self.setup_client()

def test_api_auth(self):
url = "/clients/"
Expand Down
3 changes: 2 additions & 1 deletion api/tacticalrmm/agents/management/commands/demo_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random

from agents.models import Agent
from core.tasks import cache_db_fields_task
from core.tasks import cache_db_fields_task, handle_resolved_stuff
from django.core.management.base import BaseCommand
from django.utils import timezone as djangotime

Expand Down Expand Up @@ -37,3 +37,4 @@ def handle(self, *args, **kwargs):
agent.save(update_fields=["last_seen"])

cache_db_fields_task()
handle_resolved_stuff()
Loading

0 comments on commit 2216ee4

Please sign in to comment.