From 17739129d3725f56545c3ffbc3fc2f61304ec000 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 13 May 2015 12:16:51 +0000 Subject: [PATCH] Random fixes --- TODO.md | 7 ++--- orchestra/contrib/orchestration/admin.py | 11 ++++--- orchestra/contrib/orchestration/manager.py | 8 ++--- .../migrations/0003_auto_20150512_1512.py | 30 +++++++++++++++++++ orchestra/contrib/orchestration/models.py | 15 +++++++++- orchestra/contrib/services/handlers.py | 2 ++ orchestra/contrib/systemusers/actions.py | 9 +++--- orchestra/contrib/systemusers/backends.py | 13 ++++---- orchestra/contrib/systemusers/filters.py | 6 ++-- orchestra/contrib/systemusers/forms.py | 7 +++-- orchestra/contrib/systemusers/models.py | 13 ++++++++ orchestra/contrib/webapps/types/php.py | 6 ++-- orchestra/core/caches.py | 2 +- 13 files changed, 92 insertions(+), 37 deletions(-) create mode 100644 orchestra/contrib/orchestration/migrations/0003_auto_20150512_1512.py diff --git a/TODO.md b/TODO.md index 12195713..6e75682b 100644 --- a/TODO.md +++ b/TODO.md @@ -340,7 +340,7 @@ TODO mount the filesystem with "nosuid" option # smtplib.SMTPConnectError: (421, b'4.7.0 mail.pangea.org Error: too many connections from 77.246.181.209') # rename virtual_maps to virtual_alias_maps and remove virtual_alias_domains ? -# virtdomains file is not ideal, prevent fake/error on domains there! and make sure this file is required! +# virtdomains file is not ideal, prevent fake/error on domains there! and make sure to chekc if this file is required! # Deprecate restart/start/stop services (do touch wsgi.py and fuck celery) orchestra-beat support for uwsgi cron @@ -353,11 +353,10 @@ make django admin taskstate uncollapse fucking traceback, ( if exists ?) resorce monitoring more efficient, less mem an better queries for calc current data -# best_price rating method +# test best_price rating method # bill this https://orchestra.pangea.org/admin/orders/order/8236/ should be already billed, <= vs < # Convert rating method from function to PluginClass # Tests can not run because django.db.utils.ProgrammingError: relation "accounts_account" does not exist - - +# autoresponses on mailboxes, not addresses or remove them diff --git a/orchestra/contrib/orchestration/admin.py b/orchestra/contrib/orchestration/admin.py index 456a2e9d..dc655d8b 100644 --- a/orchestra/contrib/orchestration/admin.py +++ b/orchestra/contrib/orchestration/admin.py @@ -92,12 +92,11 @@ class BackendOperationInline(admin.TabularInline): } def instance_link(self, operation): - try: - return admin_link('instance')(self, operation) - except: - return _("deleted {0} {1}").format( - escape(operation.content_type), escape(operation.object_id) - ) + link = admin_link('instance')(self, operation) + if not link.startswith('= bp: + continue order.new_billed_until = bp ini = min(ini, cini) end = max(end, bp) diff --git a/orchestra/contrib/systemusers/actions.py b/orchestra/contrib/systemusers/actions.py index 29190a71..f2ae474c 100644 --- a/orchestra/contrib/systemusers/actions.py +++ b/orchestra/contrib/systemusers/actions.py @@ -33,10 +33,11 @@ def set_permission(modeladmin, request, queryset): cleaned_data = form.cleaned_data operations = [] for user in queryset: - user.set_perm_action = cleaned_data['set_action'] - user.set_perm_base_home = cleaned_data['base_home'] - user.set_perm_home_extension = cleaned_data['home_extension'] - user.set_perm_perms = cleaned_data['permissions'] + base_home = cleaned_data['base_home'] + extension = cleaned_data['home_extension'] + action = cleaned_data['set_action'] + perms = cleaned_data['permissions'] + user.set_permission(base_home, extension, action=action, perms=perms) operations.extend(Operation.create_for_action(user, 'set_permission')) verbose_action = get_verbose_choice(form.fields['set_action'].choices, user.set_perm_action) diff --git a/orchestra/contrib/systemusers/backends.py b/orchestra/contrib/systemusers/backends.py index 13179a0a..4cca82f2 100644 --- a/orchestra/contrib/systemusers/backends.py +++ b/orchestra/contrib/systemusers/backends.py @@ -86,14 +86,14 @@ class UNIXUserBackend(ServiceController): }) exclude_acl = [] for exclude in settings.SYSTEMUSERS_FORBIDDEN_PATHS: - context['exclude_acl'] = exclude - exclude_acl.append('-not -path "%(perm_to)s/%(exclude_acl)s"' % context) + context['exclude_acl'] = os.path.join(context['perm_home'], exclude) + exclude_acl.append('-not -path "%(exclude_acl)s"' % context) context['exclude_acl'] = ' \\\n -a '.join(exclude_acl) if exclude_acl else '' - if user.set_perm_perms == 'read-write': + if user.set_perm_perms == 'rw': context['perm_perms'] = 'rwx' if user.set_perm_action == 'grant' else '---' - elif user.set_perm_perms == 'read-only': + elif user.set_perm_perms == 'r': context['perm_perms'] = 'r-x' if user.set_perm_action == 'grant' else '-wx' - elif user.set_perm_perms == 'write-only': + elif user.set_perm_perms == 'w': context['perm_perms'] = '-wx' if user.set_perm_action == 'grant' else 'r-x' if user.set_perm_action == 'grant': self.append(textwrap.dedent("""\ @@ -105,8 +105,7 @@ class UNIXUserBackend(ServiceController): find '%(perm_to)s' -type d %(exclude_acl)s \\ -exec setfacl -m d:u:%(user)s:%(perm_perms)s {} \\; # Account group as the owner of new files - chmod g+s '%(perm_to)s' - """) % context + chmod g+s '%(perm_to)s'""") % context ) if not user.is_main: self.append(textwrap.dedent("""\ diff --git a/orchestra/contrib/systemusers/filters.py b/orchestra/contrib/systemusers/filters.py index 1e78a1d9..8e619a49 100644 --- a/orchestra/contrib/systemusers/filters.py +++ b/orchestra/contrib/systemusers/filters.py @@ -1,5 +1,4 @@ from django.contrib.admin import SimpleListFilter -from django.db.models import F from django.utils.translation import ugettext_lazy as _ @@ -16,7 +15,6 @@ class IsMainListFilter(SimpleListFilter): def queryset(self, request, queryset): if self.value() == 'True': - return queryset.filter(account__main_systemuser_id=F('id')) + return queryset.by_is_main() if self.value() == 'False': - return queryset.exclude(account__main_systemuser_id=F('id')) - + return queryset.by_is_main(is_main=False) diff --git a/orchestra/contrib/systemusers/forms.py b/orchestra/contrib/systemusers/forms.py index 6340444e..cfca1b57 100644 --- a/orchestra/contrib/systemusers/forms.py +++ b/orchestra/contrib/systemusers/forms.py @@ -1,3 +1,4 @@ +import os import textwrap from django import forms @@ -94,9 +95,9 @@ class PermissionForm(forms.Form): widget=forms.TextInput(attrs={'size':'70'}), help_text=_("Relative to chosen home.")) permissions = forms.ChoiceField(label=_("Permissions"), initial='read-write', choices=( - ('read-write', _("Read and write")), - ('read-only', _("Read only")), - ('write-only', _("Write only")) + ('rw', _("Read and write")), + ('r', _("Read only")), + ('w', _("Write only")) )) def __init__(self, *args, **kwargs): diff --git a/orchestra/contrib/systemusers/models.py b/orchestra/contrib/systemusers/models.py index ca3f2df1..29419b83 100644 --- a/orchestra/contrib/systemusers/models.py +++ b/orchestra/contrib/systemusers/models.py @@ -4,6 +4,7 @@ import os from django.contrib.auth.hashers import make_password from django.core.exceptions import ValidationError from django.db import models +from django.db.models import F from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ @@ -18,6 +19,12 @@ class SystemUserQuerySet(models.QuerySet): user.set_password(password) user.save(update_fields=['password']) return user + + def by_is_main(self, is_main=True, **kwargs): + if is_main: + return self.filter(account__main_systemuser_id=F('id')) + else: + return self.exclude(account__main_systemuser_id=F('id')) class SystemUser(models.Model): @@ -112,6 +119,12 @@ class SystemUser(models.Model): def set_password(self, raw_password): self.password = make_password(raw_password) + def set_permission(self, base_home, extension, perms='rw', action='grant'): + self.set_perm_action = action + self.set_perm_base_home = base_home + self.set_perm_home_extension = extension + self.set_perm_perms = perms + def get_base_home(self): context = { 'user': self.username, diff --git a/orchestra/contrib/webapps/types/php.py b/orchestra/contrib/webapps/types/php.py index 44f41f61..a79a7e18 100644 --- a/orchestra/contrib/webapps/types/php.py +++ b/orchestra/contrib/webapps/types/php.py @@ -82,8 +82,10 @@ class PHPApp(AppType): options += list(webapp.options.all()) init_vars = OrderedDict((opt.name, opt.value) for opt in options) # Enable functions - enable_functions = init_vars.pop('enable_functions', None) - if enable_functions: + enable_functions = init_vars.pop('enable_functions', '') + if enable_functions or self.is_fpm: + # FPM: Defining 'disable_functions' or 'disable_classes' will not overwrite previously + # defined php.ini values, but will append the new value enable_functions = set(enable_functions.split(',')) disable_functions = [] for function in self.PHP_DISABLED_FUNCTIONS: diff --git a/orchestra/core/caches.py b/orchestra/core/caches.py index 15e8d826..4550d827 100644 --- a/orchestra/core/caches.py +++ b/orchestra/core/caches.py @@ -27,7 +27,7 @@ def get_request_cache(): class RequestCacheMiddleware(object): def process_request(self, request): - cache = _request_cache.get(currentThread()) or RequestCache() + cache = _request_cache.get(currentThread(), RequestCache()) _request_cache[currentThread()] = cache cache.clear()