Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.10 #3814

Merged
merged 51 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
cf4c6f6
Update to Django 1.9
matyldv Apr 25, 2024
d0d7511
Fix some tests
matyldv Apr 29, 2024
c5d72e6
Fix sitetree
matyldv Apr 29, 2024
6543ef4
Fix permissions
matyldv Apr 30, 2024
4d7d82d
Fix RalphAdminChecks
matyldv May 2, 2024
3f09ecc
Fix isort
matyldv May 2, 2024
a521074
Fix user_password_change and bump pyflakes
matyldv May 2, 2024
3028f8d
Fix some tests and flake
matyldv May 2, 2024
1fabbf6
Fix lookup
hipek8 May 6, 2024
7afc621
Add missing migrations
hipek8 May 6, 2024
b64efa4
Fix flake
hipek8 May 6, 2024
a07bc6c
Fix managers in migrations. Fix error with content type id
hipek8 May 6, 2024
dcfcb53
Fix
hipek8 May 6, 2024
63f897b
Fix data_importer tests
hipek8 May 6, 2024
bb2c870
Clean up migrations
hipek8 May 6, 2024
5bd289e
WIP - migrate from deprectated get_...
hipek8 May 7, 2024
37ece5a
cleanup
awieckowski May 7, 2024
21c4657
cleanup
awieckowski May 7, 2024
e97463e
cleanup
awieckowski May 7, 2024
aff1f47
Bump dependencies
hipek8 May 8, 2024
d17ae9f
Adjust import-export
hipek8 May 8, 2024
095c29c
Adjust django-money ver
hipek8 May 8, 2024
da8060f
Fix render
hipek8 May 8, 2024
6263431
Merge branch 'ng' of github.com:allegro/ralph into update-to-django-1-9
matyldv May 9, 2024
664222d
Fix imports
matyldv May 10, 2024
7f7723e
Fix ldap imports
matyldv May 13, 2024
9a5ee25
Merge branch 'update-to-django-1-9' of github.com:matyldv/ralph into …
awieckowski May 13, 2024
5809f3d
Fix reversion import and bump Django
matyldv May 13, 2024
7e80230
fix PermissionsForObjectMixin
awieckowski May 14, 2024
529ccd5
Fix 500 when sorting ContentType
hipek8 May 14, 2024
5351b00
Fix icon-unknown
matyldv May 14, 2024
152d3ca
Merge branch 'update-to-django-1-9' of github.com:allegro/ralph into …
awieckowski May 14, 2024
e4ab786
Merge branch 'update-to-django-1-10' of github.com:allegro/ralph into…
awieckowski May 14, 2024
8a917a7
Fix invalid literal for int() with base 10: 'PL'
hipek8 May 14, 2024
812d666
Fix set country
hipek8 May 14, 2024
a2049a1
fix conflicts
awieckowski May 14, 2024
1eb6ee9
fix flake, fix ImportForeignKeyMixin
awieckowski May 14, 2024
9f410fd
fix data importer widgets
awieckowski May 14, 2024
daa8310
Fix django-import-export compatibility
hipek8 May 15, 2024
3965ff0
Build for any push
hipek8 May 15, 2024
79eea79
Fix non-relational field in select_related
hipek8 May 15, 2024
1112b75
Fix bad manager by making them even worse
hipek8 May 16, 2024
d5d2ea0
Adjust num queries
hipek8 May 16, 2024
7a11b0e
Fix line length
hipek8 May 16, 2024
9ad9540
Fix popup_response
matyldv May 17, 2024
c4dff78
Fix network terminators
matyldv Jun 3, 2024
d5e5cbe
Fix IPNetwork to_python
matyldv Jun 3, 2024
d4d3ee8
Merge branch 'ng' into update-to-django-1-10
hipek8 Jun 12, 2024
3978c13
Add test for dhcp config format
hipek8 Jul 2, 2024
d00a1a6
remove removed middleware imports
hipek8 Jul 2, 2024
160156c
Remove WrappedOperationalError occurrence
hipek8 Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ name: CI
# push or pull request events but only for the ng branch
on:
push:
branches: [ ng ]
pull_request:
branches: [ ng ]

Expand Down
16 changes: 7 additions & 9 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
-r openstack.txt
-r hermes.txt
Django==1.8.19
Django==1.10.8
dj.choices==0.11.0
django-extensions==1.7.5
django-filter==0.13.0
django-import-export==0.4.2
django-money==0.15.1
django-import-export==1.2.0
django-money==0.12
py-moneyed==1.2
django-mptt==0.8.7
django-reversion==1.8.6
django-reversion==2.0
django-rq==2.0
django-sitetree==1.7.0
django-taggit==0.17.1
django-taggit-serializer==0.1.5
django-taggit==0.22.2
django-taggit-serializer==0.1.7
django-threadlocals==0.8
django-transaction-hooks==0.2 # it's merged to Django 1.9 - remove this when Django version will be bumped to 1.9
django-cryptography==0.3
djangorestframework==3.2.2
djangorestframework==3.4.0
djangorestframework_xml==1.2.0
drf-nested-routers==0.11.1
Markdown<3.0 # headerid extension removed in 3.0 - see #3313 for details
Expand All @@ -37,4 +36,3 @@ Faker==0.9.0
openpyxl==2.4.0
typing==3.6.6
Pillow==6.2.2

3 changes: 2 additions & 1 deletion requirements/code_style.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flake8==3.0.4
isort==4.2.5
isort==4.2.5
pyflakes==1.5.0
3 changes: 2 additions & 1 deletion src/ralph/access_cards/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.utils.translation import ugettext_lazy as _

from ralph.access_cards.models import AccessCard, AccessZone
from ralph.admin import RalphAdmin, RalphMPTTAdmin, register
from ralph.admin.decorators import register
from ralph.admin.mixins import RalphAdmin, RalphMPTTAdmin
from ralph.lib.transitions.admin import TransitionAdminMixin


Expand Down
3 changes: 2 additions & 1 deletion src/ralph/accessories/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.utils.translation import ugettext_lazy as _

from ralph.accessories.models import Accessory, AccessoryUser
from ralph.admin import RalphAdmin, RalphTabularInline, register
from ralph.admin.decorators import register
from ralph.admin.mixins import RalphAdmin, RalphTabularInline
from ralph.admin.views.extra import RalphDetailViewAdmin
from ralph.lib.transitions.admin import TransitionAdminMixin

Expand Down
3 changes: 2 additions & 1 deletion src/ralph/accessories/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import reversion
from dj.choices import Choices
from django import forms
from django.conf import settings
Expand All @@ -8,6 +7,7 @@
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from mptt.fields import TreeForeignKey
from reversion import revisions as reversion

from ralph.accounts.models import RalphUser, Regionalizable
from ralph.assets.models import Category, Manufacturer
Expand All @@ -18,6 +18,7 @@
from ralph.lib.transitions.fields import TransitionField
from ralph.lib.transitions.models import TransitionWorkflowBaseWithPermissions


_SELECT_USED_ACCESSORY_QUERY = """
SELECT COALESCE(SUM({assignment_table}.{quantity_column}), 0)
FROM {assignment_table}
Expand Down
11 changes: 6 additions & 5 deletions src/ralph/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
from django.forms.models import model_to_dict
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from reversion import revisions as reversion

from ralph.accounts.models import RalphUser, Region, Team
from ralph.admin import RalphAdmin, register
from ralph.admin.decorators import register
from ralph.admin.helpers import getattr_dunder
from ralph.admin.mixins import RalphAdminFormMixin
from ralph.admin.mixins import RalphAdmin, RalphAdminFormMixin
from ralph.admin.views.extra import RalphDetailView
from ralph.back_office.models import BackOfficeAsset, BackOfficeAssetStatus
from ralph.lib.table import Table
from ralph.lib.table.table import Table
from ralph.lib.transitions.models import TransitionsHistory
from ralph.licences.models import Licence
from ralph.sim_cards.models import SIMCard
Expand Down Expand Up @@ -338,8 +339,8 @@ def user_change_password(self, request, id, form_url=''):

if not self.has_change_permission(request, obj=user):
raise PermissionDenied

return super().user_change_password(request, id, form_url)
with reversion.create_revision():
return super().user_change_password(request, id, form_url)


@register(Group)
Expand Down
87 changes: 0 additions & 87 deletions src/ralph/accounts/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from django.dispatch import receiver
from django.utils.encoding import force_text
from django_auth_ldap.backend import _LDAPUser, LDAPSettings, populate_user
from django_auth_ldap.config import ActiveDirectoryGroupType

from ralph.accounts.management.commands.ldap_sync import get_nested_groups

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -102,87 +99,3 @@ def manager_country_attribute_populate(
user.country = Country.id_from_name(country.lower())
except ValueError:
user.country = None


class MappedGroupOfNamesType(ActiveDirectoryGroupType):
"""Provide group mappings described in project settings."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._ldap_groups = None

@property
def ldap_groups(self):
"""
Composition of flat LDAP groups (taken from `AUTH_LDAP_GROUP_MAPPING`)
and nested groups (taken from `AUTH_LDAP_NESTED_GROUPS`).

Returns: dict with both flat and nested LDAP groups.
"""
if not self._ldap_groups:
logger.debug('Evaluating LDAP groupd from settings')
self._ldap_flat_groups = getattr(
settings, 'AUTH_LDAP_GROUP_MAPPING', {}
)
self._ldap_nested_groups = getattr(
settings, 'AUTH_LDAP_NESTED_GROUPS', {}
)
self._ldap_groups = self._ldap_flat_groups.copy()
self._ldap_groups.update(self._ldap_nested_groups)
return self._ldap_groups

def _get_group(self, group_dn, ldap_user, group_search):
base_dn = group_search.base_dn
group_search.base_dn = force_text(group_dn)
group = group_search.execute(ldap_user.connection)[0]
group_search.base_dn = base_dn
return group

def user_groups(self, ldap_user, group_search):
"""Get groups which user belongs to."""
group_map = []

def handle_groups(groups_dns):
"""
Compare user groups with groups accepted by Ralph
(`self.ldap_groups`) and for each in common get LDAP group

Args:
groups_dns: set of user groups DNs
"""
for group_dn in groups_dns & set(self.ldap_groups.keys()):
group = self._get_group(group_dn, ldap_user, group_search)
group_map.append(group)

username = ldap_user.attrs[settings.AUTH_LDAP_USER_USERNAME_ATTR][0]

# handle flat groups first (to which user belongs directly)
try:
flat_groups_dns = set(map(force_text, ldap_user.attrs['memberOf']))
except KeyError:
flat_groups_dns = set()
logger.info('Flat groups DNs for {}: {}'.format(
username, flat_groups_dns
))
handle_groups(flat_groups_dns)

# handle nested groups
nested_groups_dns = get_nested_groups()[1].get(username, set())
logger.info('Nested groups DNs for {}: {}'.format(
username, nested_groups_dns
))
handle_groups(nested_groups_dns)
return group_map

def group_name_from_info(self, group_info):
"""Map ldap group names into ralph names if mapping defined."""
if self.ldap_groups:
for dn in group_info[1]['distinguishedname']:
mapped = self.ldap_groups.get(dn)
if mapped:
return mapped
# return original name if mapping not defined
else:
return super(
MappedGroupOfNamesType,
self
).group_name_from_info(group_info)
93 changes: 93 additions & 0 deletions src/ralph/accounts/ldap_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
import logging

from django.conf import settings
from django.utils.encoding import force_text
from django_auth_ldap.config import ActiveDirectoryGroupType


logger = logging.getLogger(__name__)


class MappedGroupOfNamesType(ActiveDirectoryGroupType):
"""Provide group mappings described in project settings."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._ldap_groups = None

@property
def ldap_groups(self):
"""
Composition of flat LDAP groups (taken from `AUTH_LDAP_GROUP_MAPPING`)
and nested groups (taken from `AUTH_LDAP_NESTED_GROUPS`).

Returns: dict with both flat and nested LDAP groups.
"""
if not self._ldap_groups:
logger.debug('Evaluating LDAP groupd from settings')
self._ldap_flat_groups = getattr(
settings, 'AUTH_LDAP_GROUP_MAPPING', {}
)
self._ldap_nested_groups = getattr(
settings, 'AUTH_LDAP_NESTED_GROUPS', {}
)
self._ldap_groups = self._ldap_flat_groups.copy()
self._ldap_groups.update(self._ldap_nested_groups)
return self._ldap_groups

def _get_group(self, group_dn, ldap_user, group_search):
base_dn = group_search.base_dn
group_search.base_dn = force_text(group_dn)
group = group_search.execute(ldap_user.connection)[0]
group_search.base_dn = base_dn
return group

def user_groups(self, ldap_user, group_search):
"""Get groups which user belongs to."""
group_map = []

def handle_groups(groups_dns):
"""
Compare user groups with groups accepted by Ralph
(`self.ldap_groups`) and for each in common get LDAP group

Args:
groups_dns: set of user groups DNs
"""
for group_dn in groups_dns & set(self.ldap_groups.keys()):
group = self._get_group(group_dn, ldap_user, group_search)
group_map.append(group)

username = ldap_user.attrs[settings.AUTH_LDAP_USER_USERNAME_ATTR][0]

# handle flat groups first (to which user belongs directly)
try:
flat_groups_dns = set(map(force_text, ldap_user.attrs['memberOf']))
except KeyError:
flat_groups_dns = set()
logger.info('Flat groups DNs for {}: {}'.format(
username, flat_groups_dns
))
handle_groups(flat_groups_dns)
from ralph.accounts.management.commands.ldap_sync import get_nested_groups # noqa
# handle nested groups
nested_groups_dns = get_nested_groups()[1].get(username, set())
logger.info('Nested groups DNs for {}: {}'.format(
username, nested_groups_dns
))
handle_groups(nested_groups_dns)
return group_map

def group_name_from_info(self, group_info):
"""Map ldap group names into ralph names if mapping defined."""
if self.ldap_groups:
for dn in group_info[1]['distinguishedname']:
mapped = self.ldap_groups.get(dn)
if mapped:
return mapped
# return original name if mapping not defined
else:
return super(
MappedGroupOfNamesType,
self
).group_name_from_info(group_info)
21 changes: 21 additions & 0 deletions src/ralph/accounts/migrations/0007_auto_20240506_1128.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2024-05-06 11:28
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0006_remove_ralphuser_gender'),
]

operations = [
migrations.AlterField(
model_name='ralphuser',
name='username',
field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=30, unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.')], verbose_name='username'),
),
]
21 changes: 21 additions & 0 deletions src/ralph/accounts/migrations/0008_auto_20240507_1422.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2024-05-07 14:22
from __future__ import unicode_literals

import django.contrib.auth.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0007_auto_20240506_1128'),
]

operations = [
migrations.AlterField(
model_name='ralphuser',
name='username',
field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username'),
),
]
12 changes: 5 additions & 7 deletions src/ralph/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ralph.admin.autocomplete import AutocompleteTooltipMixin
from ralph.lib.mixins.models import AdminAbsoluteUrlMixin, NamedMixin
from ralph.lib.permissions import (
from ralph.lib.permissions.models import (
PermByFieldMixin,
PermissionsForObjectMixin,
user_permission
Expand Down Expand Up @@ -164,12 +164,10 @@ def has_any_perms(self, perms, obj=None):
return any([self.has_perm(p, obj=obj) for p in perms])

def save(self, *args, **kwargs):
# set default values if None provided
for field in ('country',):
val = getattr(self, field)
if val is None:
val = self._meta.get_field_by_name(field)[0].default
setattr(self, field, val)
if isinstance(self.country, str):
self.country = Country.from_name(self.country.lower()).id
elif self.country is None:
self.country = Country.pl.id
return super().save(*args, **kwargs)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
from datetime import date

import reversion
from django.conf import settings
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View
from reversion import revisions as reversion

from ralph.accounts.admin import (
AssetList,
Expand Down
Loading
Loading